authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-01-27 19:42:32-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-01-27 19:42:32-05:00
log9d59cdb8c13db0cfbc01f499dc227b1964ca24cc
treedc7b0dc0bf840421f9859fdb315d41d7b60ab3df
parentd8e25499963849f756498196f919575cb646f3dd
signature Commit is signed but in an unrecognized format.

fix auto created variables not having correct alignment


2 files changed, 14 insertions(+), 1 deletions(-)

src/ir.cpp+1-1
...@@ -17729,7 +17729,7 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV...@@ -17729,7 +17729,7 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV
17729 var->var_type = ira->codegen->builtin_types.entry_invalid;17729 var->var_type = ira->codegen->builtin_types.entry_invalid;
17730 return ir_const_void(ira, &decl_var_instruction->base.base);17730 return ir_const_void(ira, &decl_var_instruction->base.base);
17731 }17731 }
17732 var->align_bytes = get_abi_alignment(ira->codegen, result_type);17732 var->align_bytes = get_ptr_align(ira->codegen, var_ptr->value->type);
17733 } else {17733 } else {
17734 if (!ir_resolve_align(ira, decl_var_instruction->align_value->child, nullptr, &var->align_bytes)) {17734 if (!ir_resolve_align(ira, decl_var_instruction->align_value->child, nullptr, &var->align_bytes)) {
17735 var->var_type = ira->codegen->builtin_types.entry_invalid;17735 var->var_type = ira->codegen->builtin_types.entry_invalid;
test/stage1/behavior/misc.zig+13
...@@ -781,3 +781,16 @@ test "pointer to thread local array" {...@@ -781,3 +781,16 @@ test "pointer to thread local array" {
781 std.mem.copy(u8, buffer[0..], s);781 std.mem.copy(u8, buffer[0..], s);
782 std.testing.expectEqualSlices(u8, buffer[0..], s);782 std.testing.expectEqualSlices(u8, buffer[0..], s);
783}783}
784
785test "auto created variables have correct alignment" {
786 const S = struct {
787 fn foo(str: [*]const u8) u32 {
788 for (@ptrCast([*]align(1) const u32, str)[0..1]) |v| {
789 return v;
790 }
791 return 0;
792 }
793 };
794 expect(S.foo("\x7a\x7a\x7a\x7a") == 0x7a7a7a7a);
795 comptime expect(S.foo("\x7a\x7a\x7a\x7a") == 0x7a7a7a7a);
796}