authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-08-30 02:41:27-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-08-30 02:41:27-04:00
log010b725bdef57eee969668087c8737e053b10e9f
tree39945bc7b66f480d281d76b7e112e0a1f36f71ae
parent5482f9f9e8b66ba0ad1c38384b1c3df8e1381308

add alignment field to pointer type


2 files changed, 9 insertions(+), 0 deletions(-)

src/ir.cpp+8
......@@ -11472,6 +11472,14 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
1147211472 create_const_type(ira->codegen, child_type->data.pointer.child_type),
1147311473 ira->codegen->builtin_types.entry_type,
1147411474 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile);
11475 } else if (buf_eql_str(field_name, "alignment")) {
11476 bool ptr_is_const = true;
11477 bool ptr_is_volatile = false;
11478 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base,
11479 create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int,
11480 child_type->data.pointer.alignment, false),
11481 ira->codegen->builtin_types.entry_num_lit_int,
11482 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile);
1147511483 } else {
1147611484 ir_add_error(ira, &field_ptr_instruction->base,
1147711485 buf_sprintf("type '%s' has no member called '%s'",
test/cases/align.zig+1
......@@ -3,6 +3,7 @@ const assert = @import("std").debug.assert;
33var foo: u8 align 4 = 100;
44
55test "global variable alignment" {
6 assert(@typeOf(&foo).alignment == 4);
67 assert(@typeOf(&foo) == &align 4 u8);
78 const slice = (&foo)[0..1];
89 assert(@typeOf(slice) == []align 4 u8);