| ... | @@ -1248,3 +1248,32 @@ test "bitcasting a packed struct at comptime and using the result" { | ... | @@ -1248,3 +1248,32 @@ test "bitcasting a packed struct at comptime and using the result" { |
| 1248 | _ = Struct.bitcast(@as(u64, 0)).cannotReach(); | 1248 | _ = Struct.bitcast(@as(u64, 0)).cannotReach(); |
| 1249 | } | 1249 | } |
| 1250 | } | 1250 | } |
| | 1251 | |
| | 1252 | test "2-byte packed struct argument in C calling convention" { |
| | 1253 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; |
| | 1254 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; |
| | 1255 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; |
| | 1256 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| | 1257 | |
| | 1258 | const S = packed struct(u16) { |
| | 1259 | x: u15 = 0, |
| | 1260 | y: u1 = 0, |
| | 1261 | |
| | 1262 | fn foo(s: @This()) callconv(.C) i32 { |
| | 1263 | return s.x; |
| | 1264 | } |
| | 1265 | fn bar(s: @This()) !void { |
| | 1266 | try expect(foo(s) == 1); |
| | 1267 | } |
| | 1268 | }; |
| | 1269 | { |
| | 1270 | var s: S = .{}; |
| | 1271 | s.x += 1; |
| | 1272 | try S.bar(s); |
| | 1273 | } |
| | 1274 | comptime { |
| | 1275 | var s: S = .{}; |
| | 1276 | s.x += 1; |
| | 1277 | try S.bar(s); |
| | 1278 | } |
| | 1279 | } |