authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-09-12 19:37:03-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-09-13 02:04:20-07:00
logf8a9bc57ce1a2a5a1b90e9a33501b64f2dd79019
treeefe1f2ac3ba62ea641687bb82c927826ef72cee1
parent188902a710a64b08762d7731aab81cb695322184

translate-c: lower discards differently

This makes translate-c lower discards as `_ = @TypeOf(foo);` to avoid tripping the "pointless discard" error. Ideally, translate-c would avoid emitting pointless discards, in which case this commit can be reverted, however, that is a separate enhancement.

2 files changed, 78 insertions(+), 65 deletions(-)

src/translate_c/ast.zig+21-8
...@@ -1550,14 +1550,27 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {...@@ -1550,14 +1550,27 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {
1550 .main_token = try c.addToken(.identifier, "_"),1550 .main_token = try c.addToken(.identifier, "_"),
1551 .data = undefined,1551 .data = undefined,
1552 });1552 });
1553 return c.addNode(.{1553 const main_token = try c.addToken(.equal, "=");
1554 .tag = .assign,1554 if (payload.value.tag() == .identifier) {
1555 .main_token = try c.addToken(.equal, "="),1555 // Render as `_ = @TypeOf(foo);` to avoid tripping "pointless discard" error.
1556 .data = .{1556 return c.addNode(.{
1557 .lhs = lhs,1557 .tag = .assign,
1558 .rhs = try renderNode(c, payload.value),1558 .main_token = main_token,
1559 },1559 .data = .{
1560 });1560 .lhs = lhs,
1561 .rhs = try renderBuiltinCall(c, "@TypeOf", &.{payload.value}),
1562 },
1563 });
1564 } else {
1565 return c.addNode(.{
1566 .tag = .assign,
1567 .main_token = main_token,
1568 .data = .{
1569 .lhs = lhs,
1570 .rhs = try renderNode(c, payload.value),
1571 },
1572 });
1573 }
1561 },1574 },
1562 .@"while" => {1575 .@"while" => {
1563 const payload = node.castTag(.@"while").?.data;1576 const payload = node.castTag(.@"while").?.data;
test/translate_c.zig+57-57
...@@ -116,10 +116,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -116,10 +116,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
116 \\pub export fn foo() void {116 \\pub export fn foo() void {
117 \\ while (true) if (true) {117 \\ while (true) if (true) {
118 \\ var a: c_int = 1;118 \\ var a: c_int = 1;
119 \\ _ = a;119 \\ _ = @TypeOf(a);
120 \\ } else {120 \\ } else {
121 \\ var b: c_int = 2;121 \\ var b: c_int = 2;
122 \\ _ = b;122 \\ _ = @TypeOf(b);
123 \\ };123 \\ };
124 \\ if (true) if (true) {};124 \\ if (true) if (true) {};
125 \\}125 \\}
...@@ -192,7 +192,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -192,7 +192,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
192 \\ .B = 0,192 \\ .B = 0,
193 \\ .C = 0,193 \\ .C = 0,
194 \\ };194 \\ };
195 \\ _ = a;195 \\ _ = @TypeOf(a);
196 \\ {196 \\ {
197 \\ const struct_Foo_1 = extern struct {197 \\ const struct_Foo_1 = extern struct {
198 \\ A: c_int,198 \\ A: c_int,
...@@ -204,7 +204,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -204,7 +204,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
204 \\ .B = 0,204 \\ .B = 0,
205 \\ .C = 0,205 \\ .C = 0,
206 \\ };206 \\ };
207 \\ _ = a_2;207 \\ _ = @TypeOf(a_2);
208 \\ }208 \\ }
209 \\}209 \\}
210 });210 });
...@@ -233,24 +233,24 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -233,24 +233,24 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
233 \\ B: c_int,233 \\ B: c_int,
234 \\ C: c_int,234 \\ C: c_int,
235 \\ };235 \\ };
236 \\ _ = union_unnamed_1;236 \\ _ = @TypeOf(union_unnamed_1);
237 \\ const Foo = union_unnamed_1;237 \\ const Foo = union_unnamed_1;
238 \\ var a: Foo = Foo{238 \\ var a: Foo = Foo{
239 \\ .A = @as(c_int, 0),239 \\ .A = @as(c_int, 0),
240 \\ };240 \\ };
241 \\ _ = a;241 \\ _ = @TypeOf(a);
242 \\ {242 \\ {
243 \\ const union_unnamed_2 = extern union {243 \\ const union_unnamed_2 = extern union {
244 \\ A: c_int,244 \\ A: c_int,
245 \\ B: c_int,245 \\ B: c_int,
246 \\ C: c_int,246 \\ C: c_int,
247 \\ };247 \\ };
248 \\ _ = union_unnamed_2;248 \\ _ = @TypeOf(union_unnamed_2);
249 \\ const Foo_1 = union_unnamed_2;249 \\ const Foo_1 = union_unnamed_2;
250 \\ var a_2: Foo_1 = Foo_1{250 \\ var a_2: Foo_1 = Foo_1{
251 \\ .A = @as(c_int, 0),251 \\ .A = @as(c_int, 0),
252 \\ };252 \\ };
253 \\ _ = a_2;253 \\ _ = @TypeOf(a_2);
254 \\ }254 \\ }
255 \\}255 \\}
256 });256 });
...@@ -318,7 +318,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -318,7 +318,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
318 \\ const bar_1 = struct {318 \\ const bar_1 = struct {
319 \\ threadlocal var static: c_int = 2;319 \\ threadlocal var static: c_int = 2;
320 \\ };320 \\ };
321 \\ _ = bar_1;321 \\ _ = @TypeOf(bar_1);
322 \\ return 0;322 \\ return 0;
323 \\}323 \\}
324 });324 });
...@@ -337,7 +337,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -337,7 +337,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
337 \\}337 \\}
338 \\pub export fn bar() c_int {338 \\pub export fn bar() c_int {
339 \\ var a: c_int = 2;339 \\ var a: c_int = 2;
340 \\ _ = a;340 \\ _ = @TypeOf(a);
341 \\ return 0;341 \\ return 0;
342 \\}342 \\}
343 \\pub export fn baz() c_int {343 \\pub export fn baz() c_int {
...@@ -352,7 +352,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -352,7 +352,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
352 , &[_][]const u8{352 , &[_][]const u8{
353 \\pub export fn main() void {353 \\pub export fn main() void {
354 \\ var a: c_int = @bitCast(c_int, @truncate(c_uint, @alignOf(c_int)));354 \\ var a: c_int = @bitCast(c_int, @truncate(c_uint, @alignOf(c_int)));
355 \\ _ = a;355 \\ _ = @TypeOf(a);
356 \\}356 \\}
357 });357 });
358358
...@@ -500,7 +500,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -500,7 +500,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
500 \\#define bar(x) (&x, +3, 4 == 4, 5 * 6, baz(1, 2), 2 % 2, baz(1,2))500 \\#define bar(x) (&x, +3, 4 == 4, 5 * 6, baz(1, 2), 2 % 2, baz(1,2))
501 , &[_][]const u8{501 , &[_][]const u8{
502 \\pub const foo = blk: {502 \\pub const foo = blk: {
503 \\ _ = foo;503 \\ _ = @TypeOf(foo);
504 \\ break :blk bar;504 \\ break :blk bar;
505 \\};505 \\};
506 ,506 ,
...@@ -724,7 +724,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -724,7 +724,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
724 \\pub export fn function(arg_opaque_1: ?*struct_opaque) void {724 \\pub export fn function(arg_opaque_1: ?*struct_opaque) void {
725 \\ var opaque_1 = arg_opaque_1;725 \\ var opaque_1 = arg_opaque_1;
726 \\ var cast: ?*struct_opaque_2 = @ptrCast(?*struct_opaque_2, opaque_1);726 \\ var cast: ?*struct_opaque_2 = @ptrCast(?*struct_opaque_2, opaque_1);
727 \\ _ = cast;727 \\ _ = @TypeOf(cast);
728 \\}728 \\}
729 });729 });
730730
...@@ -761,7 +761,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -761,7 +761,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
761 \\pub export fn my_fn() align(128) void {}761 \\pub export fn my_fn() align(128) void {}
762 \\pub export fn other_fn() void {762 \\pub export fn other_fn() void {
763 \\ var ARR: [16]u8 align(16) = undefined;763 \\ var ARR: [16]u8 align(16) = undefined;
764 \\ _ = ARR;764 \\ _ = @TypeOf(ARR);
765 \\}765 \\}
766 });766 });
767 }767 }
...@@ -798,17 +798,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -798,17 +798,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
798 , &[_][]const u8{798 , &[_][]const u8{
799 \\pub export fn foo() void {799 \\pub export fn foo() void {
800 \\ var a: c_int = undefined;800 \\ var a: c_int = undefined;
801 \\ _ = a;801 \\ _ = @TypeOf(a);
802 \\ var b: u8 = 123;802 \\ var b: u8 = 123;
803 \\ _ = b;803 \\ _ = @TypeOf(b);
804 \\ const c: c_int = undefined;804 \\ const c: c_int = undefined;
805 \\ _ = c;805 \\ _ = @TypeOf(c);
806 \\ const d: c_uint = @bitCast(c_uint, @as(c_int, 440));806 \\ const d: c_uint = @bitCast(c_uint, @as(c_int, 440));
807 \\ _ = d;807 \\ _ = @TypeOf(d);
808 \\ var e: c_int = 10;808 \\ var e: c_int = 10;
809 \\ _ = e;809 \\ _ = @TypeOf(e);
810 \\ var f: c_uint = 10;810 \\ var f: c_uint = 10;
811 \\ _ = f;811 \\ _ = @TypeOf(f);
812 \\}812 \\}
813 });813 });
814814
...@@ -867,7 +867,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -867,7 +867,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
867 \\ const v2 = struct {867 \\ const v2 = struct {
868 \\ const static: [5:0]u8 = "2.2.2".*;868 \\ const static: [5:0]u8 = "2.2.2".*;
869 \\ };869 \\ };
870 \\ _ = v2;870 \\ _ = @TypeOf(v2);
871 \\}871 \\}
872 });872 });
873873
...@@ -911,7 +911,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -911,7 +911,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
911 \\pub export fn bar() void {911 \\pub export fn bar() void {
912 \\ var func_ptr: ?*anyopaque = @ptrCast(?*anyopaque, foo);912 \\ var func_ptr: ?*anyopaque = @ptrCast(?*anyopaque, foo);
913 \\ var typed_func_ptr: ?*const fn () callconv(.C) void = @intToPtr(?*const fn () callconv(.C) void, @intCast(c_ulong, @ptrToInt(func_ptr)));913 \\ var typed_func_ptr: ?*const fn () callconv(.C) void = @intToPtr(?*const fn () callconv(.C) void, @intCast(c_ulong, @ptrToInt(func_ptr)));
914 \\ _ = typed_func_ptr;914 \\ _ = @TypeOf(typed_func_ptr);
915 \\}915 \\}
916 });916 });
917 }917 }
...@@ -1353,7 +1353,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1353,7 +1353,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1353 , &[_][]const u8{1353 , &[_][]const u8{
1354 \\pub export fn foo() void {1354 \\pub export fn foo() void {
1355 \\ var a: c_int = undefined;1355 \\ var a: c_int = undefined;
1356 \\ _ = a;1356 \\ _ = @TypeOf(a);
1357 \\}1357 \\}
1358 });1358 });
13591359
...@@ -1524,23 +1524,23 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1524,23 +1524,23 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1524 \\ var p: ?*anyopaque = undefined;1524 \\ var p: ?*anyopaque = undefined;
1525 \\ {1525 \\ {
1526 \\ var to_char: [*c]u8 = @ptrCast([*c]u8, @alignCast(@import("std").meta.alignment([*c]u8), p));1526 \\ var to_char: [*c]u8 = @ptrCast([*c]u8, @alignCast(@import("std").meta.alignment([*c]u8), p));
1527 \\ _ = to_char;1527 \\ _ = @TypeOf(to_char);
1528 \\ var to_short: [*c]c_short = @ptrCast([*c]c_short, @alignCast(@import("std").meta.alignment([*c]c_short), p));1528 \\ var to_short: [*c]c_short = @ptrCast([*c]c_short, @alignCast(@import("std").meta.alignment([*c]c_short), p));
1529 \\ _ = to_short;1529 \\ _ = @TypeOf(to_short);
1530 \\ var to_int: [*c]c_int = @ptrCast([*c]c_int, @alignCast(@import("std").meta.alignment([*c]c_int), p));1530 \\ var to_int: [*c]c_int = @ptrCast([*c]c_int, @alignCast(@import("std").meta.alignment([*c]c_int), p));
1531 \\ _ = to_int;1531 \\ _ = @TypeOf(to_int);
1532 \\ var to_longlong: [*c]c_longlong = @ptrCast([*c]c_longlong, @alignCast(@import("std").meta.alignment([*c]c_longlong), p));1532 \\ var to_longlong: [*c]c_longlong = @ptrCast([*c]c_longlong, @alignCast(@import("std").meta.alignment([*c]c_longlong), p));
1533 \\ _ = to_longlong;1533 \\ _ = @TypeOf(to_longlong);
1534 \\ }1534 \\ }
1535 \\ {1535 \\ {
1536 \\ var to_char: [*c]u8 = @ptrCast([*c]u8, @alignCast(@import("std").meta.alignment([*c]u8), p));1536 \\ var to_char: [*c]u8 = @ptrCast([*c]u8, @alignCast(@import("std").meta.alignment([*c]u8), p));
1537 \\ _ = to_char;1537 \\ _ = @TypeOf(to_char);
1538 \\ var to_short: [*c]c_short = @ptrCast([*c]c_short, @alignCast(@import("std").meta.alignment([*c]c_short), p));1538 \\ var to_short: [*c]c_short = @ptrCast([*c]c_short, @alignCast(@import("std").meta.alignment([*c]c_short), p));
1539 \\ _ = to_short;1539 \\ _ = @TypeOf(to_short);
1540 \\ var to_int: [*c]c_int = @ptrCast([*c]c_int, @alignCast(@import("std").meta.alignment([*c]c_int), p));1540 \\ var to_int: [*c]c_int = @ptrCast([*c]c_int, @alignCast(@import("std").meta.alignment([*c]c_int), p));
1541 \\ _ = to_int;1541 \\ _ = @TypeOf(to_int);
1542 \\ var to_longlong: [*c]c_longlong = @ptrCast([*c]c_longlong, @alignCast(@import("std").meta.alignment([*c]c_longlong), p));1542 \\ var to_longlong: [*c]c_longlong = @ptrCast([*c]c_longlong, @alignCast(@import("std").meta.alignment([*c]c_longlong), p));
1543 \\ _ = to_longlong;1543 \\ _ = @TypeOf(to_longlong);
1544 \\ }1544 \\ }
1545 \\}1545 \\}
1546 });1546 });
...@@ -1786,11 +1786,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1786,11 +1786,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1786 \\ var arr: [10]u8 = [1]u8{1786 \\ var arr: [10]u8 = [1]u8{
1787 \\ 1,1787 \\ 1,
1788 \\ } ++ [1]u8{0} ** 9;1788 \\ } ++ [1]u8{0} ** 9;
1789 \\ _ = arr;1789 \\ _ = @TypeOf(arr);
1790 \\ var arr1: [10][*c]u8 = [1][*c]u8{1790 \\ var arr1: [10][*c]u8 = [1][*c]u8{
1791 \\ null,1791 \\ null,
1792 \\ } ++ [1][*c]u8{null} ** 9;1792 \\ } ++ [1][*c]u8{null} ** 9;
1793 \\ _ = arr1;1793 \\ _ = @TypeOf(arr1);
1794 \\}1794 \\}
1795 });1795 });
17961796
...@@ -2038,16 +2038,16 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2038,16 +2038,16 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2038 \\pub var c: c_int = 4;2038 \\pub var c: c_int = 4;
2039 \\pub export fn foo(arg_c_1: u8) void {2039 \\pub export fn foo(arg_c_1: u8) void {
2040 \\ var c_1 = arg_c_1;2040 \\ var c_1 = arg_c_1;
2041 \\ _ = c_1;2041 \\ _ = @TypeOf(c_1);
2042 \\ var a_2: c_int = undefined;2042 \\ var a_2: c_int = undefined;
2043 \\ var b_3: u8 = 123;2043 \\ var b_3: u8 = 123;
2044 \\ b_3 = @bitCast(u8, @truncate(i8, a_2));2044 \\ b_3 = @bitCast(u8, @truncate(i8, a_2));
2045 \\ {2045 \\ {
2046 \\ var d: c_int = 5;2046 \\ var d: c_int = 5;
2047 \\ _ = d;2047 \\ _ = @TypeOf(d);
2048 \\ }2048 \\ }
2049 \\ var d: c_uint = @bitCast(c_uint, @as(c_int, 440));2049 \\ var d: c_uint = @bitCast(c_uint, @as(c_int, 440));
2050 \\ _ = d;2050 \\ _ = @TypeOf(d);
2051 \\}2051 \\}
2052 });2052 });
20532053
...@@ -2146,7 +2146,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2146,7 +2146,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2146 \\ {2146 \\ {
2147 \\ var i: c_int = 2;2147 \\ var i: c_int = 2;
2148 \\ var b: c_int = 4;2148 \\ var b: c_int = 4;
2149 \\ _ = b;2149 \\ _ = @TypeOf(b);
2150 \\ while ((i + @as(c_int, 2)) != 0) : (i = 2) {2150 \\ while ((i + @as(c_int, 2)) != 0) : (i = 2) {
2151 \\ var a: c_int = 2;2151 \\ var a: c_int = 2;
2152 \\ _ = blk: {2152 \\ _ = blk: {
...@@ -2159,7 +2159,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2159,7 +2159,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2159 \\ }2159 \\ }
2160 \\ }2160 \\ }
2161 \\ var i: u8 = 2;2161 \\ var i: u8 = 2;
2162 \\ _ = i;2162 \\ _ = @TypeOf(i);
2163 \\}2163 \\}
2164 });2164 });
21652165
...@@ -2396,27 +2396,27 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2396,27 +2396,27 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2396 , &[_][]const u8{2396 , &[_][]const u8{
2397 \\pub export fn escapes() [*c]const u8 {2397 \\pub export fn escapes() [*c]const u8 {
2398 \\ var a: u8 = '\'';2398 \\ var a: u8 = '\'';
2399 \\ _ = a;2399 \\ _ = @TypeOf(a);
2400 \\ var b: u8 = '\\';2400 \\ var b: u8 = '\\';
2401 \\ _ = b;2401 \\ _ = @TypeOf(b);
2402 \\ var c: u8 = '\x07';2402 \\ var c: u8 = '\x07';
2403 \\ _ = c;2403 \\ _ = @TypeOf(c);
2404 \\ var d: u8 = '\x08';2404 \\ var d: u8 = '\x08';
2405 \\ _ = d;2405 \\ _ = @TypeOf(d);
2406 \\ var e: u8 = '\x0c';2406 \\ var e: u8 = '\x0c';
2407 \\ _ = e;2407 \\ _ = @TypeOf(e);
2408 \\ var f: u8 = '\n';2408 \\ var f: u8 = '\n';
2409 \\ _ = f;2409 \\ _ = @TypeOf(f);
2410 \\ var g: u8 = '\r';2410 \\ var g: u8 = '\r';
2411 \\ _ = g;2411 \\ _ = @TypeOf(g);
2412 \\ var h: u8 = '\t';2412 \\ var h: u8 = '\t';
2413 \\ _ = h;2413 \\ _ = @TypeOf(h);
2414 \\ var i: u8 = '\x0b';2414 \\ var i: u8 = '\x0b';
2415 \\ _ = i;2415 \\ _ = @TypeOf(i);
2416 \\ var j: u8 = '\x00';2416 \\ var j: u8 = '\x00';
2417 \\ _ = j;2417 \\ _ = @TypeOf(j);
2418 \\ var k: u8 = '"';2418 \\ var k: u8 = '"';
2419 \\ _ = k;2419 \\ _ = @TypeOf(k);
2420 \\ return "'\\\x07\x08\x0c\n\r\t\x0b\x00\"";2420 \\ return "'\\\x07\x08\x0c\n\r\t\x0b\x00\"";
2421 \\}2421 \\}
2422 });2422 });
...@@ -2612,7 +2612,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2612,7 +2612,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2612 \\pub export fn foo() c_int {2612 \\pub export fn foo() c_int {
2613 \\ return blk: {2613 \\ return blk: {
2614 \\ var a: c_int = 1;2614 \\ var a: c_int = 1;
2615 \\ _ = a;2615 \\ _ = @TypeOf(a);
2616 \\ break :blk a;2616 \\ break :blk a;
2617 \\ };2617 \\ };
2618 \\}2618 \\}
...@@ -2716,7 +2716,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2716,7 +2716,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2716 \\int bar(void) { return 0; }2716 \\int bar(void) { return 0; }
2717 , &[_][]const u8{2717 , &[_][]const u8{
2718 \\pub inline fn CALL(arg: anytype) @TypeOf(bar()) {2718 \\pub inline fn CALL(arg: anytype) @TypeOf(bar()) {
2719 \\ _ = arg;2719 \\ _ = @TypeOf(arg);
2720 \\ return bar();2720 \\ return bar();
2721 \\}2721 \\}
2722 });2722 });
...@@ -2775,14 +2775,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2775,14 +2775,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2775 \\pub export fn foo() void {2775 \\pub export fn foo() void {
2776 \\ if (true) {2776 \\ if (true) {
2777 \\ var a: c_int = 2;2777 \\ var a: c_int = 2;
2778 \\ _ = a;2778 \\ _ = @TypeOf(a);
2779 \\ }2779 \\ }
2780 \\ if ((blk: {2780 \\ if ((blk: {
2781 \\ _ = @as(c_int, 2);2781 \\ _ = @as(c_int, 2);
2782 \\ break :blk @as(c_int, 5);2782 \\ break :blk @as(c_int, 5);
2783 \\ }) != 0) {2783 \\ }) != 0) {
2784 \\ var a: c_int = 2;2784 \\ var a: c_int = 2;
2785 \\ _ = a;2785 \\ _ = @TypeOf(a);
2786 \\ }2786 \\ }
2787 \\}2787 \\}
2788 });2788 });
...@@ -3285,7 +3285,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -3285,7 +3285,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3285 \\#define a 23285 \\#define a 2
3286 , &[_][]const u8{3286 , &[_][]const u8{
3287 \\pub inline fn FOO(bar: anytype) @TypeOf(baz(@import("std").zig.c_translation.cast(?*anyopaque, baz))) {3287 \\pub inline fn FOO(bar: anytype) @TypeOf(baz(@import("std").zig.c_translation.cast(?*anyopaque, baz))) {
3288 \\ _ = bar;3288 \\ _ = @TypeOf(bar);
3289 \\ return baz(@import("std").zig.c_translation.cast(?*anyopaque, baz));3289 \\ return baz(@import("std").zig.c_translation.cast(?*anyopaque, baz));
3290 \\}3290 \\}
3291 ,3291 ,
...@@ -3425,7 +3425,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -3425,7 +3425,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3425 , &[_][]const u8{3425 , &[_][]const u8{
3426 \\pub export fn foo(arg_a: [*c]c_int) void {3426 \\pub export fn foo(arg_a: [*c]c_int) void {
3427 \\ var a = arg_a;3427 \\ var a = arg_a;
3428 \\ _ = a;3428 \\ _ = @TypeOf(a);
3429 \\}3429 \\}
3430 \\pub export fn bar(arg_a: [*c]const c_int) void {3430 \\pub export fn bar(arg_a: [*c]const c_int) void {
3431 \\ var a = arg_a;3431 \\ var a = arg_a;
...@@ -3785,12 +3785,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -3785,12 +3785,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3785 \\pub export fn bar(arg_x: c_int, arg_y: c_int) c_int {3785 \\pub export fn bar(arg_x: c_int, arg_y: c_int) c_int {
3786 \\ var x = arg_x;3786 \\ var x = arg_x;
3787 \\ var y = arg_y;3787 \\ var y = arg_y;
3788 \\ _ = y;3788 \\ _ = @TypeOf(y);
3789 \\ return x;3789 \\ return x;
3790 \\}3790 \\}
3791 ,3791 ,
3792 \\pub inline fn FOO(A: anytype, B: anytype) @TypeOf(A) {3792 \\pub inline fn FOO(A: anytype, B: anytype) @TypeOf(A) {
3793 \\ _ = B;3793 \\ _ = @TypeOf(B);
3794 \\ return A;3794 \\ return A;
3795 \\}3795 \\}
3796 });3796 });