diff --git a/releasenotes.md b/releasenotes.md index a79014f2c..0ae7edaa0 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -31,6 +31,7 @@ - Issue where trailing body argument was allowed without type even though the definition specified it #1879. - Fix issues with @jump on empty `default` or only `default` #1893 #1894 - Fixes miscompilation of nested `@jump` #1896. +- Fixed STB_WEAK errors when using consts in macros in the stdlib #1871. ### Stdlib changes - Added '%h' and '%H' for printing out binary data in hexadecimal using the formatter. diff --git a/src/compiler/sema_decls.c b/src/compiler/sema_decls.c index efb9f9de8..7f1b985ad 100755 --- a/src/compiler/sema_decls.c +++ b/src/compiler/sema_decls.c @@ -4049,6 +4049,8 @@ bool sema_analyse_var_decl(SemaContext *context, Decl *decl, bool local) is_global = true; break; case VARDECL_CONST: + if (local) decl->var.is_static = true; + break; default: break; } diff --git a/test/test_suite/variables/const_in_func.c3t b/test/test_suite/variables/const_in_func.c3t new file mode 100644 index 000000000..fadc81f34 --- /dev/null +++ b/test/test_suite/variables/const_in_func.c3t @@ -0,0 +1,19 @@ +// #target: linux-x64 +module scratch; +import std::test; +fn void main() +{ + int x = test::abc(); +} + +module std::test; + +macro abc() +{ + const int A = 256; + return A; +} + +/* #expect: scratch.ll + +@main.A = internal local_unnamed_addr constant i32 256, align 4 \ No newline at end of file