authorgravatar for evan@lagerdata.comEvan Haas <evan@lagerdata.com> 2021-07-04 14:06:43-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-07-05 17:51:53-04:00
logb5659e02331ad1d4c273b3efe551c70bb5d92464
tree8c56ba1fcc25224753ef46f93a46a31810803a78
parentb7da1b2d45bc42a56eea3a143e4237a0712c4769

translate-c: Don't discard variables unless necessary

Closes #9205

3 files changed, 69 insertions(+), 173 deletions(-)

src/translate_c.zig+53-15
...@@ -67,6 +67,12 @@ const Scope = struct {...@@ -67,6 +67,12 @@ const Scope = struct {
67 mangle_count: u32 = 0,67 mangle_count: u32 = 0,
68 label: ?[]const u8 = null,68 label: ?[]const u8 = null,
6969
70 /// By default all variables are discarded, since we do not know in advance if they
71 /// will be used. This maps the variable's name to the Discard payload, so that if
72 /// the variable is subsequently referenced we can indicate that the discard should
73 /// be skipped during the intermediate AST -> Zig AST render step.
74 variable_discards: std.StringArrayHashMap(*ast.Payload.Discard),
75
70 /// When the block corresponds to a function, keep track of the return type76 /// When the block corresponds to a function, keep track of the return type
71 /// so that the return expression can be cast, if necessary77 /// so that the return expression can be cast, if necessary
72 return_type: ?clang.QualType = null,78 return_type: ?clang.QualType = null,
...@@ -84,6 +90,7 @@ const Scope = struct {...@@ -84,6 +90,7 @@ const Scope = struct {
84 },90 },
85 .statements = std.ArrayList(Node).init(c.gpa),91 .statements = std.ArrayList(Node).init(c.gpa),
86 .variables = AliasList.init(c.gpa),92 .variables = AliasList.init(c.gpa),
93 .variable_discards = std.StringArrayHashMap(*ast.Payload.Discard).init(c.gpa),
87 };94 };
88 if (labeled) {95 if (labeled) {
89 blk.label = try blk.makeMangledName(c, "blk");96 blk.label = try blk.makeMangledName(c, "blk");
...@@ -94,6 +101,7 @@ const Scope = struct {...@@ -94,6 +101,7 @@ const Scope = struct {
94 fn deinit(self: *Block) void {101 fn deinit(self: *Block) void {
95 self.statements.deinit();102 self.statements.deinit();
96 self.variables.deinit();103 self.variables.deinit();
104 self.variable_discards.deinit();
97 self.* = undefined;105 self.* = undefined;
98 }106 }
99107
...@@ -154,8 +162,9 @@ const Scope = struct {...@@ -154,8 +162,9 @@ const Scope = struct {
154162
155 fn discardVariable(scope: *Block, c: *Context, name: []const u8) Error!void {163 fn discardVariable(scope: *Block, c: *Context, name: []const u8) Error!void {
156 const name_node = try Tag.identifier.create(c.arena, name);164 const name_node = try Tag.identifier.create(c.arena, name);
157 const discard = try Tag.discard.create(c.arena, name_node);165 const discard = try Tag.discard.create(c.arena, .{ .should_skip = false, .value = name_node });
158 try scope.statements.append(discard);166 try scope.statements.append(discard);
167 try scope.variable_discards.putNoClobber(name, discard.castTag(.discard).?);
159 }168 }
160 };169 };
161170
...@@ -271,6 +280,24 @@ const Scope = struct {...@@ -271,6 +280,24 @@ const Scope = struct {
271 }280 }
272 }281 }
273 }282 }
283
284 fn skipVariableDiscard(inner: *Scope, name: []const u8) void {
285 var scope = inner;
286 while (true) {
287 switch (scope.id) {
288 .root => return,
289 .block => {
290 const block = @fieldParentPtr(Block, "base", scope);
291 if (block.variable_discards.get(name)) |discard| {
292 discard.data.should_skip = true;
293 return;
294 }
295 },
296 else => {},
297 }
298 scope = scope.parent.?;
299 }
300 }
274};301};
275302
276pub const Context = struct {303pub const Context = struct {
...@@ -834,7 +861,9 @@ fn transTypeDef(c: *Context, scope: *Scope, typedef_decl: *const clang.TypedefNa...@@ -834,7 +861,9 @@ fn transTypeDef(c: *Context, scope: *Scope, typedef_decl: *const clang.TypedefNa
834 try addTopLevelDecl(c, name, node);861 try addTopLevelDecl(c, name, node);
835 } else {862 } else {
836 try scope.appendNode(node);863 try scope.appendNode(node);
837 try bs.discardVariable(c, name);864 if (node.tag() != .pub_var_simple) {
865 try bs.discardVariable(c, name);
866 }
838 }867 }
839}868}
840869
...@@ -1078,14 +1107,16 @@ fn transRecordDecl(c: *Context, scope: *Scope, record_decl: *const clang.RecordD...@@ -1078,14 +1107,16 @@ fn transRecordDecl(c: *Context, scope: *Scope, record_decl: *const clang.RecordD
1078 .init = init_node,1107 .init = init_node,
1079 },1108 },
1080 };1109 };
10811110 const node = Node.initPayload(&payload.base);
1082 if (toplevel) {1111 if (toplevel) {
1083 try addTopLevelDecl(c, name, Node.initPayload(&payload.base));1112 try addTopLevelDecl(c, name, node);
1084 if (!is_unnamed)1113 if (!is_unnamed)
1085 try c.alias_list.append(.{ .alias = bare_name, .name = name });1114 try c.alias_list.append(.{ .alias = bare_name, .name = name });
1086 } else {1115 } else {
1087 try scope.appendNode(Node.initPayload(&payload.base));1116 try scope.appendNode(node);
1088 try bs.discardVariable(c, name);1117 if (node.tag() != .pub_var_simple) {
1118 try bs.discardVariable(c, name);
1119 }
1089 }1120 }
1090}1121}
10911122
...@@ -1172,14 +1203,16 @@ fn transEnumDecl(c: *Context, scope: *Scope, enum_decl: *const clang.EnumDecl) E...@@ -1172,14 +1203,16 @@ fn transEnumDecl(c: *Context, scope: *Scope, enum_decl: *const clang.EnumDecl) E
1172 .name = name,1203 .name = name,
1173 },1204 },
1174 };1205 };
11751206 const node = Node.initPayload(&payload.base);
1176 if (toplevel) {1207 if (toplevel) {
1177 try addTopLevelDecl(c, name, Node.initPayload(&payload.base));1208 try addTopLevelDecl(c, name, node);
1178 if (!is_unnamed)1209 if (!is_unnamed)
1179 try c.alias_list.append(.{ .alias = bare_name, .name = name });1210 try c.alias_list.append(.{ .alias = bare_name, .name = name });
1180 } else {1211 } else {
1181 try scope.appendNode(Node.initPayload(&payload.base));1212 try scope.appendNode(node);
1182 try bs.discardVariable(c, name);1213 if (node.tag() != .pub_var_simple) {
1214 try bs.discardVariable(c, name);
1215 }
1183 }1216 }
1184}1217}
11851218
...@@ -1789,7 +1822,7 @@ fn transDeclStmtOne(...@@ -1789,7 +1822,7 @@ fn transDeclStmtOne(
1789 args[0] = try Tag.address_of.create(c.arena, varname);1822 args[0] = try Tag.address_of.create(c.arena, varname);
17901823
1791 const cleanup_call = try Tag.call.create(c.arena, .{ .lhs = fn_id, .args = args });1824 const cleanup_call = try Tag.call.create(c.arena, .{ .lhs = fn_id, .args = args });
1792 const discard = try Tag.discard.create(c.arena, cleanup_call);1825 const discard = try Tag.discard.create(c.arena, .{ .should_skip = false, .value = cleanup_call });
1793 const deferred_cleanup = try Tag.@"defer".create(c.arena, discard);1826 const deferred_cleanup = try Tag.@"defer".create(c.arena, discard);
17941827
1795 try block_scope.statements.append(deferred_cleanup);1828 try block_scope.statements.append(deferred_cleanup);
...@@ -1844,6 +1877,7 @@ fn transDeclRefExpr(...@@ -1844,6 +1877,7 @@ fn transDeclRefExpr(
1844 });1877 });
1845 }1878 }
1846 }1879 }
1880 scope.skipVariableDiscard(mangled_name);
1847 return ref_expr;1881 return ref_expr;
1848}1882}
18491883
...@@ -2478,7 +2512,9 @@ fn transInitListExprRecord(...@@ -2478,7 +2512,9 @@ fn transInitListExprRecord(
2478 .value = try transExpr(c, scope, elem_expr, .used),2512 .value = try transExpr(c, scope, elem_expr, .used),
2479 });2513 });
2480 }2514 }
24812515 if (ty_node.castTag(.identifier)) |ident_node| {
2516 scope.skipVariableDiscard(ident_node.data);
2517 }
2482 return Tag.container_init.create(c.arena, .{2518 return Tag.container_init.create(c.arena, .{
2483 .lhs = ty_node,2519 .lhs = ty_node,
2484 .inits = try c.arena.dupe(ast.Payload.ContainerInit.Initializer, field_inits.items),2520 .inits = try c.arena.dupe(ast.Payload.ContainerInit.Initializer, field_inits.items),
...@@ -3870,7 +3906,7 @@ fn maybeSuppressResult(...@@ -3870,7 +3906,7 @@ fn maybeSuppressResult(
3870) TransError!Node {3906) TransError!Node {
3871 _ = scope;3907 _ = scope;
3872 if (used == .used) return result;3908 if (used == .used) return result;
3873 return Tag.discard.create(c.arena, result);3909 return Tag.discard.create(c.arena, .{ .should_skip = false, .value = result });
3874}3910}
38753911
3876fn addTopLevelDecl(c: *Context, name: []const u8, decl_node: Node) !void {3912fn addTopLevelDecl(c: *Context, name: []const u8, decl_node: Node) !void {
...@@ -5004,7 +5040,7 @@ fn parseCExpr(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!Node {...@@ -5004,7 +5040,7 @@ fn parseCExpr(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!Node {
5004 var last = node;5040 var last = node;
5005 while (true) {5041 while (true) {
5006 // suppress result5042 // suppress result
5007 const ignore = try Tag.discard.create(c.arena, last);5043 const ignore = try Tag.discard.create(c.arena, .{ .should_skip = false, .value = last });
5008 try block_scope.statements.append(ignore);5044 try block_scope.statements.append(ignore);
50095045
5010 last = try parseCCondExpr(c, m, scope);5046 last = try parseCCondExpr(c, m, scope);
...@@ -5303,7 +5339,9 @@ fn parseCPrimaryExprInner(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!N...@@ -5303,7 +5339,9 @@ fn parseCPrimaryExprInner(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!N
5303 try m.fail(c, "TODO implement function '{s}' in std.c.builtins", .{mangled_name});5339 try m.fail(c, "TODO implement function '{s}' in std.c.builtins", .{mangled_name});
5304 return error.ParseError;5340 return error.ParseError;
5305 }5341 }
5306 return Tag.identifier.create(c.arena, builtin_typedef_map.get(mangled_name) orelse mangled_name);5342 const identifier = try Tag.identifier.create(c.arena, builtin_typedef_map.get(mangled_name) orelse mangled_name);
5343 scope.skipVariableDiscard(identifier.castTag(.identifier).?.data);
5344 return identifier;
5307 },5345 },
5308 .LParen => {5346 .LParen => {
5309 const inner_node = try parseCExpr(c, m, scope);5347 const inner_node = try parseCExpr(c, m, scope);
src/translate_c/ast.zig+12-2
...@@ -248,7 +248,6 @@ pub const Node = extern union {...@@ -248,7 +248,6 @@ pub const Node = extern union {
248 .@"comptime",248 .@"comptime",
249 .@"defer",249 .@"defer",
250 .asm_simple,250 .asm_simple,
251 .discard,
252 .std_math_Log2Int,251 .std_math_Log2Int,
253 .negate,252 .negate,
254 .negate_wrap,253 .negate_wrap,
...@@ -341,6 +340,7 @@ pub const Node = extern union {...@@ -341,6 +340,7 @@ pub const Node = extern union {
341 .warning,340 .warning,
342 .type,341 .type,
343 => Payload.Value,342 => Payload.Value,
343 .discard => Payload.Discard,
344 .@"if" => Payload.If,344 .@"if" => Payload.If,
345 .@"while" => Payload.While,345 .@"while" => Payload.While,
346 .@"switch", .array_init, .switch_prong => Payload.Switch,346 .@"switch", .array_init, .switch_prong => Payload.Switch,
...@@ -463,6 +463,14 @@ pub const Payload = struct {...@@ -463,6 +463,14 @@ pub const Payload = struct {
463 },463 },
464 };464 };
465465
466 pub const Discard = struct {
467 base: Payload,
468 data: struct {
469 should_skip: bool,
470 value: Node,
471 },
472 };
473
466 pub const If = struct {474 pub const If = struct {
467 base: Payload,475 base: Payload,
468 data: struct {476 data: struct {
...@@ -1491,6 +1499,8 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {...@@ -1491,6 +1499,8 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {
1491 .pub_inline_fn => return renderMacroFunc(c, node),1499 .pub_inline_fn => return renderMacroFunc(c, node),
1492 .discard => {1500 .discard => {
1493 const payload = node.castTag(.discard).?.data;1501 const payload = node.castTag(.discard).?.data;
1502 if (payload.should_skip) return @as(NodeIndex, 0);
1503
1494 const lhs = try c.addNode(.{1504 const lhs = try c.addNode(.{
1495 .tag = .identifier,1505 .tag = .identifier,
1496 .main_token = try c.addToken(.identifier, "_"),1506 .main_token = try c.addToken(.identifier, "_"),
...@@ -1501,7 +1511,7 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {...@@ -1501,7 +1511,7 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {
1501 .main_token = try c.addToken(.equal, "="),1511 .main_token = try c.addToken(.equal, "="),
1502 .data = .{1512 .data = .{
1503 .lhs = lhs,1513 .lhs = lhs,
1504 .rhs = try renderNode(c, payload),1514 .rhs = try renderNode(c, payload.value),
1505 },1515 },
1506 });1516 });
1507 },1517 },
test/translate_c.zig+4-156
...@@ -12,11 +12,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -12,11 +12,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
12 , &[_][]const u8{12 , &[_][]const u8{
13 \\pub export fn foo(arg_x: c_ulong) c_ulong {13 \\pub export fn foo(arg_x: c_ulong) c_ulong {
14 \\ var x = arg_x;14 \\ var x = arg_x;
15 \\ _ = x;
16 \\ const union_unnamed_1 = extern union {15 \\ const union_unnamed_1 = extern union {
17 \\ _x: c_ulong,16 \\ _x: c_ulong,
18 \\ };17 \\ };
19 \\ _ = union_unnamed_1;
20 \\ return (union_unnamed_1{18 \\ return (union_unnamed_1{
21 \\ ._x = x,19 \\ ._x = x,
22 \\ })._x;20 \\ })._x;
...@@ -75,7 +73,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -75,7 +73,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
75 \\pub extern fn bar(...) c_int;73 \\pub extern fn bar(...) c_int;
76 \\pub export fn foo() void {74 \\pub export fn foo() void {
77 \\ var a: c_int = undefined;75 \\ var a: c_int = undefined;
78 \\ _ = a;
79 \\ if (a != 0) a = 2 else _ = bar();76 \\ if (a != 0) a = 2 else _ = bar();
80 \\}77 \\}
81 });78 });
...@@ -128,7 +125,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -128,7 +125,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
128 \\ B: c_int,125 \\ B: c_int,
129 \\ C: c_int,126 \\ C: c_int,
130 \\ };127 \\ };
131 \\ _ = struct_Foo;
132 \\ var a: struct_Foo = struct_Foo{128 \\ var a: struct_Foo = struct_Foo{
133 \\ .A = @as(c_int, 0),129 \\ .A = @as(c_int, 0),
134 \\ .B = 0,130 \\ .B = 0,
...@@ -141,7 +137,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -141,7 +137,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
141 \\ B: c_int,137 \\ B: c_int,
142 \\ C: c_int,138 \\ C: c_int,
143 \\ };139 \\ };
144 \\ _ = struct_Foo_1;
145 \\ var a_2: struct_Foo_1 = struct_Foo_1{140 \\ var a_2: struct_Foo_1 = struct_Foo_1{
146 \\ .A = @as(c_int, 0),141 \\ .A = @as(c_int, 0),
147 \\ .B = 0,142 \\ .B = 0,
...@@ -178,7 +173,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -178,7 +173,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
178 \\ };173 \\ };
179 \\ _ = union_unnamed_1;174 \\ _ = union_unnamed_1;
180 \\ const Foo = union_unnamed_1;175 \\ const Foo = union_unnamed_1;
181 \\ _ = Foo;
182 \\ var a: Foo = Foo{176 \\ var a: Foo = Foo{
183 \\ .A = @as(c_int, 0),177 \\ .A = @as(c_int, 0),
184 \\ };178 \\ };
...@@ -191,7 +185,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -191,7 +185,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
191 \\ };185 \\ };
192 \\ _ = union_unnamed_2;186 \\ _ = union_unnamed_2;
193 \\ const Foo_1 = union_unnamed_2;187 \\ const Foo_1 = union_unnamed_2;
194 \\ _ = Foo_1;
195 \\ var a_2: Foo_1 = Foo_1{188 \\ var a_2: Foo_1 = Foo_1{
196 \\ .A = @as(c_int, 0),189 \\ .A = @as(c_int, 0),
197 \\ };190 \\ };
...@@ -205,7 +198,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -205,7 +198,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
205 \\#define MEM_PHYSICAL_TO_K0(x) (void*)((uint32_t)(x) + SYS_BASE_CACHED)198 \\#define MEM_PHYSICAL_TO_K0(x) (void*)((uint32_t)(x) + SYS_BASE_CACHED)
206 , &[_][]const u8{199 , &[_][]const u8{
207 \\pub inline fn MEM_PHYSICAL_TO_K0(x: anytype) ?*c_void {200 \\pub inline fn MEM_PHYSICAL_TO_K0(x: anytype) ?*c_void {
208 \\ _ = x;
209 \\ return @import("std").zig.c_translation.cast(?*c_void, @import("std").zig.c_translation.cast(u32, x) + SYS_BASE_CACHED);201 \\ return @import("std").zig.c_translation.cast(?*c_void, @import("std").zig.c_translation.cast(u32, x) + SYS_BASE_CACHED);
210 \\}202 \\}
211 });203 });
...@@ -247,7 +239,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -247,7 +239,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
247 \\pub const VALUE = ((((@as(c_int, 1) + (@as(c_int, 2) * @as(c_int, 3))) + (@as(c_int, 4) * @as(c_int, 5))) + @as(c_int, 6)) << @as(c_int, 7)) | @boolToInt(@as(c_int, 8) == @as(c_int, 9));239 \\pub const VALUE = ((((@as(c_int, 1) + (@as(c_int, 2) * @as(c_int, 3))) + (@as(c_int, 4) * @as(c_int, 5))) + @as(c_int, 6)) << @as(c_int, 7)) | @boolToInt(@as(c_int, 8) == @as(c_int, 9));
248 ,240 ,
249 \\pub inline fn _AL_READ3BYTES(p: anytype) @TypeOf((@import("std").zig.c_translation.cast([*c]u8, p).* | ((@import("std").zig.c_translation.cast([*c]u8, p) + @as(c_int, 1)).* << @as(c_int, 8))) | ((@import("std").zig.c_translation.cast([*c]u8, p) + @as(c_int, 2)).* << @as(c_int, 16))) {241 \\pub inline fn _AL_READ3BYTES(p: anytype) @TypeOf((@import("std").zig.c_translation.cast([*c]u8, p).* | ((@import("std").zig.c_translation.cast([*c]u8, p) + @as(c_int, 1)).* << @as(c_int, 8))) | ((@import("std").zig.c_translation.cast([*c]u8, p) + @as(c_int, 2)).* << @as(c_int, 16))) {
250 \\ _ = p;
251 \\ return (@import("std").zig.c_translation.cast([*c]u8, p).* | ((@import("std").zig.c_translation.cast([*c]u8, p) + @as(c_int, 1)).* << @as(c_int, 8))) | ((@import("std").zig.c_translation.cast([*c]u8, p) + @as(c_int, 2)).* << @as(c_int, 16));242 \\ return (@import("std").zig.c_translation.cast([*c]u8, p).* | ((@import("std").zig.c_translation.cast([*c]u8, p) + @as(c_int, 1)).* << @as(c_int, 8))) | ((@import("std").zig.c_translation.cast([*c]u8, p) + @as(c_int, 2)).* << @as(c_int, 16));
252 \\}243 \\}
253 });244 });
...@@ -328,7 +319,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -328,7 +319,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
328 \\pub const Color = struct_Color;319 \\pub const Color = struct_Color;
329 ,320 ,
330 \\pub inline fn CLITERAL(type_1: anytype) @TypeOf(type_1) {321 \\pub inline fn CLITERAL(type_1: anytype) @TypeOf(type_1) {
331 \\ _ = type_1;
332 \\ return type_1;322 \\ return type_1;
333 \\}323 \\}
334 ,324 ,
...@@ -346,7 +336,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -346,7 +336,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
346 \\};336 \\};
347 ,337 ,
348 \\pub inline fn A(_x: anytype) MyCStruct {338 \\pub inline fn A(_x: anytype) MyCStruct {
349 \\ _ = _x;
350 \\ return @import("std").mem.zeroInit(MyCStruct, .{339 \\ return @import("std").mem.zeroInit(MyCStruct, .{
351 \\ .x = _x,340 \\ .x = _x,
352 \\ });341 \\ });
...@@ -377,7 +366,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -377,7 +366,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
377 \\#define __ferror_unlocked_body(_fp) (((_fp)->_flags & _IO_ERR_SEEN) != 0)366 \\#define __ferror_unlocked_body(_fp) (((_fp)->_flags & _IO_ERR_SEEN) != 0)
378 , &[_][]const u8{367 , &[_][]const u8{
379 \\pub inline fn __ferror_unlocked_body(_fp: anytype) @TypeOf((_fp.*._flags & _IO_ERR_SEEN) != @as(c_int, 0)) {368 \\pub inline fn __ferror_unlocked_body(_fp: anytype) @TypeOf((_fp.*._flags & _IO_ERR_SEEN) != @as(c_int, 0)) {
380 \\ _ = _fp;
381 \\ return (_fp.*._flags & _IO_ERR_SEEN) != @as(c_int, 0);369 \\ return (_fp.*._flags & _IO_ERR_SEEN) != @as(c_int, 0);
382 \\}370 \\}
383 });371 });
...@@ -387,7 +375,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -387,7 +375,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
387 \\#define BAR 1 && 2 > 4375 \\#define BAR 1 && 2 > 4
388 , &[_][]const u8{376 , &[_][]const u8{
389 \\pub inline fn FOO(x: anytype) @TypeOf(@boolToInt(x >= @as(c_int, 0)) + @boolToInt(x >= @as(c_int, 0))) {377 \\pub inline fn FOO(x: anytype) @TypeOf(@boolToInt(x >= @as(c_int, 0)) + @boolToInt(x >= @as(c_int, 0))) {
390 \\ _ = x;
391 \\ return @boolToInt(x >= @as(c_int, 0)) + @boolToInt(x >= @as(c_int, 0));378 \\ return @boolToInt(x >= @as(c_int, 0)) + @boolToInt(x >= @as(c_int, 0));
392 \\}379 \\}
393 ,380 ,
...@@ -450,7 +437,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -450,7 +437,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
450 \\};437 \\};
451 ,438 ,
452 \\pub inline fn bar(x: anytype) @TypeOf(baz(@as(c_int, 1), @as(c_int, 2))) {439 \\pub inline fn bar(x: anytype) @TypeOf(baz(@as(c_int, 1), @as(c_int, 2))) {
453 \\ _ = x;
454 \\ return blk: {440 \\ return blk: {
455 \\ _ = &x;441 \\ _ = &x;
456 \\ _ = @as(c_int, 3);442 \\ _ = @as(c_int, 3);
...@@ -580,7 +566,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -580,7 +566,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
580 \\};566 \\};
581 \\pub export fn foo(arg_x: [*c]outer) void {567 \\pub export fn foo(arg_x: [*c]outer) void {
582 \\ var x = arg_x;568 \\ var x = arg_x;
583 \\ _ = x;
584 \\ x.*.unnamed_0.unnamed_0.y = @bitCast(c_int, @as(c_uint, x.*.unnamed_0.x));569 \\ x.*.unnamed_0.unnamed_0.y = @bitCast(c_int, @as(c_uint, x.*.unnamed_0.x));
585 \\}570 \\}
586 });571 });
...@@ -667,7 +652,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -667,7 +652,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
667 \\pub const struct_opaque_2 = opaque {};652 \\pub const struct_opaque_2 = opaque {};
668 \\pub export fn function(arg_opaque_1: ?*struct_opaque) void {653 \\pub export fn function(arg_opaque_1: ?*struct_opaque) void {
669 \\ var opaque_1 = arg_opaque_1;654 \\ var opaque_1 = arg_opaque_1;
670 \\ _ = opaque_1;
671 \\ var cast: ?*struct_opaque_2 = @ptrCast(?*struct_opaque_2, opaque_1);655 \\ var cast: ?*struct_opaque_2 = @ptrCast(?*struct_opaque_2, opaque_1);
672 \\ _ = cast;656 \\ _ = cast;
673 \\}657 \\}
...@@ -763,7 +747,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -763,7 +747,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
763 , &[_][]const u8{747 , &[_][]const u8{
764 \\pub export fn foo() void {748 \\pub export fn foo() void {
765 \\ var a: c_int = undefined;749 \\ var a: c_int = undefined;
766 \\ _ = a;
767 \\ _ = @as(c_int, 1);750 \\ _ = @as(c_int, 1);
768 \\ _ = "hey";751 \\ _ = "hey";
769 \\ _ = @as(c_int, 1) + @as(c_int, 1);752 \\ _ = @as(c_int, 1) + @as(c_int, 1);
...@@ -849,7 +832,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -849,7 +832,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
849 \\pub extern fn foo() void;832 \\pub extern fn foo() void;
850 \\pub export fn bar() void {833 \\pub export fn bar() void {
851 \\ var func_ptr: ?*c_void = @ptrCast(?*c_void, foo);834 \\ var func_ptr: ?*c_void = @ptrCast(?*c_void, foo);
852 \\ _ = func_ptr;
853 \\ var typed_func_ptr: ?fn () callconv(.C) void = @intToPtr(?fn () callconv(.C) void, @intCast(c_ulong, @ptrToInt(func_ptr)));835 \\ var typed_func_ptr: ?fn () callconv(.C) void = @intToPtr(?fn () callconv(.C) void, @intCast(c_ulong, @ptrToInt(func_ptr)));
854 \\ _ = typed_func_ptr;836 \\ _ = typed_func_ptr;
855 \\}837 \\}
...@@ -881,11 +863,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -881,11 +863,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
881 , &[_][]const u8{863 , &[_][]const u8{
882 \\pub export fn s() c_int {864 \\pub export fn s() c_int {
883 \\ var a: c_int = undefined;865 \\ var a: c_int = undefined;
884 \\ _ = a;
885 \\ var b: c_int = undefined;866 \\ var b: c_int = undefined;
886 \\ _ = b;
887 \\ var c: c_int = undefined;867 \\ var c: c_int = undefined;
888 \\ _ = c;
889 \\ c = a + b;868 \\ c = a + b;
890 \\ c = a - b;869 \\ c = a - b;
891 \\ c = a * b;870 \\ c = a * b;
...@@ -895,11 +874,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -895,11 +874,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
895 \\}874 \\}
896 \\pub export fn u() c_uint {875 \\pub export fn u() c_uint {
897 \\ var a: c_uint = undefined;876 \\ var a: c_uint = undefined;
898 \\ _ = a;
899 \\ var b: c_uint = undefined;877 \\ var b: c_uint = undefined;
900 \\ _ = b;
901 \\ var c: c_uint = undefined;878 \\ var c: c_uint = undefined;
902 \\ _ = c;
903 \\ c = a +% b;879 \\ c = a +% b;
904 \\ c = a -% b;880 \\ c = a -% b;
905 \\ c = a *% b;881 \\ c = a *% b;
...@@ -1263,7 +1239,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1263,7 +1239,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1263 \\pub export fn foo() void {1239 \\pub export fn foo() void {
1264 \\ var a: c_int = undefined;1240 \\ var a: c_int = undefined;
1265 \\ _ = a;1241 \\ _ = a;
1266 \\ _ = a;
1267 \\}1242 \\}
1268 });1243 });
12691244
...@@ -1275,7 +1250,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1275,7 +1250,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1275 , &[_][]const u8{1250 , &[_][]const u8{
1276 \\pub export fn foo() ?*c_void {1251 \\pub export fn foo() ?*c_void {
1277 \\ var x: [*c]c_ushort = undefined;1252 \\ var x: [*c]c_ushort = undefined;
1278 \\ _ = x;
1279 \\ return @ptrCast(?*c_void, x);1253 \\ return @ptrCast(?*c_void, x);
1280 \\}1254 \\}
1281 });1255 });
...@@ -1332,7 +1306,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1332,7 +1306,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1332 \\pub export fn foo() void {1306 \\pub export fn foo() void {
1333 \\ {1307 \\ {
1334 \\ var i: c_int = 0;1308 \\ var i: c_int = 0;
1335 \\ _ = i;
1336 \\ while (i != 0) : (i += 1) {}1309 \\ while (i != 0) : (i += 1) {}
1337 \\ }1310 \\ }
1338 \\}1311 \\}
...@@ -1356,7 +1329,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1356,7 +1329,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1356 , &[_][]const u8{1329 , &[_][]const u8{
1357 \\pub export fn foo() void {1330 \\pub export fn foo() void {
1358 \\ var i: c_int = undefined;1331 \\ var i: c_int = undefined;
1359 \\ _ = i;
1360 \\ {1332 \\ {
1361 \\ i = 3;1333 \\ i = 3;
1362 \\ while (i != 0) : (i -= 1) {}1334 \\ while (i != 0) : (i -= 1) {}
...@@ -1400,7 +1372,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1400,7 +1372,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1400 , &[_][]const u8{1372 , &[_][]const u8{
1401 \\pub export fn ptrcast() [*c]f32 {1373 \\pub export fn ptrcast() [*c]f32 {
1402 \\ var a: [*c]c_int = undefined;1374 \\ var a: [*c]c_int = undefined;
1403 \\ _ = a;
1404 \\ return @ptrCast([*c]f32, @alignCast(@import("std").meta.alignment(f32), a));1375 \\ return @ptrCast([*c]f32, @alignCast(@import("std").meta.alignment(f32), a));
1405 \\}1376 \\}
1406 });1377 });
...@@ -1424,7 +1395,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1424,7 +1395,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1424 , &[_][]const u8{1395 , &[_][]const u8{
1425 \\pub export fn test_ptr_cast() void {1396 \\pub export fn test_ptr_cast() void {
1426 \\ var p: ?*c_void = undefined;1397 \\ var p: ?*c_void = undefined;
1427 \\ _ = p;
1428 \\ {1398 \\ {
1429 \\ var to_char: [*c]u8 = @ptrCast([*c]u8, @alignCast(@import("std").meta.alignment(u8), p));1399 \\ var to_char: [*c]u8 = @ptrCast([*c]u8, @alignCast(@import("std").meta.alignment(u8), p));
1430 \\ _ = to_char;1400 \\ _ = to_char;
...@@ -1461,11 +1431,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1461,11 +1431,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1461 , &[_][]const u8{1431 , &[_][]const u8{
1462 \\pub export fn while_none_bool() c_int {1432 \\pub export fn while_none_bool() c_int {
1463 \\ var a: c_int = undefined;1433 \\ var a: c_int = undefined;
1464 \\ _ = a;
1465 \\ var b: f32 = undefined;1434 \\ var b: f32 = undefined;
1466 \\ _ = b;
1467 \\ var c: ?*c_void = undefined;1435 \\ var c: ?*c_void = undefined;
1468 \\ _ = c;
1469 \\ while (a != 0) return 0;1436 \\ while (a != 0) return 0;
1470 \\ while (b != 0) return 1;1437 \\ while (b != 0) return 1;
1471 \\ while (c != null) return 2;1438 \\ while (c != null) return 2;
...@@ -1486,11 +1453,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1486,11 +1453,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1486 , &[_][]const u8{1453 , &[_][]const u8{
1487 \\pub export fn for_none_bool() c_int {1454 \\pub export fn for_none_bool() c_int {
1488 \\ var a: c_int = undefined;1455 \\ var a: c_int = undefined;
1489 \\ _ = a;
1490 \\ var b: f32 = undefined;1456 \\ var b: f32 = undefined;
1491 \\ _ = b;
1492 \\ var c: ?*c_void = undefined;1457 \\ var c: ?*c_void = undefined;
1493 \\ _ = c;
1494 \\ while (a != 0) return 0;1458 \\ while (a != 0) return 0;
1495 \\ while (b != 0) return 1;1459 \\ while (b != 0) return 1;
1496 \\ while (c != null) return 2;1460 \\ while (c != null) return 2;
...@@ -1527,7 +1491,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1527,7 +1491,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1527 , &[_][]const u8{1491 , &[_][]const u8{
1528 \\pub export fn foo() void {1492 \\pub export fn foo() void {
1529 \\ var x: [*c]c_int = undefined;1493 \\ var x: [*c]c_int = undefined;
1530 \\ _ = x;
1531 \\ x.* = 1;1494 \\ x.* = 1;
1532 \\}1495 \\}
1533 });1496 });
...@@ -1541,9 +1504,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1541,9 +1504,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1541 , &[_][]const u8{1504 , &[_][]const u8{
1542 \\pub export fn foo() c_int {1505 \\pub export fn foo() c_int {
1543 \\ var x: c_int = 1234;1506 \\ var x: c_int = 1234;
1544 \\ _ = x;
1545 \\ var ptr: [*c]c_int = &x;1507 \\ var ptr: [*c]c_int = &x;
1546 \\ _ = ptr;
1547 \\ return ptr.*;1508 \\ return ptr.*;
1548 \\}1509 \\}
1549 });1510 });
...@@ -1556,7 +1517,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1556,7 +1517,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1556 , &[_][]const u8{1517 , &[_][]const u8{
1557 \\pub export fn foo() c_int {1518 \\pub export fn foo() c_int {
1558 \\ var x: c_int = undefined;1519 \\ var x: c_int = undefined;
1559 \\ _ = x;
1560 \\ return ~x;1520 \\ return ~x;
1561 \\}1521 \\}
1562 });1522 });
...@@ -1574,11 +1534,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1574,11 +1534,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1574 , &[_][]const u8{1534 , &[_][]const u8{
1575 \\pub export fn foo() c_int {1535 \\pub export fn foo() c_int {
1576 \\ var a: c_int = undefined;1536 \\ var a: c_int = undefined;
1577 \\ _ = a;
1578 \\ var b: f32 = undefined;1537 \\ var b: f32 = undefined;
1579 \\ _ = b;
1580 \\ var c: ?*c_void = undefined;1538 \\ var c: ?*c_void = undefined;
1581 \\ _ = c;
1582 \\ return @boolToInt(!(a == @as(c_int, 0)));1539 \\ return @boolToInt(!(a == @as(c_int, 0)));
1583 \\ return @boolToInt(!(a != 0));1540 \\ return @boolToInt(!(a != 0));
1584 \\ return @boolToInt(!(b != 0));1541 \\ return @boolToInt(!(b != 0));
...@@ -1891,13 +1848,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1891,13 +1848,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1891 \\pub extern var c: c_int;1848 \\pub extern var c: c_int;
1892 ,1849 ,
1893 \\pub inline fn BASIC(c_1: anytype) @TypeOf(c_1 * @as(c_int, 2)) {1850 \\pub inline fn BASIC(c_1: anytype) @TypeOf(c_1 * @as(c_int, 2)) {
1894 \\ _ = c_1;
1895 \\ return c_1 * @as(c_int, 2);1851 \\ return c_1 * @as(c_int, 2);
1896 \\}1852 \\}
1897 ,1853 ,
1898 \\pub inline fn FOO(L: anytype, b: anytype) @TypeOf(L + b) {1854 \\pub inline fn FOO(L: anytype, b: anytype) @TypeOf(L + b) {
1899 \\ _ = L;
1900 \\ _ = b;
1901 \\ return L + b;1855 \\ return L + b;
1902 \\}1856 \\}
1903 ,1857 ,
...@@ -1951,9 +1905,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1951,9 +1905,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1951 \\ var c_1 = arg_c_1;1905 \\ var c_1 = arg_c_1;
1952 \\ _ = c_1;1906 \\ _ = c_1;
1953 \\ var a_2: c_int = undefined;1907 \\ var a_2: c_int = undefined;
1954 \\ _ = a_2;
1955 \\ var b_3: u8 = 123;1908 \\ var b_3: u8 = 123;
1956 \\ _ = b_3;
1957 \\ b_3 = @bitCast(u8, @truncate(i8, a_2));1909 \\ b_3 = @bitCast(u8, @truncate(i8, a_2));
1958 \\ {1910 \\ {
1959 \\ var d: c_int = 5;1911 \\ var d: c_int = 5;
...@@ -1994,9 +1946,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1994,9 +1946,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1994 , &[_][]const u8{1946 , &[_][]const u8{
1995 \\pub export fn foo() void {1947 \\pub export fn foo() void {
1996 \\ var a: c_int = undefined;1948 \\ var a: c_int = undefined;
1997 \\ _ = a;
1998 \\ var b: c_int = undefined;1949 \\ var b: c_int = undefined;
1999 \\ _ = b;
2000 \\ a = blk: {1950 \\ a = blk: {
2001 \\ const tmp = @as(c_int, 2);1951 \\ const tmp = @as(c_int, 2);
2002 \\ b = tmp;1952 \\ b = tmp;
...@@ -2026,13 +1976,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2026,13 +1976,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2026 , &[_][]const u8{1976 , &[_][]const u8{
2027 \\pub export fn foo() c_int {1977 \\pub export fn foo() c_int {
2028 \\ var a: c_int = 5;1978 \\ var a: c_int = 5;
2029 \\ _ = a;
2030 \\ while (true) {1979 \\ while (true) {
2031 \\ a = 2;1980 \\ a = 2;
2032 \\ }1981 \\ }
2033 \\ while (true) {1982 \\ while (true) {
2034 \\ var a_1: c_int = 4;1983 \\ var a_1: c_int = 4;
2035 \\ _ = a_1;
2036 \\ a_1 = 9;1984 \\ a_1 = 9;
2037 \\ return blk: {1985 \\ return blk: {
2038 \\ _ = @as(c_int, 6);1986 \\ _ = @as(c_int, 6);
...@@ -2041,7 +1989,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2041,7 +1989,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2041 \\ }1989 \\ }
2042 \\ while (true) {1990 \\ while (true) {
2043 \\ var a_1: c_int = 2;1991 \\ var a_1: c_int = 2;
2044 \\ _ = a_1;
2045 \\ a_1 = 12;1992 \\ a_1 = 12;
2046 \\ }1993 \\ }
2047 \\ while (true) {1994 \\ while (true) {
...@@ -2063,12 +2010,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2063,12 +2010,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2063 \\pub export fn foo() void {2010 \\pub export fn foo() void {
2064 \\ {2011 \\ {
2065 \\ var i: c_int = 2;2012 \\ var i: c_int = 2;
2066 \\ _ = i;
2067 \\ var b: c_int = 4;2013 \\ var b: c_int = 4;
2068 \\ _ = b;2014 \\ _ = b;
2069 \\ while ((i + @as(c_int, 2)) != 0) : (i = 2) {2015 \\ while ((i + @as(c_int, 2)) != 0) : (i = 2) {
2070 \\ var a: c_int = 2;2016 \\ var a: c_int = 2;
2071 \\ _ = a;
2072 \\ _ = blk: {2017 \\ _ = blk: {
2073 \\ _ = blk_1: {2018 \\ _ = blk_1: {
2074 \\ a = 6;2019 \\ a = 6;
...@@ -2152,9 +2097,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2152,9 +2097,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2152 , &[_][]const u8{2097 , &[_][]const u8{
2153 \\pub export fn switch_fn(arg_i: c_int) void {2098 \\pub export fn switch_fn(arg_i: c_int) void {
2154 \\ var i = arg_i;2099 \\ var i = arg_i;
2155 \\ _ = i;
2156 \\ var res: c_int = 0;2100 \\ var res: c_int = 0;
2157 \\ _ = res;
2158 \\ while (true) {2101 \\ while (true) {
2159 \\ switch (i) {2102 \\ switch (i) {
2160 \\ @as(c_int, 0) => {2103 \\ @as(c_int, 0) => {
...@@ -2243,9 +2186,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2243,9 +2186,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2243 , &[_][]const u8{2186 , &[_][]const u8{
2244 \\pub export fn max(arg_a: c_int) void {2187 \\pub export fn max(arg_a: c_int) void {
2245 \\ var a = arg_a;2188 \\ var a = arg_a;
2246 \\ _ = a;
2247 \\ var tmp: c_int = undefined;2189 \\ var tmp: c_int = undefined;
2248 \\ _ = tmp;
2249 \\ tmp = a;2190 \\ tmp = a;
2250 \\ a = tmp;2191 \\ a = tmp;
2251 \\}2192 \\}
...@@ -2259,11 +2200,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2259,11 +2200,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2259 , &[_][]const u8{2200 , &[_][]const u8{
2260 \\pub export fn max(arg_a: c_int) void {2201 \\pub export fn max(arg_a: c_int) void {
2261 \\ var a = arg_a;2202 \\ var a = arg_a;
2262 \\ _ = a;
2263 \\ var b: c_int = undefined;2203 \\ var b: c_int = undefined;
2264 \\ _ = b;
2265 \\ var c: c_int = undefined;2204 \\ var c: c_int = undefined;
2266 \\ _ = c;
2267 \\ c = blk: {2205 \\ c = blk: {
2268 \\ const tmp = a;2206 \\ const tmp = a;
2269 \\ b = tmp;2207 \\ b = tmp;
...@@ -2292,7 +2230,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2292,7 +2230,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2292 , &[_][]const u8{2230 , &[_][]const u8{
2293 \\pub export fn float_to_int(arg_a: f32) c_int {2231 \\pub export fn float_to_int(arg_a: f32) c_int {
2294 \\ var a = arg_a;2232 \\ var a = arg_a;
2295 \\ _ = a;
2296 \\ return @floatToInt(c_int, a);2233 \\ return @floatToInt(c_int, a);
2297 \\}2234 \\}
2298 });2235 });
...@@ -2356,13 +2293,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2356,13 +2293,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2356 , &[_][]const u8{2293 , &[_][]const u8{
2357 \\pub export fn foo() void {2294 \\pub export fn foo() void {
2358 \\ var a: c_int = 2;2295 \\ var a: c_int = 2;
2359 \\ _ = a;
2360 \\ while (true) {2296 \\ while (true) {
2361 \\ a = a - @as(c_int, 1);2297 \\ a = a - @as(c_int, 1);
2362 \\ if (!(a != 0)) break;2298 \\ if (!(a != 0)) break;
2363 \\ }2299 \\ }
2364 \\ var b: c_int = 2;2300 \\ var b: c_int = 2;
2365 \\ _ = b;
2366 \\ while (true) {2301 \\ while (true) {
2367 \\ b = b - @as(c_int, 1);2302 \\ b = b - @as(c_int, 1);
2368 \\ if (!(b != 0)) break;2303 \\ if (!(b != 0)) break;
...@@ -2403,37 +2338,21 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2403,37 +2338,21 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2403 \\pub const SomeTypedef = c_int;2338 \\pub const SomeTypedef = c_int;
2404 \\pub export fn and_or_non_bool(arg_a: c_int, arg_b: f32, arg_c: ?*c_void) c_int {2339 \\pub export fn and_or_non_bool(arg_a: c_int, arg_b: f32, arg_c: ?*c_void) c_int {
2405 \\ var a = arg_a;2340 \\ var a = arg_a;
2406 \\ _ = a;
2407 \\ var b = arg_b;2341 \\ var b = arg_b;
2408 \\ _ = b;
2409 \\ var c = arg_c;2342 \\ var c = arg_c;
2410 \\ _ = c;
2411 \\ var d: enum_Foo = @bitCast(c_uint, FooA);2343 \\ var d: enum_Foo = @bitCast(c_uint, FooA);
2412 \\ _ = d;
2413 \\ var e: c_int = @boolToInt((a != 0) and (b != 0));2344 \\ var e: c_int = @boolToInt((a != 0) and (b != 0));
2414 \\ _ = e;
2415 \\ var f: c_int = @boolToInt((b != 0) and (c != null));2345 \\ var f: c_int = @boolToInt((b != 0) and (c != null));
2416 \\ _ = f;
2417 \\ var g: c_int = @boolToInt((a != 0) and (c != null));2346 \\ var g: c_int = @boolToInt((a != 0) and (c != null));
2418 \\ _ = g;
2419 \\ var h: c_int = @boolToInt((a != 0) or (b != 0));2347 \\ var h: c_int = @boolToInt((a != 0) or (b != 0));
2420 \\ _ = h;
2421 \\ var i: c_int = @boolToInt((b != 0) or (c != null));2348 \\ var i: c_int = @boolToInt((b != 0) or (c != null));
2422 \\ _ = i;
2423 \\ var j: c_int = @boolToInt((a != 0) or (c != null));2349 \\ var j: c_int = @boolToInt((a != 0) or (c != null));
2424 \\ _ = j;
2425 \\ var k: c_int = @boolToInt((a != 0) or (@bitCast(c_int, d) != 0));2350 \\ var k: c_int = @boolToInt((a != 0) or (@bitCast(c_int, d) != 0));
2426 \\ _ = k;
2427 \\ var l: c_int = @boolToInt((@bitCast(c_int, d) != 0) and (b != 0));2351 \\ var l: c_int = @boolToInt((@bitCast(c_int, d) != 0) and (b != 0));
2428 \\ _ = l;
2429 \\ var m: c_int = @boolToInt((c != null) or (d != 0));2352 \\ var m: c_int = @boolToInt((c != null) or (d != 0));
2430 \\ _ = m;
2431 \\ var td: SomeTypedef = 44;2353 \\ var td: SomeTypedef = 44;
2432 \\ _ = td;
2433 \\ var o: c_int = @boolToInt((td != 0) or (b != 0));2354 \\ var o: c_int = @boolToInt((td != 0) or (b != 0));
2434 \\ _ = o;
2435 \\ var p: c_int = @boolToInt((c != null) and (td != 0));2355 \\ var p: c_int = @boolToInt((c != null) and (td != 0));
2436 \\ _ = p;
2437 \\ return (((((((((e + f) + g) + h) + i) + j) + k) + l) + m) + o) + p;2356 \\ return (((((((((e + f) + g) + h) + i) + j) + k) + l) + m) + o) + p;
2438 \\}2357 \\}
2439 ,2358 ,
...@@ -2473,9 +2392,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2473,9 +2392,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2473 , &[_][]const u8{2392 , &[_][]const u8{
2474 \\pub export fn max(arg_a: c_int, arg_b: c_int) c_int {2393 \\pub export fn max(arg_a: c_int, arg_b: c_int) c_int {
2475 \\ var a = arg_a;2394 \\ var a = arg_a;
2476 \\ _ = a;
2477 \\ var b = arg_b;2395 \\ var b = arg_b;
2478 \\ _ = b;
2479 \\ return (a & b) ^ (a | b);2396 \\ return (a & b) ^ (a | b);
2480 \\}2397 \\}
2481 });2398 });
...@@ -2494,23 +2411,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2494,23 +2411,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2494 , &[_][]const u8{2411 , &[_][]const u8{
2495 \\pub export fn test_comparisons(arg_a: c_int, arg_b: c_int) c_int {2412 \\pub export fn test_comparisons(arg_a: c_int, arg_b: c_int) c_int {
2496 \\ var a = arg_a;2413 \\ var a = arg_a;
2497 \\ _ = a;
2498 \\ var b = arg_b;2414 \\ var b = arg_b;
2499 \\ _ = b;
2500 \\ var c: c_int = @boolToInt(a < b);2415 \\ var c: c_int = @boolToInt(a < b);
2501 \\ _ = c;
2502 \\ var d: c_int = @boolToInt(a > b);2416 \\ var d: c_int = @boolToInt(a > b);
2503 \\ _ = d;
2504 \\ var e: c_int = @boolToInt(a <= b);2417 \\ var e: c_int = @boolToInt(a <= b);
2505 \\ _ = e;
2506 \\ var f: c_int = @boolToInt(a >= b);2418 \\ var f: c_int = @boolToInt(a >= b);
2507 \\ _ = f;
2508 \\ var g: c_int = @boolToInt(c < d);2419 \\ var g: c_int = @boolToInt(c < d);
2509 \\ _ = g;
2510 \\ var h: c_int = @boolToInt(e < f);2420 \\ var h: c_int = @boolToInt(e < f);
2511 \\ _ = h;
2512 \\ var i: c_int = @boolToInt(g < h);2421 \\ var i: c_int = @boolToInt(g < h);
2513 \\ _ = i;
2514 \\ return i;2422 \\ return i;
2515 \\}2423 \\}
2516 });2424 });
...@@ -2526,9 +2434,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2526,9 +2434,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2526 , &[_][]const u8{2434 , &[_][]const u8{
2527 \\pub export fn max(arg_a: c_int, arg_b: c_int) c_int {2435 \\pub export fn max(arg_a: c_int, arg_b: c_int) c_int {
2528 \\ var a = arg_a;2436 \\ var a = arg_a;
2529 \\ _ = a;
2530 \\ var b = arg_b;2437 \\ var b = arg_b;
2531 \\ _ = b;
2532 \\ if (a == b) return a;2438 \\ if (a == b) return a;
2533 \\ if (a != b) return b;2439 \\ if (a != b) return b;
2534 \\ return a;2440 \\ return a;
...@@ -2545,7 +2451,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2545,7 +2451,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2545 \\pub const yes = [*c]u8;2451 \\pub const yes = [*c]u8;
2546 \\pub export fn foo() void {2452 \\pub export fn foo() void {
2547 \\ var a: yes = undefined;2453 \\ var a: yes = undefined;
2548 \\ _ = a;
2549 \\ if (a != null) {2454 \\ if (a != null) {
2550 \\ _ = @as(c_int, 2);2455 \\ _ = @as(c_int, 2);
2551 \\ }2456 \\ }
...@@ -2565,7 +2470,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2565,7 +2470,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2565 \\ return blk: {2470 \\ return blk: {
2566 \\ var a: c_int = 1;2471 \\ var a: c_int = 1;
2567 \\ _ = a;2472 \\ _ = a;
2568 \\ _ = a;
2569 \\ break :blk a;2473 \\ break :blk a;
2570 \\ };2474 \\ };
2571 \\}2475 \\}
...@@ -2591,7 +2495,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2591,7 +2495,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2591 \\pub export var b: f32 = 2.0;2495 \\pub export var b: f32 = 2.0;
2592 \\pub export fn foo() void {2496 \\pub export fn foo() void {
2593 \\ var c: [*c]struct_Foo = undefined;2497 \\ var c: [*c]struct_Foo = undefined;
2594 \\ _ = c;
2595 \\ _ = a.b;2498 \\ _ = a.b;
2596 \\ _ = c.*.b;2499 \\ _ = c.*.b;
2597 \\}2500 \\}
...@@ -2611,7 +2514,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2611,7 +2514,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2611 \\pub export var array: [100]c_int = [1]c_int{0} ** 100;2514 \\pub export var array: [100]c_int = [1]c_int{0} ** 100;
2612 \\pub export fn foo(arg_index: c_int) c_int {2515 \\pub export fn foo(arg_index: c_int) c_int {
2613 \\ var index = arg_index;2516 \\ var index = arg_index;
2614 \\ _ = index;
2615 \\ return array[@intCast(c_uint, index)];2517 \\ return array[@intCast(c_uint, index)];
2616 \\}2518 \\}
2617 ,2519 ,
...@@ -2626,9 +2528,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2626,9 +2528,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2626 , &[_][]const u8{2528 , &[_][]const u8{
2627 \\pub export fn foo() void {2529 \\pub export fn foo() void {
2628 \\ var a: [10]c_int = undefined;2530 \\ var a: [10]c_int = undefined;
2629 \\ _ = a;
2630 \\ var i: c_int = 0;2531 \\ var i: c_int = 0;
2631 \\ _ = i;
2632 \\ a[@intCast(c_uint, i)] = 0;2532 \\ a[@intCast(c_uint, i)] = 0;
2633 \\}2533 \\}
2634 });2534 });
...@@ -2641,9 +2541,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2641,9 +2541,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2641 , &[_][]const u8{2541 , &[_][]const u8{
2642 \\pub export fn foo() void {2542 \\pub export fn foo() void {
2643 \\ var a: [10]c_longlong = undefined;2543 \\ var a: [10]c_longlong = undefined;
2644 \\ _ = a;
2645 \\ var i: c_longlong = 0;2544 \\ var i: c_longlong = 0;
2646 \\ _ = i;
2647 \\ a[@intCast(usize, i)] = 0;2545 \\ a[@intCast(usize, i)] = 0;
2648 \\}2546 \\}
2649 });2547 });
...@@ -2656,9 +2554,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2656,9 +2554,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2656 , &[_][]const u8{2554 , &[_][]const u8{
2657 \\pub export fn foo() void {2555 \\pub export fn foo() void {
2658 \\ var a: [10]c_uint = undefined;2556 \\ var a: [10]c_uint = undefined;
2659 \\ _ = a;
2660 \\ var i: c_uint = 0;2557 \\ var i: c_uint = 0;
2661 \\ _ = i;
2662 \\ a[i] = 0;2558 \\ a[i] = 0;
2663 \\}2559 \\}
2664 });2560 });
...@@ -2667,7 +2563,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2667,7 +2563,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2667 \\#define CALL(arg) bar(arg)2563 \\#define CALL(arg) bar(arg)
2668 , &[_][]const u8{2564 , &[_][]const u8{
2669 \\pub inline fn CALL(arg: anytype) @TypeOf(bar(arg)) {2565 \\pub inline fn CALL(arg: anytype) @TypeOf(bar(arg)) {
2670 \\ _ = arg;
2671 \\ return bar(arg);2566 \\ return bar(arg);
2672 \\}2567 \\}
2673 });2568 });
...@@ -2692,9 +2587,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2692,9 +2587,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2692 , &[_][]const u8{2587 , &[_][]const u8{
2693 \\pub export fn max(arg_a: c_int, arg_b: c_int) c_int {2588 \\pub export fn max(arg_a: c_int, arg_b: c_int) c_int {
2694 \\ var a = arg_a;2589 \\ var a = arg_a;
2695 \\ _ = a;
2696 \\ var b = arg_b;2590 \\ var b = arg_b;
2697 \\ _ = b;
2698 \\ if ((a < b) or (a == b)) return b;2591 \\ if ((a < b) or (a == b)) return b;
2699 \\ if ((a >= b) and (a == b)) return a;2592 \\ if ((a >= b) and (a == b)) return a;
2700 \\ return a;2593 \\ return a;
...@@ -2716,9 +2609,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2716,9 +2609,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2716 , &[_][]const u8{2609 , &[_][]const u8{
2717 \\pub export fn max(arg_a: c_int, arg_b: c_int) c_int {2610 \\pub export fn max(arg_a: c_int, arg_b: c_int) c_int {
2718 \\ var a = arg_a;2611 \\ var a = arg_a;
2719 \\ _ = a;
2720 \\ var b = arg_b;2612 \\ var b = arg_b;
2721 \\ _ = b;
2722 \\ if (a < b) return b;2613 \\ if (a < b) return b;
2723 \\ if (a < b) return b else return a;2614 \\ if (a < b) return b else return a;
2724 \\ if (a < b) {} else {}2615 \\ if (a < b) {} else {}
...@@ -2769,13 +2660,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2769,13 +2660,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2769 \\;2660 \\;
2770 \\pub export fn if_none_bool(arg_a: c_int, arg_b: f32, arg_c: ?*c_void, arg_d: enum_SomeEnum) c_int {2661 \\pub export fn if_none_bool(arg_a: c_int, arg_b: f32, arg_c: ?*c_void, arg_d: enum_SomeEnum) c_int {
2771 \\ var a = arg_a;2662 \\ var a = arg_a;
2772 \\ _ = a;
2773 \\ var b = arg_b;2663 \\ var b = arg_b;
2774 \\ _ = b;
2775 \\ var c = arg_c;2664 \\ var c = arg_c;
2776 \\ _ = c;
2777 \\ var d = arg_d;2665 \\ var d = arg_d;
2778 \\ _ = d;
2779 \\ if (a != 0) return 0;2666 \\ if (a != 0) return 0;
2780 \\ if (b != 0) return 1;2667 \\ if (b != 0) return 1;
2781 \\ if (c != null) return 2;2668 \\ if (c != null) return 2;
...@@ -2803,7 +2690,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2803,7 +2690,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2803 , &[_][]const u8{2690 , &[_][]const u8{
2804 \\pub export fn abs(arg_a: c_int) c_int {2691 \\pub export fn abs(arg_a: c_int) c_int {
2805 \\ var a = arg_a;2692 \\ var a = arg_a;
2806 \\ _ = a;
2807 \\ return if (a < @as(c_int, 0)) -a else a;2693 \\ return if (a < @as(c_int, 0)) -a else a;
2808 \\}2694 \\}
2809 });2695 });
...@@ -2824,19 +2710,16 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2824,19 +2710,16 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2824 , &[_][]const u8{2710 , &[_][]const u8{
2825 \\pub export fn foo1(arg_a: c_uint) c_uint {2711 \\pub export fn foo1(arg_a: c_uint) c_uint {
2826 \\ var a = arg_a;2712 \\ var a = arg_a;
2827 \\ _ = a;
2828 \\ a +%= 1;2713 \\ a +%= 1;
2829 \\ return a;2714 \\ return a;
2830 \\}2715 \\}
2831 \\pub export fn foo2(arg_a: c_int) c_int {2716 \\pub export fn foo2(arg_a: c_int) c_int {
2832 \\ var a = arg_a;2717 \\ var a = arg_a;
2833 \\ _ = a;
2834 \\ a += 1;2718 \\ a += 1;
2835 \\ return a;2719 \\ return a;
2836 \\}2720 \\}
2837 \\pub export fn foo3(arg_a: [*c]c_int) [*c]c_int {2721 \\pub export fn foo3(arg_a: [*c]c_int) [*c]c_int {
2838 \\ var a = arg_a;2722 \\ var a = arg_a;
2839 \\ _ = a;
2840 \\ a += 1;2723 \\ a += 1;
2841 \\ return a;2724 \\ return a;
2842 \\}2725 \\}
...@@ -2862,9 +2745,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2862,9 +2745,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2862 \\}2745 \\}
2863 \\pub export fn bar() void {2746 \\pub export fn bar() void {
2864 \\ var f: ?fn () callconv(.C) void = foo;2747 \\ var f: ?fn () callconv(.C) void = foo;
2865 \\ _ = f;
2866 \\ var b: ?fn () callconv(.C) c_int = baz;2748 \\ var b: ?fn () callconv(.C) c_int = baz;
2867 \\ _ = b;
2868 \\ f.?();2749 \\ f.?();
2869 \\ f.?();2750 \\ f.?();
2870 \\ foo();2751 \\ foo();
...@@ -2890,9 +2771,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2890,9 +2771,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2890 , &[_][]const u8{2771 , &[_][]const u8{
2891 \\pub export fn foo() void {2772 \\pub export fn foo() void {
2892 \\ var i: c_int = 0;2773 \\ var i: c_int = 0;
2893 \\ _ = i;
2894 \\ var u: c_uint = 0;2774 \\ var u: c_uint = 0;
2895 \\ _ = u;
2896 \\ i += 1;2775 \\ i += 1;
2897 \\ i -= 1;2776 \\ i -= 1;
2898 \\ u +%= 1;2777 \\ u +%= 1;
...@@ -2931,9 +2810,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2931,9 +2810,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2931 , &[_][]const u8{2810 , &[_][]const u8{
2932 \\pub export fn log2(arg_a: c_uint) c_int {2811 \\pub export fn log2(arg_a: c_uint) c_int {
2933 \\ var a = arg_a;2812 \\ var a = arg_a;
2934 \\ _ = a;
2935 \\ var i: c_int = 0;2813 \\ var i: c_int = 0;
2936 \\ _ = i;
2937 \\ while (a > @bitCast(c_uint, @as(c_int, 0))) {2814 \\ while (a > @bitCast(c_uint, @as(c_int, 0))) {
2938 \\ a >>= @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1));2815 \\ a >>= @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1));
2939 \\ }2816 \\ }
...@@ -2953,9 +2830,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2953,9 +2830,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2953 , &[_][]const u8{2830 , &[_][]const u8{
2954 \\pub export fn log2(arg_a: u32) c_int {2831 \\pub export fn log2(arg_a: u32) c_int {
2955 \\ var a = arg_a;2832 \\ var a = arg_a;
2956 \\ _ = a;
2957 \\ var i: c_int = 0;2833 \\ var i: c_int = 0;
2958 \\ _ = i;
2959 \\ while (a > @bitCast(c_uint, @as(c_int, 0))) {2834 \\ while (a > @bitCast(c_uint, @as(c_int, 0))) {
2960 \\ a >>= @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1));2835 \\ a >>= @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1));
2961 \\ }2836 \\ }
...@@ -2983,9 +2858,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2983,9 +2858,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2983 , &[_][]const u8{2858 , &[_][]const u8{
2984 \\pub export fn foo() void {2859 \\pub export fn foo() void {
2985 \\ var a: c_int = 0;2860 \\ var a: c_int = 0;
2986 \\ _ = a;
2987 \\ var b: c_uint = 0;2861 \\ var b: c_uint = 0;
2988 \\ _ = b;
2989 \\ a += blk: {2862 \\ a += blk: {
2990 \\ const ref = &a;2863 \\ const ref = &a;
2991 \\ ref.* += @as(c_int, 1);2864 \\ ref.* += @as(c_int, 1);
...@@ -3064,7 +2937,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -3064,7 +2937,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3064 , &[_][]const u8{2937 , &[_][]const u8{
3065 \\pub export fn foo() void {2938 \\pub export fn foo() void {
3066 \\ var a: c_uint = 0;2939 \\ var a: c_uint = 0;
3067 \\ _ = a;
3068 \\ a +%= blk: {2940 \\ a +%= blk: {
3069 \\ const ref = &a;2941 \\ const ref = &a;
3070 \\ ref.* +%= @bitCast(c_uint, @as(c_int, 1));2942 \\ ref.* +%= @bitCast(c_uint, @as(c_int, 1));
...@@ -3124,9 +2996,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -3124,9 +2996,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3124 , &[_][]const u8{2996 , &[_][]const u8{
3125 \\pub export fn foo() void {2997 \\pub export fn foo() void {
3126 \\ var i: c_int = 0;2998 \\ var i: c_int = 0;
3127 \\ _ = i;
3128 \\ var u: c_uint = 0;2999 \\ var u: c_uint = 0;
3129 \\ _ = u;
3130 \\ i += 1;3000 \\ i += 1;
3131 \\ i -= 1;3001 \\ i -= 1;
3132 \\ u +%= 1;3002 \\ u +%= 1;
...@@ -3221,7 +3091,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -3221,7 +3091,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3221 \\pub fn bar() callconv(.C) void {}3091 \\pub fn bar() callconv(.C) void {}
3222 \\pub export fn foo(arg_baz: ?fn () callconv(.C) [*c]c_int) void {3092 \\pub export fn foo(arg_baz: ?fn () callconv(.C) [*c]c_int) void {
3223 \\ var baz = arg_baz;3093 \\ var baz = arg_baz;
3224 \\ _ = baz;
3225 \\ bar();3094 \\ bar();
3226 \\ _ = baz.?();3095 \\ _ = baz.?();
3227 \\}3096 \\}
...@@ -3304,14 +3173,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -3304,14 +3173,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3304 \\#define MAX(a, b) ((b) > (a) ? (b) : (a))3173 \\#define MAX(a, b) ((b) > (a) ? (b) : (a))
3305 , &[_][]const u8{3174 , &[_][]const u8{
3306 \\pub inline fn MIN(a: anytype, b: anytype) @TypeOf(if (b < a) b else a) {3175 \\pub inline fn MIN(a: anytype, b: anytype) @TypeOf(if (b < a) b else a) {
3307 \\ _ = a;
3308 \\ _ = b;
3309 \\ return if (b < a) b else a;3176 \\ return if (b < a) b else a;
3310 \\}3177 \\}
3311 ,3178 ,
3312 \\pub inline fn MAX(a: anytype, b: anytype) @TypeOf(if (b > a) b else a) {3179 \\pub inline fn MAX(a: anytype, b: anytype) @TypeOf(if (b > a) b else a) {
3313 \\ _ = a;
3314 \\ _ = b;
3315 \\ return if (b > a) b else a;3180 \\ return if (b > a) b else a;
3316 \\}3181 \\}
3317 });3182 });
...@@ -3323,9 +3188,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -3323,9 +3188,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3323 , &[_][]const u8{3188 , &[_][]const u8{
3324 \\pub export fn foo(arg_p: [*c]c_int, arg_x: c_int) c_int {3189 \\pub export fn foo(arg_p: [*c]c_int, arg_x: c_int) c_int {
3325 \\ var p = arg_p;3190 \\ var p = arg_p;
3326 \\ _ = p;
3327 \\ var x = arg_x;3191 \\ var x = arg_x;
3328 \\ _ = x;
3329 \\ return blk: {3192 \\ return blk: {
3330 \\ const tmp = x;3193 \\ const tmp = x;
3331 \\ (blk_1: {3194 \\ (blk_1: {
...@@ -3352,7 +3215,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -3352,7 +3215,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3352 \\}3215 \\}
3353 \\pub export fn bar(arg_x: c_long) c_ushort {3216 \\pub export fn bar(arg_x: c_long) c_ushort {
3354 \\ var x = arg_x;3217 \\ var x = arg_x;
3355 \\ _ = x;
3356 \\ return @bitCast(c_ushort, @truncate(c_short, x));3218 \\ return @bitCast(c_ushort, @truncate(c_short, x));
3357 \\}3219 \\}
3358 });3220 });
...@@ -3365,7 +3227,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -3365,7 +3227,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3365 , &[_][]const u8{3227 , &[_][]const u8{
3366 \\pub export fn foo(arg_bar_1: c_int) void {3228 \\pub export fn foo(arg_bar_1: c_int) void {
3367 \\ var bar_1 = arg_bar_1;3229 \\ var bar_1 = arg_bar_1;
3368 \\ _ = bar_1;
3369 \\ bar_1 = 2;3230 \\ bar_1 = 2;
3370 \\}3231 \\}
3371 \\pub export var bar: c_int = 4;3232 \\pub export var bar: c_int = 4;
...@@ -3379,7 +3240,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -3379,7 +3240,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3379 , &[_][]const u8{3240 , &[_][]const u8{
3380 \\pub export fn foo(arg_bar_1: c_int) void {3241 \\pub export fn foo(arg_bar_1: c_int) void {
3381 \\ var bar_1 = arg_bar_1;3242 \\ var bar_1 = arg_bar_1;
3382 \\ _ = bar_1;
3383 \\ bar_1 = 2;3243 \\ bar_1 = 2;
3384 \\}3244 \\}
3385 ,3245 ,
...@@ -3413,12 +3273,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -3413,12 +3273,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3413 \\}3273 \\}
3414 \\pub export fn bar(arg_a: [*c]const c_int) void {3274 \\pub export fn bar(arg_a: [*c]const c_int) void {
3415 \\ var a = arg_a;3275 \\ var a = arg_a;
3416 \\ _ = a;
3417 \\ foo(@intToPtr([*c]c_int, @ptrToInt(a)));3276 \\ foo(@intToPtr([*c]c_int, @ptrToInt(a)));
3418 \\}3277 \\}
3419 \\pub export fn baz(arg_a: [*c]volatile c_int) void {3278 \\pub export fn baz(arg_a: [*c]volatile c_int) void {
3420 \\ var a = arg_a;3279 \\ var a = arg_a;
3421 \\ _ = a;
3422 \\ foo(@intToPtr([*c]c_int, @ptrToInt(a)));3280 \\ foo(@intToPtr([*c]c_int, @ptrToInt(a)));
3423 \\}3281 \\}
3424 });3282 });
...@@ -3433,13 +3291,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -3433,13 +3291,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3433 , &[_][]const u8{3291 , &[_][]const u8{
3434 \\pub export fn foo(arg_x: bool) bool {3292 \\pub export fn foo(arg_x: bool) bool {
3435 \\ var x = arg_x;3293 \\ var x = arg_x;
3436 \\ _ = x;
3437 \\ var a: bool = @as(c_int, @boolToInt(x)) != @as(c_int, 1);3294 \\ var a: bool = @as(c_int, @boolToInt(x)) != @as(c_int, 1);
3438 \\ _ = a;
3439 \\ var b: bool = @as(c_int, @boolToInt(a)) != @as(c_int, 0);3295 \\ var b: bool = @as(c_int, @boolToInt(a)) != @as(c_int, 0);
3440 \\ _ = b;
3441 \\ var c: bool = @ptrToInt(foo) != 0;3296 \\ var c: bool = @ptrToInt(foo) != 0;
3442 \\ _ = c;
3443 \\ return foo(@as(c_int, @boolToInt(c)) != @as(c_int, @boolToInt(b)));3297 \\ return foo(@as(c_int, @boolToInt(c)) != @as(c_int, @boolToInt(b)));
3444 \\}3298 \\}
3445 });3299 });
...@@ -3450,9 +3304,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -3450,9 +3304,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3450 \\}3304 \\}
3451 , &[_][]const u8{3305 , &[_][]const u8{
3452 \\pub export fn max(x: c_int, arg_y: c_int) c_int {3306 \\pub export fn max(x: c_int, arg_y: c_int) c_int {
3453 \\ _ = x;
3454 \\ var y = arg_y;3307 \\ var y = arg_y;
3455 \\ _ = y;
3456 \\ return if (x > y) x else y;3308 \\ return if (x > y) x else y;
3457 \\}3309 \\}
3458 });3310 });
...@@ -3513,7 +3365,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -3513,7 +3365,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3513 \\3365 \\
3514 , &[_][]const u8{3366 , &[_][]const u8{
3515 \\pub inline fn DefaultScreen(dpy: anytype) @TypeOf(@import("std").zig.c_translation.cast(_XPrivDisplay, dpy).*.default_screen) {3367 \\pub inline fn DefaultScreen(dpy: anytype) @TypeOf(@import("std").zig.c_translation.cast(_XPrivDisplay, dpy).*.default_screen) {
3516 \\ _ = dpy;
3517 \\ return @import("std").zig.c_translation.cast(_XPrivDisplay, dpy).*.default_screen;3368 \\ return @import("std").zig.c_translation.cast(_XPrivDisplay, dpy).*.default_screen;
3518 \\}3369 \\}
3519 });3370 });
...@@ -3733,7 +3584,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -3733,7 +3584,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3733 \\ const foo = struct {3584 \\ const foo = struct {
3734 \\ var static: struct_FOO = @import("std").mem.zeroes(struct_FOO);3585 \\ var static: struct_FOO = @import("std").mem.zeroes(struct_FOO);
3735 \\ };3586 \\ };
3736 \\ _ = foo;
3737 \\ return foo.static.x;3587 \\ return foo.static.x;
3738 \\}3588 \\}
3739 });3589 });
...@@ -3747,24 +3597,22 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -3747,24 +3597,22 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3747 \\pub const INVALID_HANDLE_VALUE = @import("std").zig.c_translation.cast(?*c_void, @import("std").zig.c_translation.cast(LONG_PTR, -@as(c_int, 1)));3597 \\pub const INVALID_HANDLE_VALUE = @import("std").zig.c_translation.cast(?*c_void, @import("std").zig.c_translation.cast(LONG_PTR, -@as(c_int, 1)));
3748 });3598 });
37493599
3750 cases.add("discard local variables and function parameters",3600 cases.add("discard unused local variables and function parameters",
3751 \\#define FOO(A, B) (A) + (B)3601 \\#define FOO(A, B) (A)
3752 \\int bar(int x, int y) {3602 \\int bar(int x, int y) {
3753 \\ return x;3603 \\ return x;
3754 \\}3604 \\}
3755 , &[_][]const u8{3605 , &[_][]const u8{
3756 \\pub export fn bar(arg_x: c_int, arg_y: c_int) c_int {3606 \\pub export fn bar(arg_x: c_int, arg_y: c_int) c_int {
3757 \\ var x = arg_x;3607 \\ var x = arg_x;
3758 \\ _ = x;
3759 \\ var y = arg_y;3608 \\ var y = arg_y;
3760 \\ _ = y;3609 \\ _ = y;
3761 \\ return x;3610 \\ return x;
3762 \\}3611 \\}
3763 ,3612 ,
3764 \\pub inline fn FOO(A: anytype, B: anytype) @TypeOf(A + B) {3613 \\pub inline fn FOO(A: anytype, B: anytype) @TypeOf(A) {
3765 \\ _ = A;
3766 \\ _ = B;3614 \\ _ = B;
3767 \\ return A + B;3615 \\ return A;
3768 \\}3616 \\}
3769 });3617 });
37703618