diff --git a/src-self-hosted/translate_c.zig b/src-self-hosted/translate_c.zig index 934ed3634d..40e7d7f79d 100644 --- a/src-self-hosted/translate_c.zig +++ b/src-self-hosted/translate_c.zig @@ -5375,7 +5375,7 @@ fn parseCPrimaryExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8, const first_tok = it.list.at(0); const token = try appendToken(c, .CharLiteral, try zigifyEscapeSequences(c, source[tok.start..tok.end], source[first_tok.start..first_tok.end], source_loc)); const node = try c.a().create(ast.Node.CharLiteral); - node.* = ast.Node.CharLiteral{ + node.* = .{ .token = token, }; return &node.base; @@ -5384,7 +5384,7 @@ fn parseCPrimaryExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8, const first_tok = it.list.at(0); const token = try appendToken(c, .StringLiteral, try zigifyEscapeSequences(c, source[tok.start..tok.end], source[first_tok.start..first_tok.end], source_loc)); const node = try c.a().create(ast.Node.StringLiteral); - node.* = ast.Node.StringLiteral{ + node.* = .{ .token = token, }; return &node.base; @@ -5793,12 +5793,13 @@ fn parseCSuffixOpExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8, return node; }, } + const cast_fn = if (bool_op) macroIntToBool else macroBoolToInt; + const lhs_node = try cast_fn(c, node); const rhs_node = try parseCPrefixOpExpr(c, it, source, source_loc, scope); const op_node = try c.a().create(ast.Node.InfixOp); - const cast_fn = if (bool_op) macroIntToBool else macroBoolToInt; op_node.* = .{ .op_token = op_token, - .lhs = try cast_fn(c, node), + .lhs = lhs_node, .op = op_id, .rhs = try cast_fn(c, rhs_node), }; diff --git a/test/translate_c.zig b/test/translate_c.zig index 29b07b86a9..9890c4034e 100644 --- a/test/translate_c.zig +++ b/test/translate_c.zig @@ -3,6 +3,14 @@ const std = @import("std"); const CrossTarget = std.zig.CrossTarget; pub fn addCases(cases: *tests.TranslateCContext) void { + cases.add("correct semicolon after infixop", + \\#define __ferror_unlocked_body(_fp) (((_fp)->_flags & _IO_ERR_SEEN) != 0) + , &[_][]const u8{ + \\pub inline fn __ferror_unlocked_body(_fp: var) @TypeOf(((_fp.*._flags) & _IO_ERR_SEEN) != 0) { + \\ return ((_fp.*._flags) & _IO_ERR_SEEN) != 0; + \\} + }); + cases.add("c booleans are just ints", \\#define FOO(x) ((x >= 0) + (x >= 0)) \\#define BAR 1 && 2 > 4