mirror of
https://github.com/ziglang/zig.git
synced 2025-12-29 09:33:18 +00:00
fix auto created variables not having correct alignment
This commit is contained in:
parent
d8e2549996
commit
9d59cdb8c1
@ -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;
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user