authorgravatar for daniele.cocca@gmail.comDaniele Cocca <daniele.cocca@gmail.com> 2022-03-28 21:30:07+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-29 02:28:20-04:00
log8238d4b33585a715c58ab559cd001dd3ea1db55b
treef1d659627f00427fdaecaaacb80806d033a2501d
parent8df84cce8b68339c332d30213efe90cdc833d059

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.

6 files changed, 5 insertions(+), 7 deletions(-)

src/codegen/c.zig+5-1
......@@ -433,7 +433,6 @@ pub const DeclGen = struct {
433433 if (is_signed) try writer.writeAll("(int128_t)");
434434 if (is_neg) try writer.writeByte('-');
435435
436 assert(high > 0);
437436 try writer.print("(((uint128_t)0x{x}u<<64)", .{high});
438437
439438 if (low > 0)
......@@ -572,6 +571,11 @@ pub const DeclGen = struct {
572571 64 => return writer.writeAll("(void *)0xaaaaaaaaaaaaaaaa"),
573572 else => unreachable,
574573 },
574 .Struct => {
575 try writer.writeByte('(');
576 try dg.renderTypecast(writer, ty);
577 return writer.writeAll("){0xaa}");
578 },
575579 else => {
576580 // This should lower to 0xaa bytes in safe modes, and for unsafe modes should
577581 // lower to leaving variables uninitialized (that might need to be implemented
test/behavior/eval.zig-1
......@@ -443,7 +443,6 @@ fn copyWithPartialInline(s: []u32, b: []u8) void {
443443test "binary math operator in partially inlined function" {
444444 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
445445 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
446 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
447446
448447 var s: [4]u32 = undefined;
449448 var b: [16]u8 = undefined;
test/behavior/fn.zig-1
......@@ -75,7 +75,6 @@ test "return inner function which references comptime variable of outer function
7575}
7676
7777test "discard the result of a function that returns a struct" {
78 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
7978 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
8079 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
8180
test/behavior/for.zig-1
......@@ -69,7 +69,6 @@ test "basic for loop" {
6969 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
7070 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
7171 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
72 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
7372
7473 const expected_result = [_]u8{ 9, 8, 7, 6, 0, 1, 2, 3 } ** 3;
7574
test/behavior/int128.zig-1
......@@ -46,7 +46,6 @@ test "int128" {
4646 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
4747 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
4848 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
49 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
5049
5150 var buff: i128 = -1;
5251 try expect(buff < 0 and (buff + 1) == 0);
test/behavior/slice.zig-2
......@@ -74,8 +74,6 @@ fn assertLenIsZero(msg: []const u8) !void {
7474}
7575
7676test "access len index of sentinel-terminated slice" {
77 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
78
7977 const S = struct {
8078 fn doTheTest() !void {
8179 var slice: [:0]const u8 = "hello";