From 8fbae77770a77ccd645054e06baab45b03c8befd Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Sat, 7 Sep 2019 11:17:12 +0200 Subject: Force LLVM to generate byte-aligned packed unions Sometimes the frontend and LLVM would disagree on the ABI alignment of a packed union. Solve the problem by telling LLVM we're gonna manage the struct layout by ourselves. Closes #3184 --- test/stage1/behavior/union.zig | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test') diff --git a/test/stage1/behavior/union.zig b/test/stage1/behavior/union.zig index 7c5c653275..21308b0ea2 100644 --- a/test/stage1/behavior/union.zig +++ b/test/stage1/behavior/union.zig @@ -482,3 +482,15 @@ test "comparison between union and enum literal" { testComparison(); comptime testComparison(); } + +test "packed union generates correctly aligned LLVM type" { + const U = packed union { + f1: fn () void, + f2: u32, + }; + var foo = [_]U{ + U{ .f1 = doTest }, + U{ .f2 = 0 }, + }; + foo[0].f1(); +} -- cgit v1.2.3