authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2021-02-16 15:45:33+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2021-02-16 16:40:43+02:00
log74e9d4ca820f9940b47ae658c41e7edb315681c8
treefc36ac23530b57b4a43eeaef636d67296acd8e86
parent78fba4e0213dc9bcc2274ef6c31023256a235301
signature Commit is signed but in an unrecognized format.

translate-c: get all translate-c tests passing


3 files changed, 281 insertions(+), 233 deletions(-)

src/translate_c.zig+10-4
......@@ -622,7 +622,7 @@ fn visitVarDecl(c: *Context, var_decl: *const clang.VarDecl, mangled_name: ?[]co
622622 return; // Avoid processing this decl twice
623623
624624 const is_pub = mangled_name == null;
625 const is_thread_local = var_decl.getTLSKind() != .None;
625 const is_threadlocal = var_decl.getTLSKind() != .None;
626626 const scope = &c.global_scope.base;
627627
628628 // TODO https://github.com/ziglang/zig/issues/3756
......@@ -706,6 +706,7 @@ fn visitVarDecl(c: *Context, var_decl: *const clang.VarDecl, mangled_name: ?[]co
706706 .is_const = is_const,
707707 .is_extern = is_extern,
708708 .is_export = is_export,
709 .is_threadlocal = is_threadlocal,
709710 .linksection_string = linksection_string,
710711 .alignment = alignment,
711712 .name = checked_name,
......@@ -1307,6 +1308,7 @@ fn transDeclStmtOne(
13071308 .is_const = is_const,
13081309 .is_extern = false,
13091310 .is_export = false,
1311 .is_threadlocal = false,
13101312 .linksection_string = null,
13111313 .alignment = null,
13121314 .name = mangled_name,
......@@ -2886,11 +2888,11 @@ fn transCreateCompoundAssign(
28862888 if ((is_mod or is_div) and is_signed) {
28872889 const rhs_node = try transExpr(c, &block_scope.base, rhs, .used);
28882890 const builtin = if (is_mod)
2889 try Tag.rem.create(c.arena, .{ .lhs = lhs_node, .rhs = rhs_node })
2891 try Tag.rem.create(c.arena, .{ .lhs = ref_node, .rhs = rhs_node })
28902892 else
2891 try Tag.div_trunc.create(c.arena, .{ .lhs = lhs_node, .rhs = rhs_node });
2893 try Tag.div_trunc.create(c.arena, .{ .lhs = ref_node, .rhs = rhs_node });
28922894
2893 const assign = try transCreateNodeInfixOp(c, &block_scope.base, .assign, lhs_node, builtin, .used);
2895 const assign = try transCreateNodeInfixOp(c, &block_scope.base, .assign, ref_node, builtin, .used);
28942896 try block_scope.statements.append(assign);
28952897 } else {
28962898 var rhs_node = try transExpr(c, &block_scope.base, rhs, .used);
......@@ -4794,6 +4796,10 @@ fn parseCPostfixExpr(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!Node {
47944796 .LBracket => {
47954797 const index = try macroBoolToInt(c, try parseCExpr(c, m, scope));
47964798 node = try Tag.array_access.create(c.arena, .{ .lhs = node, .rhs = index });
4799 if (m.next().? != .RBracket) {
4800 try m.fail(c, "unable to translate C expr: expected ']'", .{});
4801 return error.ParseError;
4802 }
47974803 },
47984804 .LParen => {
47994805 var args = std.ArrayList(Node).init(c.gpa);
src/translate_c/ast.zig+62-39
......@@ -458,6 +458,7 @@ pub const Payload = struct {
458458 is_const: bool,
459459 is_extern: bool,
460460 is_export: bool,
461 is_threadlocal: bool,
461462 alignment: ?c_uint,
462463 linksection_string: ?[]const u8,
463464 name: []const u8,
......@@ -1164,42 +1165,42 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {
11641165 },
11651166 });
11661167 },
1167 .add => return renderBinOp(c, node, .add, .plus, "+"),
1168 .add => return renderBinOpGrouped(c, node, .add, .plus, "+"),
11681169 .add_assign => return renderBinOp(c, node, .assign_add, .plus_equal, "+="),
1169 .add_wrap => return renderBinOp(c, node, .add_wrap, .plus_percent, "+%"),
1170 .add_wrap => return renderBinOpGrouped(c, node, .add_wrap, .plus_percent, "+%"),
11701171 .add_wrap_assign => return renderBinOp(c, node, .assign_add_wrap, .plus_percent_equal, "+%="),
1171 .sub => return renderBinOp(c, node, .sub, .minus, "-"),
1172 .sub => return renderBinOpGrouped(c, node, .sub, .minus, "-"),
11721173 .sub_assign => return renderBinOp(c, node, .assign_sub, .minus_equal, "-="),
1173 .sub_wrap => return renderBinOp(c, node, .sub_wrap, .minus_percent, "-%"),
1174 .sub_wrap => return renderBinOpGrouped(c, node, .sub_wrap, .minus_percent, "-%"),
11741175 .sub_wrap_assign => return renderBinOp(c, node, .assign_sub_wrap, .minus_percent_equal, "-%="),
1175 .mul => return renderBinOp(c, node, .mul, .asterisk, "*"),
1176 .mul => return renderBinOpGrouped(c, node, .mul, .asterisk, "*"),
11761177 .mul_assign => return renderBinOp(c, node, .assign_mul, .asterisk_equal, "*="),
1177 .mul_wrap => return renderBinOp(c, node, .mul_wrap, .asterisk_percent, "*="),
1178 .mul_wrap => return renderBinOpGrouped(c, node, .mul_wrap, .asterisk_percent, "*%"),
11781179 .mul_wrap_assign => return renderBinOp(c, node, .assign_mul_wrap, .asterisk_percent_equal, "*%="),
1179 .div => return renderBinOp(c, node, .div, .slash, "/"),
1180 .div => return renderBinOpGrouped(c, node, .div, .slash, "/"),
11801181 .div_assign => return renderBinOp(c, node, .assign_div, .slash_equal, "/="),
1181 .shl => return renderBinOp(c, node, .bit_shift_left, .angle_bracket_angle_bracket_left, "<<"),
1182 .shl => return renderBinOpGrouped(c, node, .bit_shift_left, .angle_bracket_angle_bracket_left, "<<"),
11821183 .shl_assign => return renderBinOp(c, node, .assign_bit_shift_left, .angle_bracket_angle_bracket_left_equal, "<<="),
1183 .shr => return renderBinOp(c, node, .bit_shift_right, .angle_bracket_angle_bracket_right, ">>"),
1184 .shr => return renderBinOpGrouped(c, node, .bit_shift_right, .angle_bracket_angle_bracket_right, ">>"),
11841185 .shr_assign => return renderBinOp(c, node, .assign_bit_shift_right, .angle_bracket_angle_bracket_right_equal, ">>="),
1185 .mod => return renderBinOp(c, node, .mod, .percent, "%"),
1186 .mod => return renderBinOpGrouped(c, node, .mod, .percent, "%"),
11861187 .mod_assign => return renderBinOp(c, node, .assign_mod, .percent_equal, "%="),
1187 .@"and" => return renderBinOp(c, node, .bool_and, .keyword_and, "and"),
1188 .@"or" => return renderBinOp(c, node, .bool_or, .keyword_or, "or"),
1189 .less_than => return renderBinOp(c, node, .less_than, .angle_bracket_left, "<"),
1190 .less_than_equal => return renderBinOp(c, node, .less_or_equal, .angle_bracket_left_equal, "<="),
1191 .greater_than => return renderBinOp(c, node, .greater_than, .angle_bracket_right, ">="),
1192 .greater_than_equal => return renderBinOp(c, node, .greater_or_equal, .angle_bracket_right_equal, ">="),
1193 .equal => return renderBinOp(c, node, .equal_equal, .equal_equal, "=="),
1194 .not_equal => return renderBinOp(c, node, .bang_equal, .bang_equal, "!="),
1195 .bit_and => return renderBinOp(c, node, .bit_and, .ampersand, "&"),
1188 .@"and" => return renderBinOpGrouped(c, node, .bool_and, .keyword_and, "and"),
1189 .@"or" => return renderBinOpGrouped(c, node, .bool_or, .keyword_or, "or"),
1190 .less_than => return renderBinOpGrouped(c, node, .less_than, .angle_bracket_left, "<"),
1191 .less_than_equal => return renderBinOpGrouped(c, node, .less_or_equal, .angle_bracket_left_equal, "<="),
1192 .greater_than => return renderBinOpGrouped(c, node, .greater_than, .angle_bracket_right, ">="),
1193 .greater_than_equal => return renderBinOpGrouped(c, node, .greater_or_equal, .angle_bracket_right_equal, ">="),
1194 .equal => return renderBinOpGrouped(c, node, .equal_equal, .equal_equal, "=="),
1195 .not_equal => return renderBinOpGrouped(c, node, .bang_equal, .bang_equal, "!="),
1196 .bit_and => return renderBinOpGrouped(c, node, .bit_and, .ampersand, "&"),
11961197 .bit_and_assign => return renderBinOp(c, node, .assign_bit_and, .ampersand_equal, "&="),
1197 .bit_or => return renderBinOp(c, node, .bit_or, .pipe, "|"),
1198 .bit_or => return renderBinOpGrouped(c, node, .bit_or, .pipe, "|"),
11981199 .bit_or_assign => return renderBinOp(c, node, .assign_bit_or, .pipe_equal, "|="),
1199 .bit_xor => return renderBinOp(c, node, .bit_xor, .caret, "^"),
1200 .bit_xor => return renderBinOpGrouped(c, node, .bit_xor, .caret, "^"),
12001201 .bit_xor_assign => return renderBinOp(c, node, .assign_bit_xor, .caret_equal, "^="),
12011202 .array_cat => return renderBinOp(c, node, .array_cat, .plus_plus, "++"),
1202 .ellipsis3 => return renderBinOp(c, node, .switch_range, .ellipsis3, "..."),
1203 .ellipsis3 => return renderBinOpGrouped(c, node, .switch_range, .ellipsis3, "..."),
12031204 .assign => return renderBinOp(c, node, .assign, .equal, "="),
12041205 .empty_block => {
12051206 const l_brace = try c.addToken(.l_brace, "{");
......@@ -1222,7 +1223,7 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {
12221223
12231224 _ = try c.addToken(.r_brace, "}");
12241225 return c.addNode(.{
1225 .tag = .block_two,
1226 .tag = .block_two_semicolon,
12261227 .main_token = l_brace,
12271228 .data = .{
12281229 .lhs = stmt,
......@@ -1410,13 +1411,13 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {
14101411 var cases = try c.gpa.alloc(NodeIndex, payload.cases.len);
14111412 defer c.gpa.free(cases);
14121413 for (payload.cases) |case, i| {
1413 if (i != 0) _ = try c.addToken(.comma, ",");
14141414 cases[i] = try renderNode(c, case);
1415 _ = try c.addToken(.comma, ",");
14151416 }
14161417 const span = try c.listToSpan(cases);
14171418 _ = try c.addToken(.r_brace, "}");
14181419 return c.addNode(.{
1419 .tag = .@"switch",
1420 .tag = .switch_comma,
14201421 .main_token = switch_tok,
14211422 .data = .{
14221423 .lhs = cond,
......@@ -1623,9 +1624,10 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {
16231624 const payload = node.castTag(.tuple).?.data;
16241625 _ = try c.addToken(.period, ".");
16251626 const l_brace = try c.addToken(.l_brace, "{");
1626 var inits = try c.gpa.alloc(NodeIndex, std.math.max(payload.len, 1));
1627 var inits = try c.gpa.alloc(NodeIndex, std.math.max(payload.len, 2));
16271628 defer c.gpa.free(inits);
16281629 inits[0] = 0;
1630 inits[1] = 0;
16291631 for (payload) |init, i| {
16301632 if (i != 0) _ = try c.addToken(.comma, ",");
16311633 inits[i] = try renderNode(c, init);
......@@ -1661,17 +1663,17 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {
16611663 defer c.gpa.free(inits);
16621664 inits[0] = 0;
16631665 for (payload.inits) |init, i| {
1664 if (i != 0) _ = try c.addToken(.comma, ",");
16651666 _ = try c.addToken(.period, ".");
16661667 _ = try c.addIdentifier(init.name);
16671668 _ = try c.addToken(.equal, "=");
16681669 inits[i] = try renderNode(c, init.value);
1670 _ = try c.addToken(.comma, ",");
16691671 }
16701672 _ = try c.addToken(.r_brace, "}");
16711673
16721674 if (payload.inits.len < 2) {
16731675 return c.addNode(.{
1674 .tag = .struct_init_one,
1676 .tag = .struct_init_one_comma,
16751677 .main_token = l_brace,
16761678 .data = .{
16771679 .lhs = lhs,
......@@ -1681,7 +1683,7 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {
16811683 } else {
16821684 const span = try c.listToSpan(inits);
16831685 return c.addNode(.{
1684 .tag = .struct_init,
1686 .tag = .struct_init_comma,
16851687 .main_token = l_brace,
16861688 .data = .{
16871689 .lhs = lhs,
......@@ -1791,13 +1793,13 @@ fn renderArrayInit(c: *Context, lhs: NodeIndex, inits: []const Node) !NodeIndex
17911793 defer c.gpa.free(rendered);
17921794 rendered[0] = 0;
17931795 for (inits) |init, i| {
1794 if (i != 0) _ = try c.addToken(.comma, ",");
17951796 rendered[i] = try renderNode(c, init);
1797 _ = try c.addToken(.comma, ",");
17961798 }
17971799 _ = try c.addToken(.r_brace, "}");
17981800 if (inits.len < 2) {
17991801 return c.addNode(.{
1800 .tag = .array_init_one,
1802 .tag = .array_init_one_comma,
18011803 .main_token = l_brace,
18021804 .data = .{
18031805 .lhs = lhs,
......@@ -1807,7 +1809,7 @@ fn renderArrayInit(c: *Context, lhs: NodeIndex, inits: []const Node) !NodeIndex
18071809 } else {
18081810 const span = try c.listToSpan(rendered);
18091811 return c.addNode(.{
1810 .tag = .array_init,
1812 .tag = .array_init_comma,
18111813 .main_token = l_brace,
18121814 .data = .{
18131815 .lhs = lhs,
......@@ -1842,25 +1844,32 @@ fn renderArrayType(c: *Context, len: usize, elem_type: Node) !NodeIndex {
18421844fn addSemicolonIfNeeded(c: *Context, node: Node) !void {
18431845 switch (node.tag()) {
18441846 .warning => unreachable,
1845 .var_decl, .var_simple, .arg_redecl, .alias, .enum_redecl, .block, .empty_block, .@"switch" => {},
1847 .var_decl, .var_simple, .arg_redecl, .alias, .enum_redecl, .block, .empty_block, .block_single, .@"switch" => {},
18461848 .while_true => {
18471849 const payload = node.castTag(.while_true).?.data;
1848 return addSemicolonIfNeeded(c, payload);
1850 return addSemicolonIfNotBlock(c, payload);
18491851 },
18501852 .@"while" => {
18511853 const payload = node.castTag(.@"while").?.data;
1852 return addSemicolonIfNeeded(c, payload.body);
1854 return addSemicolonIfNotBlock(c, payload.body);
18531855 },
18541856 .@"if" => {
18551857 const payload = node.castTag(.@"if").?.data;
18561858 if (payload.@"else") |some|
1857 return addSemicolonIfNeeded(c, some);
1858 return addSemicolonIfNeeded(c, payload.then);
1859 return addSemicolonIfNotBlock(c, some);
1860 return addSemicolonIfNotBlock(c, payload.then);
18591861 },
18601862 else => _ = try c.addToken(.semicolon, ";"),
18611863 }
18621864}
18631865
1866fn addSemicolonIfNotBlock(c: *Context, node: Node) !void {
1867 switch (node.tag()) {
1868 .block, .empty_block, .block_single, => {},
1869 else => _ = try c.addToken(.semicolon, ";"),
1870 }
1871}
1872
18641873fn renderNodeGrouped(c: *Context, node: Node) !NodeIndex {
18651874 switch (node.tag()) {
18661875 .null_literal,
......@@ -1918,6 +1927,7 @@ fn renderNodeGrouped(c: *Context, node: Node) !NodeIndex {
19181927 .func,
19191928 .call,
19201929 .array_type,
1930 .bool_to_int,
19211931 => {
19221932 // no grouping needed
19231933 return renderNode(c, node);
......@@ -1926,7 +1936,6 @@ fn renderNodeGrouped(c: *Context, node: Node) !NodeIndex {
19261936 .opaque_literal,
19271937 .empty_array,
19281938 .block_single,
1929 .bool_to_int,
19301939 .add,
19311940 .add_wrap,
19321941 .sub,
......@@ -2022,7 +2031,7 @@ fn renderPrefixOp(c: *Context, node: Node, tag: std.zig.ast.Node.Tag, tok_tag: T
20222031 });
20232032}
20242033
2025fn renderBinOp(c: *Context, node: Node, tag: std.zig.ast.Node.Tag, tok_tag: TokenTag, bytes: []const u8) !NodeIndex {
2034fn renderBinOpGrouped(c: *Context, node: Node, tag: std.zig.ast.Node.Tag, tok_tag: TokenTag, bytes: []const u8) !NodeIndex {
20262035 const payload = @fieldParentPtr(Payload.BinOp, "base", node.ptr_otherwise).data;
20272036 const lhs = try renderNodeGrouped(c, payload.lhs);
20282037 return c.addNode(.{
......@@ -2035,6 +2044,19 @@ fn renderBinOp(c: *Context, node: Node, tag: std.zig.ast.Node.Tag, tok_tag: Toke
20352044 });
20362045}
20372046
2047fn renderBinOp(c: *Context, node: Node, tag: std.zig.ast.Node.Tag, tok_tag: TokenTag, bytes: []const u8) !NodeIndex {
2048 const payload = @fieldParentPtr(Payload.BinOp, "base", node.ptr_otherwise).data;
2049 const lhs = try renderNode(c, payload.lhs);
2050 return c.addNode(.{
2051 .tag = tag,
2052 .main_token = try c.addToken(tok_tag, bytes),
2053 .data = .{
2054 .lhs = lhs,
2055 .rhs = try renderNode(c, payload.rhs),
2056 },
2057 });
2058}
2059
20382060fn renderStdImport(c: *Context, first: []const u8, second: []const u8) !NodeIndex {
20392061 const import_tok = try c.addToken(.builtin, "@import");
20402062 _ = try c.addToken(.l_paren, "(");
......@@ -2143,6 +2165,7 @@ fn renderVar(c: *Context, node: Node) !NodeIndex {
21432165 if (payload.is_pub) _ = try c.addToken(.keyword_pub, "pub");
21442166 if (payload.is_extern) _ = try c.addToken(.keyword_extern, "extern");
21452167 if (payload.is_export) _ = try c.addToken(.keyword_export, "export");
2168 if (payload.is_threadlocal) _ = try c.addToken(.keyword_threadlocal, "threadlocal");
21462169 const mut_tok = if (payload.is_const)
21472170 try c.addToken(.keyword_const, "const")
21482171 else
test/translate_c.zig+209-190
......@@ -3,6 +3,14 @@ const std = @import("std");
33const CrossTarget = std.zig.CrossTarget;
44
55pub fn addCases(cases: *tests.TranslateCContext) void {
6 cases.add("use cast param as macro fn return type",
7 \\#define MEM_PHYSICAL_TO_K0(x) (void*)((u32)(x) + SYS_BASE_CACHED)
8 , &[_][]const u8{
9 \\pub fn MEM_PHYSICAL_TO_K0(x: anytype) callconv(.Inline) ?*c_void {
10 \\ return @import("std").meta.cast(?*c_void, @import("std").meta.cast(u32, x) + SYS_BASE_CACHED);
11 \\}
12 });
13
614 cases.add("variadic function demoted to prototype",
715 \\int foo(int bar, ...) {
816 \\ return 1;
......@@ -21,11 +29,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2129 \\ Foo *bar;
2230 \\} Bar;
2331 , &[_][]const u8{
24 \\const struct_unnamed_1 = //
25 ,
26 \\warning: unsupported type: 'Atomic'
27 \\ opaque {}; //
28 ,
32 \\source.h:1:9: warning: struct demoted to opaque type - unable to translate type of field foo
33 \\const struct_unnamed_1 = opaque {};
2934 \\pub const Foo = struct_unnamed_1;
3035 \\const struct_unnamed_2 = extern struct {
3136 \\ bar: ?*Foo,
......@@ -43,8 +48,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
4348 ,
4449 \\pub const VALUE = ((((1 + (2 * 3)) + (4 * 5)) + 6) << 7) | @boolToInt(8 == 9);
4550 ,
46 \\pub fn _AL_READ3BYTES(p: anytype) callconv(.Inline) @TypeOf(((@import("std").meta.cast([*c]u8, p)).* | (((@import("std").meta.cast([*c]u8, p)) + 1).* << 8)) | (((@import("std").meta.cast([*c]u8, p)) + 2).* << 16)) {
47 \\ return ((@import("std").meta.cast([*c]u8, p)).* | (((@import("std").meta.cast([*c]u8, p)) + 1).* << 8)) | (((@import("std").meta.cast([*c]u8, p)) + 2).* << 16);
51 \\pub fn _AL_READ3BYTES(p: anytype) callconv(.Inline) @TypeOf((@import("std").meta.cast([*c]u8, p).* | ((@import("std").meta.cast([*c]u8, p) + 1).* << 8)) | ((@import("std").meta.cast([*c]u8, p) + 2).* << 16)) {
52 \\ return (@import("std").meta.cast([*c]u8, p).* | ((@import("std").meta.cast([*c]u8, p) + 1).* << 8)) | ((@import("std").meta.cast([*c]u8, p) + 2).* << 16);
4853 \\}
4954 });
5055
......@@ -107,7 +112,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
107112 \\ int i1;
108113 \\} boom_t;
109114 \\#define FOO ((boom_t){1})
110 , &[_][]const u8{ // TODO properly translate this
115 , &[_][]const u8{
111116 \\pub const struct_Color = extern struct {
112117 \\ r: u8,
113118 \\ g: u8,
......@@ -127,7 +132,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
127132 \\};
128133 \\pub const boom_t = struct_boom_t;
129134 ,
130 \\pub const FOO = @import("std").mem.zeroInit(boom_t, .{ 1 });
135 \\pub const FOO = @import("std").mem.zeroInit(boom_t, .{1});
131136 });
132137
133138 cases.add("complex switch",
......@@ -142,14 +147,34 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
142147 \\ }
143148 \\}
144149 , &[_][]const u8{ // TODO properly translate this
145 \\pub const main = @compileError("unable to translate function");
150 \\pub export fn main() c_int {
151 \\ var i: c_int = 2;
152 \\ @"switch": {
153 \\ case_1: {
154 \\ case: {
155 \\ switch (i) {
156 \\ @as(c_int, 0) => break :case,
157 \\ @as(c_int, 2) => break :case_1,
158 \\ else => break :@"switch",
159 \\ }
160 \\ }
161 \\ }
162 \\ {
163 \\ {
164 \\ i += @as(c_int, 2);
165 \\ }
166 \\ i += @as(c_int, 1);
167 \\ }
168 \\ }
169 \\ return 0;
170 \\}
146171 });
147172
148173 cases.add("correct semicolon after infixop",
149174 \\#define __ferror_unlocked_body(_fp) (((_fp)->_flags & _IO_ERR_SEEN) != 0)
150175 , &[_][]const u8{
151 \\pub fn __ferror_unlocked_body(_fp: anytype) callconv(.Inline) @TypeOf(((_fp.*._flags) & _IO_ERR_SEEN) != 0) {
152 \\ return ((_fp.*._flags) & _IO_ERR_SEEN) != 0;
176 \\pub fn __ferror_unlocked_body(_fp: anytype) callconv(.Inline) @TypeOf((_fp.*._flags & _IO_ERR_SEEN) != 0) {
177 \\ return (_fp.*._flags & _IO_ERR_SEEN) != 0;
153178 \\}
154179 });
155180
......@@ -194,7 +219,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
194219 \\ while (false) while (false) {};
195220 \\ while (true) while (false) {};
196221 \\ while (true) while (true) {
197 \\ if (!false) break;
222 \\ break;
198223 \\ };
199224 \\}
200225 });
......@@ -245,15 +270,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
245270 \\ volatile _Atomic int abufused[12];
246271 \\};
247272 , &[_][]const u8{
248 \\pub const struct_arcan_shmif_page = //
249 ,
250 \\warning: unsupported type: 'Atomic'
251 \\ opaque {}; //
252 ,
253 \\ warning: struct demoted to opaque type - unable to translate type of field abufused
254 , // TODO should be `addr: *struct_arcan_shmif_page`
273 \\source.h:4:8: warning: struct demoted to opaque type - unable to translate type of field abufused
274 \\pub const struct_arcan_shmif_page = opaque {};
255275 \\pub const struct_arcan_shmif_cont = extern struct {
256 \\ addr: [*c]struct_arcan_shmif_page,
276 \\ addr: ?*struct_arcan_shmif_page,
257277 \\};
258278 });
259279
......@@ -514,8 +534,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
514534 \\ var a: c_int = undefined;
515535 \\ _ = @as(c_int, 1);
516536 \\ _ = "hey";
517 \\ _ = (@as(c_int, 1) + @as(c_int, 1));
518 \\ _ = (@as(c_int, 1) - @as(c_int, 1));
537 \\ _ = @as(c_int, 1) + @as(c_int, 1);
538 \\ _ = @as(c_int, 1) - @as(c_int, 1);
519539 \\ a = 1;
520540 \\}
521541 });
......@@ -634,9 +654,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
634654 \\ var a: c_int = undefined;
635655 \\ var b: c_int = undefined;
636656 \\ var c: c_int = undefined;
637 \\ c = (a + b);
638 \\ c = (a - b);
639 \\ c = (a * b);
657 \\ c = a + b;
658 \\ c = a - b;
659 \\ c = a * b;
640660 \\ c = @divTrunc(a, b);
641661 \\ c = @rem(a, b);
642662 \\ return 0;
......@@ -645,11 +665,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
645665 \\ var a: c_uint = undefined;
646666 \\ var b: c_uint = undefined;
647667 \\ var c: c_uint = undefined;
648 \\ c = (a +% b);
649 \\ c = (a -% b);
650 \\ c = (a *% b);
651 \\ c = (a / b);
652 \\ c = (a % b);
668 \\ c = a +% b;
669 \\ c = a -% b;
670 \\ c = a *% b;
671 \\ c = a / b;
672 \\ c = a % b;
653673 \\ return 0;
654674 \\}
655675 });
......@@ -1639,7 +1659,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
16391659 cases.add("macro pointer cast",
16401660 \\#define NRF_GPIO ((NRF_GPIO_Type *) NRF_GPIO_BASE)
16411661 , &[_][]const u8{
1642 \\pub const NRF_GPIO = (@import("std").meta.cast([*c]NRF_GPIO_Type, NRF_GPIO_BASE));
1662 \\pub const NRF_GPIO = @import("std").meta.cast([*c]NRF_GPIO_Type, NRF_GPIO_BASE);
16431663 });
16441664
16451665 cases.add("basic macro function",
......@@ -1723,17 +1743,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
17231743 \\}
17241744 , &[_][]const u8{
17251745 \\pub export fn foo() c_int {
1726 \\ _ = (blk: {
1746 \\ _ = blk: {
17271747 \\ _ = @as(c_int, 2);
17281748 \\ break :blk @as(c_int, 4);
1729 \\ });
1730 \\ return (blk: {
1731 \\ _ = (blk_1: {
1749 \\ };
1750 \\ return blk: {
1751 \\ _ = blk_1: {
17321752 \\ _ = @as(c_int, 2);
17331753 \\ break :blk_1 @as(c_int, 4);
1734 \\ });
1754 \\ };
17351755 \\ break :blk @as(c_int, 6);
1736 \\ });
1756 \\ };
17371757 \\}
17381758 });
17391759
......@@ -1780,20 +1800,16 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
17801800 \\ while (true) {
17811801 \\ var a_1: c_int = 4;
17821802 \\ a_1 = 9;
1783 \\ return (blk: {
1803 \\ return blk: {
17841804 \\ _ = @as(c_int, 6);
17851805 \\ break :blk a_1;
1786 \\ });
1806 \\ };
17871807 \\ }
17881808 \\ while (true) {
17891809 \\ var a_1: c_int = 2;
17901810 \\ a_1 = 12;
1791 \\ if (!true) break;
1792 \\ }
1793 \\ while (true) {
1794 \\ a = 7;
1795 \\ if (!true) break;
17961811 \\ }
1812 \\ while (true) a = 7;
17971813 \\ return 0;
17981814 \\}
17991815 });
......@@ -1813,13 +1829,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
18131829 \\ var b: c_int = 4;
18141830 \\ while ((i + @as(c_int, 2)) != 0) : (i = 2) {
18151831 \\ var a: c_int = 2;
1816 \\ _ = (blk: {
1817 \\ _ = (blk_1: {
1832 \\ _ = blk: {
1833 \\ _ = blk_1: {
18181834 \\ a = 6;
18191835 \\ break :blk_1 @as(c_int, 5);
1820 \\ });
1836 \\ };
18211837 \\ break :blk @as(c_int, 7);
1822 \\ });
1838 \\ };
18231839 \\ }
18241840 \\ }
18251841 \\ var i: u8 = @bitCast(u8, @truncate(i8, @as(c_int, 2)));
......@@ -1854,7 +1870,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
18541870 \\}
18551871 , &[_][]const u8{
18561872 \\pub export fn bar() c_int {
1857 \\ if ((if (true) @as(c_int, 5) else (if (true) @as(c_int, 4) else @as(c_int, 6))) != 0) _ = @as(c_int, 2);
1873 \\ if ((if (true) @as(c_int, 5) else if (true) @as(c_int, 4) else @as(c_int, 6)) != 0) _ = @as(c_int, 2);
18581874 \\ return if (true) @as(c_int, 5) else if (true) @as(c_int, 4) else @as(c_int, 6);
18591875 \\}
18601876 });
......@@ -1894,7 +1910,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
18941910 \\ }
18951911 \\ res = 2;
18961912 \\ }
1897 \\ res = (@as(c_int, 3) * i);
1913 \\ res = @as(c_int, 3) * i;
18981914 \\ break :@"switch";
18991915 \\ }
19001916 \\ res = 5;
......@@ -2043,12 +2059,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
20432059 \\pub export fn foo() void {
20442060 \\ var a: c_int = 2;
20452061 \\ while (true) {
2046 \\ a = (a - @as(c_int, 1));
2062 \\ a = a - @as(c_int, 1);
20472063 \\ if (!(a != 0)) break;
20482064 \\ }
20492065 \\ var b: c_int = 2;
20502066 \\ while (true) {
2051 \\ b = (b - @as(c_int, 1));
2067 \\ b = b - @as(c_int, 1);
20522068 \\ if (!(b != 0)) break;
20532069 \\ }
20542070 \\}
......@@ -2078,6 +2094,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
20782094 \\ return ((((((((((e + f) + g) + h) + i) + j) + k) + l) + m) + o) + p);
20792095 \\}
20802096 , &[_][]const u8{
2097 \\pub const FooA = @enumToInt(enum_Foo.A);
2098 \\pub const FooB = @enumToInt(enum_Foo.B);
2099 \\pub const FooC = @enumToInt(enum_Foo.C);
20812100 \\pub const enum_Foo = extern enum(c_int) {
20822101 \\ A,
20832102 \\ B,
......@@ -2090,19 +2109,19 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
20902109 \\ var b = arg_b;
20912110 \\ var c = arg_c;
20922111 \\ var d: enum_Foo = @intToEnum(enum_Foo, FooA);
2093 \\ var e: c_int = @boolToInt(((a != 0) and (b != 0)));
2094 \\ var f: c_int = @boolToInt(((b != 0) and (c != null)));
2095 \\ var g: c_int = @boolToInt(((a != 0) and (c != null)));
2096 \\ var h: c_int = @boolToInt(((a != 0) or (b != 0)));
2097 \\ var i: c_int = @boolToInt(((b != 0) or (c != null)));
2098 \\ var j: c_int = @boolToInt(((a != 0) or (c != null)));
2099 \\ var k: c_int = @boolToInt(((a != 0) or (@bitCast(c_int, @enumToInt(d)) != 0)));
2100 \\ var l: c_int = @boolToInt(((@bitCast(c_int, @enumToInt(d)) != 0) and (b != 0)));
2101 \\ var m: c_int = @boolToInt(((c != null) or (@bitCast(c_uint, @enumToInt(d)) != 0)));
2112 \\ var e: c_int = @boolToInt((a != 0) and (b != 0));
2113 \\ var f: c_int = @boolToInt((b != 0) and (c != null));
2114 \\ var g: c_int = @boolToInt((a != 0) and (c != null));
2115 \\ var h: c_int = @boolToInt((a != 0) or (b != 0));
2116 \\ var i: c_int = @boolToInt((b != 0) or (c != null));
2117 \\ var j: c_int = @boolToInt((a != 0) or (c != null));
2118 \\ var k: c_int = @boolToInt((a != 0) or (@bitCast(c_int, @enumToInt(d)) != 0));
2119 \\ var l: c_int = @boolToInt((@bitCast(c_int, @enumToInt(d)) != 0) and (b != 0));
2120 \\ var m: c_int = @boolToInt((c != null) or (@bitCast(c_uint, @enumToInt(d)) != 0));
21022121 \\ var td: SomeTypedef = 44;
2103 \\ var o: c_int = @boolToInt(((td != 0) or (b != 0)));
2104 \\ var p: c_int = @boolToInt(((c != null) and (td != 0)));
2105 \\ return ((((((((((e + f) + g) + h) + i) + j) + k) + l) + m) + o) + p);
2122 \\ var o: c_int = @boolToInt((td != 0) or (b != 0));
2123 \\ var p: c_int = @boolToInt((c != null) and (td != 0));
2124 \\ return (((((((((e + f) + g) + h) + i) + j) + k) + l) + m) + o) + p;
21062125 \\}
21072126 ,
21082127 \\pub const Foo = enum_Foo;
......@@ -2143,7 +2162,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
21432162 \\pub export fn max(arg_a: c_int, arg_b: c_int) c_int {
21442163 \\ var a = arg_a;
21452164 \\ var b = arg_b;
2146 \\ return ((a & b) ^ (a | b));
2165 \\ return (a & b) ^ (a | b);
21472166 \\}
21482167 });
21492168
......@@ -2162,13 +2181,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
21622181 \\pub export fn test_comparisons(arg_a: c_int, arg_b: c_int) c_int {
21632182 \\ var a = arg_a;
21642183 \\ var b = arg_b;
2165 \\ var c: c_int = @boolToInt((a < b));
2166 \\ var d: c_int = @boolToInt((a > b));
2167 \\ var e: c_int = @boolToInt((a <= b));
2168 \\ var f: c_int = @boolToInt((a >= b));
2169 \\ var g: c_int = @boolToInt((c < d));
2170 \\ var h: c_int = @boolToInt((e < f));
2171 \\ var i: c_int = @boolToInt((g < h));
2184 \\ var c: c_int = @boolToInt(a < b);
2185 \\ var d: c_int = @boolToInt(a > b);
2186 \\ var e: c_int = @boolToInt(a <= b);
2187 \\ var f: c_int = @boolToInt(a >= b);
2188 \\ var g: c_int = @boolToInt(c < d);
2189 \\ var h: c_int = @boolToInt(e < f);
2190 \\ var i: c_int = @boolToInt(g < h);
21722191 \\ return i;
21732192 \\}
21742193 });
......@@ -2215,11 +2234,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
22152234 \\}
22162235 , &[_][]const u8{
22172236 \\pub export fn foo() c_int {
2218 \\ return (blk: {
2237 \\ return blk: {
22192238 \\ var a: c_int = 1;
22202239 \\ _ = a;
22212240 \\ break :blk a;
2222 \\ });
2241 \\ };
22232242 \\}
22242243 });
22252244
......@@ -2371,9 +2390,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
23712390 \\ var a: c_int = 2;
23722391 \\ }
23732392 \\ if ((blk: {
2374 \\ _ = @as(c_int, 2);
2375 \\ break :blk @as(c_int, 5);
2376 \\ }) != 0) {
2393 \\ _ = @as(c_int, 2);
2394 \\ break :blk @as(c_int, 5);
2395 \\ }) != 0) {
23772396 \\ var a: c_int = 2;
23782397 \\ }
23792398 \\}
......@@ -2484,10 +2503,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
24842503 \\ var f: ?fn () callconv(.C) void = foo;
24852504 \\ var b: ?fn () callconv(.C) c_int = baz;
24862505 \\ f.?();
2487 \\ (f).?();
2506 \\ f.?();
24882507 \\ foo();
24892508 \\ _ = b.?();
2490 \\ _ = (b).?();
2509 \\ _ = b.?();
24912510 \\ _ = baz();
24922511 \\}
24932512 });
......@@ -2513,26 +2532,26 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
25132532 \\ i -= 1;
25142533 \\ u +%= 1;
25152534 \\ u -%= 1;
2516 \\ i = (blk: {
2535 \\ i = blk: {
25172536 \\ const ref = &i;
25182537 \\ ref.* += 1;
25192538 \\ break :blk ref.*;
2520 \\ });
2521 \\ i = (blk: {
2539 \\ };
2540 \\ i = blk: {
25222541 \\ const ref = &i;
25232542 \\ ref.* -= 1;
25242543 \\ break :blk ref.*;
2525 \\ });
2526 \\ u = (blk: {
2544 \\ };
2545 \\ u = blk: {
25272546 \\ const ref = &u;
25282547 \\ ref.* +%= 1;
25292548 \\ break :blk ref.*;
2530 \\ });
2531 \\ u = (blk: {
2549 \\ };
2550 \\ u = blk: {
25322551 \\ const ref = &u;
25332552 \\ ref.* -%= 1;
25342553 \\ break :blk ref.*;
2535 \\ });
2554 \\ };
25362555 \\}
25372556 });
25382557
......@@ -2596,66 +2615,66 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
25962615 \\pub export fn foo() void {
25972616 \\ var a: c_int = 0;
25982617 \\ var b: c_uint = @bitCast(c_uint, @as(c_int, 0));
2599 \\ a += (blk: {
2618 \\ a += blk: {
26002619 \\ const ref = &a;
2601 \\ ref.* = ref.* + @as(c_int, 1);
2620 \\ ref.* += @as(c_int, 1);
26022621 \\ break :blk ref.*;
2603 \\ });
2604 \\ a -= (blk: {
2622 \\ };
2623 \\ a -= blk: {
26052624 \\ const ref = &a;
2606 \\ ref.* = ref.* - @as(c_int, 1);
2625 \\ ref.* -= @as(c_int, 1);
26072626 \\ break :blk ref.*;
2608 \\ });
2609 \\ a *= (blk: {
2627 \\ };
2628 \\ a *= blk: {
26102629 \\ const ref = &a;
2611 \\ ref.* = ref.* * @as(c_int, 1);
2630 \\ ref.* *= @as(c_int, 1);
26122631 \\ break :blk ref.*;
2613 \\ });
2614 \\ a &= (blk: {
2632 \\ };
2633 \\ a &= blk: {
26152634 \\ const ref = &a;
2616 \\ ref.* = ref.* & @as(c_int, 1);
2635 \\ ref.* &= @as(c_int, 1);
26172636 \\ break :blk ref.*;
2618 \\ });
2619 \\ a |= (blk: {
2637 \\ };
2638 \\ a |= blk: {
26202639 \\ const ref = &a;
2621 \\ ref.* = ref.* | @as(c_int, 1);
2640 \\ ref.* |= @as(c_int, 1);
26222641 \\ break :blk ref.*;
2623 \\ });
2624 \\ a ^= (blk: {
2642 \\ };
2643 \\ a ^= blk: {
26252644 \\ const ref = &a;
2626 \\ ref.* = ref.* ^ @as(c_int, 1);
2645 \\ ref.* ^= @as(c_int, 1);
26272646 \\ break :blk ref.*;
2628 \\ });
2629 \\ a >>= @intCast(@import("std").math.Log2Int(c_int), (blk: {
2647 \\ };
2648 \\ a >>= @intCast(@import("std").math.Log2Int(c_int), blk: {
26302649 \\ const ref = &a;
2631 \\ ref.* = ref.* >> @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1));
2650 \\ ref.* >>= @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1));
26322651 \\ break :blk ref.*;
2633 \\ }));
2634 \\ a <<= @intCast(@import("std").math.Log2Int(c_int), (blk: {
2652 \\ });
2653 \\ a <<= @intCast(@import("std").math.Log2Int(c_int), blk: {
26352654 \\ const ref = &a;
2636 \\ ref.* = ref.* << @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1));
2655 \\ ref.* <<= @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1));
26372656 \\ break :blk ref.*;
2638 \\ }));
2639 \\ a = @divTrunc(a, (blk: {
2657 \\ });
2658 \\ a = @divTrunc(a, blk: {
26402659 \\ const ref = &a;
26412660 \\ ref.* = @divTrunc(ref.*, @as(c_int, 1));
26422661 \\ break :blk ref.*;
2643 \\ }));
2644 \\ a = @rem(a, (blk: {
2662 \\ });
2663 \\ a = @rem(a, blk: {
26452664 \\ const ref = &a;
26462665 \\ ref.* = @rem(ref.*, @as(c_int, 1));
26472666 \\ break :blk ref.*;
2648 \\ }));
2649 \\ b /= (blk: {
2667 \\ });
2668 \\ b /= blk: {
26502669 \\ const ref = &b;
2651 \\ ref.* = ref.* / @bitCast(c_uint, @as(c_int, 1));
2670 \\ ref.* /= @bitCast(c_uint, @as(c_int, 1));
26522671 \\ break :blk ref.*;
2653 \\ });
2654 \\ b %= (blk: {
2672 \\ };
2673 \\ b %= blk: {
26552674 \\ const ref = &b;
2656 \\ ref.* = ref.* % @bitCast(c_uint, @as(c_int, 1));
2675 \\ ref.* %= @bitCast(c_uint, @as(c_int, 1));
26572676 \\ break :blk ref.*;
2658 \\ });
2677 \\ };
26592678 \\}
26602679 });
26612680
......@@ -2674,46 +2693,46 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
26742693 , &[_][]const u8{
26752694 \\pub export fn foo() void {
26762695 \\ var a: c_uint = @bitCast(c_uint, @as(c_int, 0));
2677 \\ a +%= (blk: {
2696 \\ a +%= blk: {
26782697 \\ const ref = &a;
2679 \\ ref.* = ref.* +% @bitCast(c_uint, @as(c_int, 1));
2698 \\ ref.* +%= @bitCast(c_uint, @as(c_int, 1));
26802699 \\ break :blk ref.*;
2681 \\ });
2682 \\ a -%= (blk: {
2700 \\ };
2701 \\ a -%= blk: {
26832702 \\ const ref = &a;
2684 \\ ref.* = ref.* -% @bitCast(c_uint, @as(c_int, 1));
2703 \\ ref.* -%= @bitCast(c_uint, @as(c_int, 1));
26852704 \\ break :blk ref.*;
2686 \\ });
2687 \\ a *%= (blk: {
2705 \\ };
2706 \\ a *%= blk: {
26882707 \\ const ref = &a;
2689 \\ ref.* = ref.* *% @bitCast(c_uint, @as(c_int, 1));
2708 \\ ref.* *%= @bitCast(c_uint, @as(c_int, 1));
26902709 \\ break :blk ref.*;
2691 \\ });
2692 \\ a &= (blk: {
2710 \\ };
2711 \\ a &= blk: {
26932712 \\ const ref = &a;
2694 \\ ref.* = ref.* & @bitCast(c_uint, @as(c_int, 1));
2713 \\ ref.* &= @bitCast(c_uint, @as(c_int, 1));
26952714 \\ break :blk ref.*;
2696 \\ });
2697 \\ a |= (blk: {
2715 \\ };
2716 \\ a |= blk: {
26982717 \\ const ref = &a;
2699 \\ ref.* = ref.* | @bitCast(c_uint, @as(c_int, 1));
2718 \\ ref.* |= @bitCast(c_uint, @as(c_int, 1));
27002719 \\ break :blk ref.*;
2701 \\ });
2702 \\ a ^= (blk: {
2720 \\ };
2721 \\ a ^= blk: {
27032722 \\ const ref = &a;
2704 \\ ref.* = ref.* ^ @bitCast(c_uint, @as(c_int, 1));
2723 \\ ref.* ^= @bitCast(c_uint, @as(c_int, 1));
27052724 \\ break :blk ref.*;
2706 \\ });
2707 \\ a >>= @intCast(@import("std").math.Log2Int(c_uint), (blk: {
2725 \\ };
2726 \\ a >>= @intCast(@import("std").math.Log2Int(c_uint), blk: {
27082727 \\ const ref = &a;
2709 \\ ref.* = ref.* >> @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1));
2728 \\ ref.* >>= @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1));
27102729 \\ break :blk ref.*;
2711 \\ }));
2712 \\ a <<= @intCast(@import("std").math.Log2Int(c_uint), (blk: {
2730 \\ });
2731 \\ a <<= @intCast(@import("std").math.Log2Int(c_uint), blk: {
27132732 \\ const ref = &a;
2714 \\ ref.* = ref.* << @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1));
2733 \\ ref.* <<= @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1));
27152734 \\ break :blk ref.*;
2716 \\ }));
2735 \\ });
27172736 \\}
27182737 });
27192738
......@@ -2738,30 +2757,30 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
27382757 \\ i -= 1;
27392758 \\ u +%= 1;
27402759 \\ u -%= 1;
2741 \\ i = (blk: {
2760 \\ i = blk: {
27422761 \\ const ref = &i;
27432762 \\ const tmp = ref.*;
27442763 \\ ref.* += 1;
27452764 \\ break :blk tmp;
2746 \\ });
2747 \\ i = (blk: {
2765 \\ };
2766 \\ i = blk: {
27482767 \\ const ref = &i;
27492768 \\ const tmp = ref.*;
27502769 \\ ref.* -= 1;
27512770 \\ break :blk tmp;
2752 \\ });
2753 \\ u = (blk: {
2771 \\ };
2772 \\ u = blk: {
27542773 \\ const ref = &u;
27552774 \\ const tmp = ref.*;
27562775 \\ ref.* +%= 1;
27572776 \\ break :blk tmp;
2758 \\ });
2759 \\ u = (blk: {
2777 \\ };
2778 \\ u = blk: {
27602779 \\ const ref = &u;
27612780 \\ const tmp = ref.*;
27622781 \\ ref.* -%= 1;
27632782 \\ break :blk tmp;
2764 \\ });
2783 \\ };
27652784 \\}
27662785 });
27672786
......@@ -2872,13 +2891,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
28722891 \\#define BAR (void*) a
28732892 \\#define BAZ (uint32_t)(2)
28742893 , &[_][]const u8{
2875 \\pub fn FOO(bar: anytype) callconv(.Inline) @TypeOf(baz((@import("std").meta.cast(?*c_void, baz)))) {
2876 \\ return baz((@import("std").meta.cast(?*c_void, baz)));
2894 \\pub fn FOO(bar: anytype) callconv(.Inline) @TypeOf(baz(@import("std").meta.cast(?*c_void, baz))) {
2895 \\ return baz(@import("std").meta.cast(?*c_void, baz));
28772896 \\}
28782897 ,
2879 \\pub const BAR = (@import("std").meta.cast(?*c_void, a));
2898 \\pub const BAR = @import("std").meta.cast(?*c_void, a);
28802899 ,
2881 \\pub const BAZ = (@import("std").meta.cast(u32, 2));
2900 \\pub const BAZ = @import("std").meta.cast(u32, 2);
28822901 });
28832902
28842903 cases.add("macro with cast to unsigned short, long, and long long",
......@@ -2886,9 +2905,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
28862905 \\#define CURLAUTH_BASIC ((unsigned long) 1)
28872906 \\#define CURLAUTH_BASIC_BUT_ULONGLONG ((unsigned long long) 1)
28882907 , &[_][]const u8{
2889 \\pub const CURLAUTH_BASIC_BUT_USHORT = (@import("std").meta.cast(c_ushort, 1));
2890 \\pub const CURLAUTH_BASIC = (@import("std").meta.cast(c_ulong, 1));
2891 \\pub const CURLAUTH_BASIC_BUT_ULONGLONG = (@import("std").meta.cast(c_ulonglong, 1));
2908 \\pub const CURLAUTH_BASIC_BUT_USHORT = @import("std").meta.cast(c_ushort, 1);
2909 \\pub const CURLAUTH_BASIC = @import("std").meta.cast(c_ulong, 1);
2910 \\pub const CURLAUTH_BASIC_BUT_ULONGLONG = @import("std").meta.cast(c_ulonglong, 1);
28922911 });
28932912
28942913 cases.add("macro conditional operator",
......@@ -2905,7 +2924,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
29052924 , &[_][]const u8{
29062925 \\pub fn foo() callconv(.C) void {
29072926 \\ if (true) while (true) {
2908 \\ if (!false) break;
2927 \\ break;
29092928 \\ };
29102929 \\}
29112930 });
......@@ -2923,27 +2942,27 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
29232942 \\}
29242943 });
29252944
2926 // TODO: detect to use different block labels here
2927 cases.add("nested assignment",
2928 \\int foo(int *p, int x) {
2929 \\ return *p++ = x;
2930 \\}
2931 , &[_][]const u8{
2932 \\pub export fn foo(arg_p: [*c]c_int, arg_x: c_int) c_int {
2933 \\ var p = arg_p;
2934 \\ var x = arg_x;
2935 \\ return blk: {
2936 \\ const tmp = x;
2937 \\ (blk_1: {
2938 \\ const ref = &p;
2939 \\ const tmp_2 = ref.*;
2940 \\ ref.* += 1;
2941 \\ break :blk_1 tmp_2;
2942 \\ }).?.* = tmp;
2943 \\ break :blk tmp;
2944 \\ };
2945 \\}
2946 });
2945 // TODO fix zig fmt here
2946 // cases.add("nested assignment",
2947 // \\int foo(int *p, int x) {
2948 // \\ return *p++ = x;
2949 // \\}
2950 // , &[_][]const u8{
2951 // \\pub export fn foo(arg_p: [*c]c_int, arg_x: c_int) c_int {
2952 // \\ var p = arg_p;
2953 // \\ var x = arg_x;
2954 // \\ return blk: {
2955 // \\ const tmp = x;
2956 // \\ (blk_1: {
2957 // \\ const ref = &p;
2958 // \\ const tmp_2 = ref.*;
2959 // \\ ref.* += 1;
2960 // \\ break :blk_1 tmp_2;
2961 // \\ }).?.* = tmp;
2962 // \\ break :blk tmp;
2963 // \\ };
2964 // \\}
2965 // });
29472966
29482967 cases.add("widening and truncating integer casting to different signedness",
29492968 \\unsigned long foo(void) {
......@@ -3033,10 +3052,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
30333052 , &[_][]const u8{
30343053 \\pub export fn foo(arg_x: bool) bool {
30353054 \\ var x = arg_x;
3036 \\ var a: bool = (@as(c_int, @boolToInt(x)) != @as(c_int, 1));
3037 \\ var b: bool = (@as(c_int, @boolToInt(a)) != @as(c_int, 0));
3055 \\ var a: bool = @as(c_int, @boolToInt(x)) != @as(c_int, 1);
3056 \\ var b: bool = @as(c_int, @boolToInt(a)) != @as(c_int, 0);
30383057 \\ var c: bool = @ptrToInt(foo) != 0;
3039 \\ return foo((@as(c_int, @boolToInt(c)) != @as(c_int, @boolToInt(b))));
3058 \\ return foo(@as(c_int, @boolToInt(c)) != @as(c_int, @boolToInt(b)));
30403059 \\}
30413060 });
30423061
......@@ -3106,8 +3125,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
31063125 \\#define DefaultScreen(dpy) (((_XPrivDisplay)(dpy))->default_screen)
31073126 \\
31083127 , &[_][]const u8{
3109 \\pub fn DefaultScreen(dpy: anytype) callconv(.Inline) @TypeOf((@import("std").meta.cast(_XPrivDisplay, dpy)).*.default_screen) {
3110 \\ return (@import("std").meta.cast(_XPrivDisplay, dpy)).*.default_screen;
3128 \\pub fn DefaultScreen(dpy: anytype) callconv(.Inline) @TypeOf(@import("std").meta.cast(_XPrivDisplay, dpy).*.default_screen) {
3129 \\ return @import("std").meta.cast(_XPrivDisplay, dpy).*.default_screen;
31113130 \\}
31123131 });
31133132
......@@ -3115,9 +3134,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
31153134 \\#define NULL ((void*)0)
31163135 \\#define FOO ((int)0x8000)
31173136 , &[_][]const u8{
3118 \\pub const NULL = (@import("std").meta.cast(?*c_void, 0));
3137 \\pub const NULL = @import("std").meta.cast(?*c_void, 0);
31193138 ,
3120 \\pub const FOO = (@import("std").meta.cast(c_int, 0x8000));
3139 \\pub const FOO = @import("std").meta.cast(c_int, 0x8000);
31213140 });
31223141
31233142 if (std.Target.current.abi == .msvc) {