diff --git a/releasenotes.md b/releasenotes.md index 385315ba9..b28bedccf 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -12,6 +12,7 @@ - Bitstruct truncated constant error escapes `$defined` #2515. - Compiler segfault when accessing member of number cast to bitstruct #2516. - Compiler assert when getting a member of a `bitstruct : char @bigendian` #2517. +- Incorrect visibility on local globals with public aliases. #2519 ### Stdlib changes diff --git a/src/compiler/sema_decls.c b/src/compiler/sema_decls.c index 3696c219f..7875c0c95 100755 --- a/src/compiler/sema_decls.c +++ b/src/compiler/sema_decls.c @@ -5302,6 +5302,10 @@ static inline bool sema_analyse_alias(SemaContext *context, Decl *decl, bool *er } decl->type = symbol->type; decl->define_decl.alias = symbol; + if (decl_is_externally_visible(decl) && !decl_is_externally_visible(symbol)) + { + symbol->is_external_visible = true; + } return true; } diff --git a/test/test_suite/define/alias_visibility.c3t b/test/test_suite/define/alias_visibility.c3t new file mode 100644 index 000000000..036aff445 --- /dev/null +++ b/test/test_suite/define/alias_visibility.c3t @@ -0,0 +1,20 @@ +// #target: macos-x64 +module test1; +alias x = y; +int y @local = 1; + +module test; +import test1; + +fn int main(String[] args) +{ + return test1::x; +} + +/* #expect: test1.ll + +@test1.y.10 = local_unnamed_addr global i32 1, align 4 + +// #expect: test.ll + +@test1.y.10 = external global i32, align 4 \ No newline at end of file