| author | |
| committer | |
| log | a84951465b409495095a9598db0cae745f34fa7b |
| tree | b894e8c1ed03b96de8d09642e51038ae715cd2d5 |
| parent | 66b71273a2555da23f6d706c22e3d85f43fe602b |
3 files changed, 8 insertions(+), 3 deletions(-)
lib/compiler/aro_translate_c.zig+3-2| ... | @@ -1469,7 +1469,7 @@ pub fn ScopeExtra(comptime ScopeExtraContext: type, comptime ScopeExtraType: typ | ... | @@ -1469,7 +1469,7 @@ pub fn ScopeExtra(comptime ScopeExtraContext: type, comptime ScopeExtraType: typ |
| 1469 | 1469 | ||
| 1470 | pub fn getAlias(scope: *ScopeExtraScope, name: []const u8) []const u8 { | 1470 | pub fn getAlias(scope: *ScopeExtraScope, name: []const u8) []const u8 { |
| 1471 | return switch (scope.id) { | 1471 | return switch (scope.id) { |
| 1472 | .root => return name, | 1472 | .root => name, |
| 1473 | .block => @as(*Block, @fieldParentPtr("base", scope)).getAlias(name), | 1473 | .block => @as(*Block, @fieldParentPtr("base", scope)).getAlias(name), |
| 1474 | .loop, .do_loop, .condition => scope.parent.?.getAlias(name), | 1474 | .loop, .do_loop, .condition => scope.parent.?.getAlias(name), |
| 1475 | }; | 1475 | }; |
| ... | @@ -1477,11 +1477,12 @@ pub fn ScopeExtra(comptime ScopeExtraContext: type, comptime ScopeExtraType: typ | ... | @@ -1477,11 +1477,12 @@ pub fn ScopeExtra(comptime ScopeExtraContext: type, comptime ScopeExtraType: typ |
| 1477 | 1477 | ||
| 1478 | pub fn getLocalExternAlias(scope: *ScopeExtraScope, name: []const u8) ?[]const u8 { | 1478 | pub fn getLocalExternAlias(scope: *ScopeExtraScope, name: []const u8) ?[]const u8 { |
| 1479 | return switch (scope.id) { | 1479 | return switch (scope.id) { |
| 1480 | .root => null, | ||
| 1480 | .block => ret: { | 1481 | .block => ret: { |
| 1481 | const block = @as(*Block, @fieldParentPtr("base", scope)); | 1482 | const block = @as(*Block, @fieldParentPtr("base", scope)); |
| 1482 | break :ret block.getLocalExternAlias(name); | 1483 | break :ret block.getLocalExternAlias(name); |
| 1483 | }, | 1484 | }, |
| 1484 | .root, .loop, .do_loop, .condition => null, | 1485 | .loop, .do_loop, .condition => scope.parent.?.getLocalExternAlias(name), |
| 1485 | }; | 1486 | }; |
| 1486 | } | 1487 | } |
| 1487 | 1488 |
src/translate_c.zig+1-1| ... | @@ -1897,7 +1897,7 @@ fn transDeclRefExpr( | ... | @@ -1897,7 +1897,7 @@ fn transDeclRefExpr( |
| 1897 | const name = try c.str(@as(*const clang.NamedDecl, @ptrCast(value_decl)).getName_bytes_begin()); | 1897 | const name = try c.str(@as(*const clang.NamedDecl, @ptrCast(value_decl)).getName_bytes_begin()); |
| 1898 | const mangled_name = scope.getAlias(name); | 1898 | const mangled_name = scope.getAlias(name); |
| 1899 | const decl_is_var = @as(*const clang.Decl, @ptrCast(value_decl)).getKind() == .Var; | 1899 | const decl_is_var = @as(*const clang.Decl, @ptrCast(value_decl)).getKind() == .Var; |
| 1900 | const potential_local_extern = if (decl_is_var) ((@as(*const clang.VarDecl, @ptrCast(value_decl)).getStorageClass() == .Extern) and (scope.id == .block)) else false; | 1900 | const potential_local_extern = if (decl_is_var) ((@as(*const clang.VarDecl, @ptrCast(value_decl)).getStorageClass() == .Extern) and (scope.id != .root)) else false; |
| 1901 | 1901 | ||
| 1902 | var confirmed_local_extern = false; | 1902 | var confirmed_local_extern = false; |
| 1903 | var ref_expr = val: { | 1903 | var ref_expr = val: { |
test/cases/run_translated_c/extern_typedef_variables_in_functions.c+4| ... | @@ -4,6 +4,10 @@ static int func(void) | ... | @@ -4,6 +4,10 @@ static int func(void) |
| 4 | { | 4 | { |
| 5 | typedef int test_type_t; | 5 | typedef int test_type_t; |
| 6 | extern const test_type_t ev; | 6 | extern const test_type_t ev; |
| 7 | // Ensure mangled name is also being used for conditions and loops, see #20828 | ||
| 8 | if (ev == 0); | ||
| 9 | while (ev == 0); | ||
| 10 | do; while (ev == 0); | ||
| 7 | return ev + 2; | 11 | return ev + 2; |
| 8 | } | 12 | } |
| 9 | 13 |