authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-10-24 15:17:01+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-10-27 01:31:18+03:00
log4fc944dde813638410850515b0d1b156e5b6e920
tree57af939346f904b0da8348d10de6666a1e948022
parentd773b7e71f8d9fd3d69c1f90cec9a941fc9f9a12

translate-c: fix redefinition of label on left recursive comma operator

Closes #13239

4 files changed, 10 insertions(+), 7 deletions(-)

src/translate_c.zig+4-3
......@@ -5651,13 +5651,14 @@ const ParseError = Error || error{ParseError};
56515651
56525652fn parseCExpr(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!Node {
56535653 // TODO parseCAssignExpr here
5654 const node = try parseCCondExpr(c, m, scope);
5654 var block_scope = try Scope.Block.init(c, scope, true);
5655 defer block_scope.deinit();
5656
5657 const node = try parseCCondExpr(c, m, &block_scope.base);
56555658 if (m.next().? != .Comma) {
56565659 m.i -= 1;
56575660 return node;
56585661 }
5659 var block_scope = try Scope.Block.init(c, scope, true);
5660 defer block_scope.deinit();
56615662
56625663 var last = node;
56635664 while (true) {
test/behavior/translate_c_macros.h+1
......@@ -40,6 +40,7 @@ union U {
4040#define CAST_OR_CALL_WITH_PARENS(type_or_fn, val) ((type_or_fn)(val))
4141
4242#define NESTED_COMMA_OPERATOR (1, (2, 3))
43#define NESTED_COMMA_OPERATOR_LHS (1, 2), 3
4344
4445#include <stdint.h>
4546#if !defined(__UINTPTR_MAX__)
test/behavior/translate_c_macros.zig+1
......@@ -100,6 +100,7 @@ test "nested comma operator" {
100100 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
101101
102102 try expectEqual(@as(c_int, 3), h.NESTED_COMMA_OPERATOR);
103 try expectEqual(@as(c_int, 3), h.NESTED_COMMA_OPERATOR_LHS);
103104}
104105
105106test "cast functions" {
test/translate_c.zig+4-4
......@@ -499,20 +499,20 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
499499 \\int baz(int x, int y) { return 0; }
500500 \\#define bar(x) (&x, +3, 4 == 4, 5 * 6, baz(1, 2), 2 % 2, baz(1,2))
501501 , &[_][]const u8{
502 \\pub const foo = blk: {
502 \\pub const foo = blk_1: {
503503 \\ _ = @TypeOf(foo);
504 \\ break :blk bar;
504 \\ break :blk_1 bar;
505505 \\};
506506 ,
507507 \\pub inline fn bar(x: anytype) @TypeOf(baz(@as(c_int, 1), @as(c_int, 2))) {
508 \\ return blk: {
508 \\ return blk_1: {
509509 \\ _ = &x;
510510 \\ _ = @as(c_int, 3);
511511 \\ _ = @as(c_int, 4) == @as(c_int, 4);
512512 \\ _ = @as(c_int, 5) * @as(c_int, 6);
513513 \\ _ = baz(@as(c_int, 1), @as(c_int, 2));
514514 \\ _ = @as(c_int, 2) % @as(c_int, 2);
515 \\ break :blk baz(@as(c_int, 1), @as(c_int, 2));
515 \\ break :blk_1 baz(@as(c_int, 1), @as(c_int, 2));
516516 \\ };
517517 \\}
518518 });