fix auto created variables not having correct alignment

This commit is contained in:
Andrew Kelley 2020-01-27 19:42:32 -05:00
parent d8e2549996
commit 9d59cdb8c1
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
2 changed files with 14 additions and 1 deletions

View File

@ -17729,7 +17729,7 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV
var->var_type = ira->codegen->builtin_types.entry_invalid;
return ir_const_void(ira, &decl_var_instruction->base.base);
}
var->align_bytes = get_abi_alignment(ira->codegen, result_type);
var->align_bytes = get_ptr_align(ira->codegen, var_ptr->value->type);
} else {
if (!ir_resolve_align(ira, decl_var_instruction->align_value->child, nullptr, &var->align_bytes)) {
var->var_type = ira->codegen->builtin_types.entry_invalid;

View File

@ -781,3 +781,16 @@ test "pointer to thread local array" {
std.mem.copy(u8, buffer[0..], s);
std.testing.expectEqualSlices(u8, buffer[0..], s);
}
test "auto created variables have correct alignment" {
const S = struct {
fn foo(str: [*]const u8) u32 {
for (@ptrCast([*]align(1) const u32, str)[0..1]) |v| {
return v;
}
return 0;
}
};
expect(S.foo("\x7a\x7a\x7a\x7a") == 0x7a7a7a7a);
comptime expect(S.foo("\x7a\x7a\x7a\x7a") == 0x7a7a7a7a);
}