From 8238d4b33585a715c58ab559cd001dd3ea1db55b Mon Sep 17 00:00:00 2001 From: Daniele Cocca Date: Mon, 28 Mar 2022 21:30:07 +0100 Subject: CBE: fix C output after PR #11302, reenable tests Commit 052079c99455d01312d377d72fa1b8b5c0b22aad surfaced two issues with the generated C code: - renderInt128() contained a seemingly unnecessary assertion to verify that the high 64 bits of the number were nonzero, dating back to 9bf1681990fe87a6b2e5fc644a89f1aece304579. I removed it. - renderValue() didn't have any special handling for undefined structs, falling back to printing "{}" which generated invalid expressions such as "return {}" for functions returning structs, whereas "return (S){}" is the correct form. I changed it accordingly. At the same time I'm reenabling the relevant tests. --- src/codegen/c.zig | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/codegen') diff --git a/src/codegen/c.zig b/src/codegen/c.zig index 84bb3a211b..38a105c172 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -433,7 +433,6 @@ pub const DeclGen = struct { if (is_signed) try writer.writeAll("(int128_t)"); if (is_neg) try writer.writeByte('-'); - assert(high > 0); try writer.print("(((uint128_t)0x{x}u<<64)", .{high}); if (low > 0) @@ -572,6 +571,11 @@ pub const DeclGen = struct { 64 => return writer.writeAll("(void *)0xaaaaaaaaaaaaaaaa"), else => unreachable, }, + .Struct => { + try writer.writeByte('('); + try dg.renderTypecast(writer, ty); + return writer.writeAll("){0xaa}"); + }, else => { // This should lower to 0xaa bytes in safe modes, and for unsafe modes should // lower to leaving variables uninitialized (that might need to be implemented -- cgit v1.2.3