Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/compiler/aro_translate_c.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1469,19 +1469,20 @@ pub fn ScopeExtra(comptime ScopeExtraContext: type, comptime ScopeExtraType: typ

pub fn getAlias(scope: *ScopeExtraScope, name: []const u8) []const u8 {
return switch (scope.id) {
.root => return name,
.root => name,
.block => @as(*Block, @fieldParentPtr("base", scope)).getAlias(name),
.loop, .do_loop, .condition => scope.parent.?.getAlias(name),
};
}

pub fn getLocalExternAlias(scope: *ScopeExtraScope, name: []const u8) ?[]const u8 {
return switch (scope.id) {
.root => null,
.block => ret: {
const block = @as(*Block, @fieldParentPtr("base", scope));
break :ret block.getLocalExternAlias(name);
},
.root, .loop, .do_loop, .condition => null,
.loop, .do_loop, .condition => scope.parent.?.getLocalExternAlias(name),
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/translate_c.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1897,7 +1897,7 @@ fn transDeclRefExpr(
const name = try c.str(@as(*const clang.NamedDecl, @ptrCast(value_decl)).getName_bytes_begin());
const mangled_name = scope.getAlias(name);
const decl_is_var = @as(*const clang.Decl, @ptrCast(value_decl)).getKind() == .Var;
const potential_local_extern = if (decl_is_var) ((@as(*const clang.VarDecl, @ptrCast(value_decl)).getStorageClass() == .Extern) and (scope.id == .block)) else false;
const potential_local_extern = if (decl_is_var) ((@as(*const clang.VarDecl, @ptrCast(value_decl)).getStorageClass() == .Extern) and (scope.id != .root)) else false;

var confirmed_local_extern = false;
var ref_expr = val: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ static int func(void)
{
typedef int test_type_t;
extern const test_type_t ev;
// Ensure mangled name is also being used for conditions and loops, see #20828
if (ev == 0);
while (ev == 0);
do; while (ev == 0);
return ev + 2;
}

Expand Down