LLVM: fix missing alignment on wrapping instructions
Previously, when lowering AIR instructions `wrap_errunion_payload`, `wrap_errunion_err`, and `wrap_optional`, the LLVM backend would create an alloca instruction to store the result, but did not set the alignment on it. This caused UB which went undetected for a long time until we started enabling the stack protector. Closes #12594 Unblocks #12508 Inspires #12634 Tests passed locally: * test-behavior * test-cases
This commit is contained in:
@@ -412,3 +412,19 @@ test "orelse on C pointer" {
|
||||
const d = foo orelse @compileError("bad");
|
||||
try expectEqual([*c]const u8, @TypeOf(d));
|
||||
}
|
||||
|
||||
test "alignment of wrapping an optional payload" {
|
||||
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
|
||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
|
||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
|
||||
|
||||
const S = struct {
|
||||
const I = extern struct { x: i128 };
|
||||
|
||||
fn foo() ?I {
|
||||
var i: I = .{ .x = 1234 };
|
||||
return i;
|
||||
}
|
||||
};
|
||||
try expect(S.foo().?.x == 1234);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user