From 8ce171877e84773352398650218d7f813625b1de Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Sat, 12 Oct 2024 02:13:35 +0200 Subject: [PATCH] Also weaken libc and generic templates. --- src/compiler/compiler_internal.h | 1 + src/compiler/llvm_codegen.c | 3 +- src/compiler/symtab.c | 2 ++ test/test_suite/functions/test_regression.c3t | 35 +++---------------- .../functions/test_regression_mingw.c3t | 24 ++++++------- test/test_suite/generic/generic_idents.c3t | 10 +++--- test/test_suite/generic/generic_over_fn.c3t | 2 +- .../test_suite/import/access_other_module.c3t | 2 +- 8 files changed, 29 insertions(+), 50 deletions(-) diff --git a/src/compiler/compiler_internal.h b/src/compiler/compiler_internal.h index a7db3f3b7..d4db80292 100644 --- a/src/compiler/compiler_internal.h +++ b/src/compiler/compiler_internal.h @@ -1886,6 +1886,7 @@ extern const char *kw_at_jump; extern const char *kw_in; extern const char *kw_inout; extern const char *kw_len; +extern const char *kw_libc; extern const char *kw_main; extern const char *kw_mainstub; extern const char *kw_memcmp; diff --git a/src/compiler/llvm_codegen.c b/src/compiler/llvm_codegen.c index f1dd0a412..d83cb7793 100644 --- a/src/compiler/llvm_codegen.c +++ b/src/compiler/llvm_codegen.c @@ -51,8 +51,9 @@ static void diagnostics_handler(LLVMDiagnosticInfoRef ref, void *context) bool module_should_weaken(Module *module) { + if (module->generic_module) return true; Module *top = module->top_module; - return top && top->name->module == kw_std; + return top && (top->name->module == kw_std || top->name->module == kw_libc); } static void gencontext_init(GenContext *context, Module *module, LLVMContextRef shared_context) diff --git a/src/compiler/symtab.c b/src/compiler/symtab.c index 6fedd04ab..045bdcb49 100644 --- a/src/compiler/symtab.c +++ b/src/compiler/symtab.c @@ -50,6 +50,7 @@ const char *kw_at_jump; const char *kw_in; const char *kw_inout; const char *kw_len; +const char *kw_libc; const char *kw_main; const char *kw_memcmp; const char *kw_mainstub; @@ -134,6 +135,7 @@ void symtab_init(uint32_t capacity) type = TOKEN_IDENT; kw_in = KW_DEF("in"); kw_inout = KW_DEF("inout"); + kw_libc = KW_DEF("libc"); kw_mainstub = KW_DEF("_$main"); kw_main = KW_DEF("main"); kw_memcmp = KW_DEF("memcmp"); diff --git a/test/test_suite/functions/test_regression.c3t b/test/test_suite/functions/test_regression.c3t index f54d33026..1ce3dda56 100644 --- a/test/test_suite/functions/test_regression.c3t +++ b/test/test_suite/functions/test_regression.c3t @@ -555,51 +555,26 @@ entry: // #expect: foo.double.ll -define double @"foo$double$.check"(double %0) +define weak double @"foo$double$.check"(double %0) entry: %fmul = fmul double %0, %0 ret double %fmul - -// #expect: test2.int.ll - -%Blob = type { i32 } -@"test2$int$.argh" = local_unnamed_addr global i32 234, align 4 - -define i32 @"test2$int$.getMult"(i32 %0) #0 { -entry: - %mul = mul i32 %0, %0 - ret i32 %mul -} - -define i32 @"test2$int$.hello"() #0 { -entry: - ret i32 1 -} - -define i32 @"test2$int$.getValue"(i32 %0) #0 { -entry: - %blob = alloca %Blob, align 4 - store i32 %0, ptr %blob, align 4 - %1 = load i32, ptr %blob, align 4 - ret i32 %1 -} - // #expect: test2.double.ll %Blob = type { double } -@"test2$double$.argh" = local_unnamed_addr global double 2.340000e+02, align 8 +@"test2$double$.argh" = weak local_unnamed_addr global double 2.340000e+02, align 8 -define double @"test2$double$.getMult"(double %0) +define weak double @"test2$double$.getMult"(double %0) entry: %fmul = fmul double %0, %0 ret double %fmul -define i32 @"test2$double$.hello"() +define weak i32 @"test2$double$.hello"() entry: ret i32 1 -define double @"test2$double$.getValue"(double %0) +define weak double @"test2$double$.getValue"(double %0) entry: %blob = alloca %Blob, align 8 store double %0, ptr %blob, align 8 diff --git a/test/test_suite/functions/test_regression_mingw.c3t b/test/test_suite/functions/test_regression_mingw.c3t index a76ff9ab0..efd96f68e 100644 --- a/test/test_suite/functions/test_regression_mingw.c3t +++ b/test/test_suite/functions/test_regression_mingw.c3t @@ -625,7 +625,7 @@ entry: // #expect: foo.double.ll -define double @"foo$double$.check"(double %0) +define weak double @"foo$double$.check"(double %0) entry: %fmul = fmul double %0, %0 ret double %fmul @@ -634,19 +634,18 @@ entry: // #expect: test2.int.ll %Blob = type { i32 } -@"test2$int$.argh" = local_unnamed_addr global i32 234, align 4 +@"test2$int$.argh" = weak local_unnamed_addr global i32 234, comdat, align 4 -define i32 @"test2$int$.getMult"(i32 %0) +define weak i32 @"test2$int$.getMult"(i32 %0) entry: %mul = mul i32 %0, %0 ret i32 %mul -define i32 @"test2$int$.hello"() +define weak i32 @"test2$int$.hello"() entry: ret i32 1 } - -define i32 @"test2$int$.getValue"(i32 %0) +define weak i32 @"test2$int$.getValue"(i32 %0) entry: %blob = alloca %Blob, align 4 store i32 %0, ptr %blob, align 4 @@ -657,22 +656,23 @@ entry: // #expect: test2.double.ll %Blob = type { double } -@"test2$double$.argh" = local_unnamed_addr global double 2.340000e+02, align 8 -define double @"test2$double$.getMult"(double %0) + +@"test2$double$.argh" = weak local_unnamed_addr global double 2.340000e+02, comdat, align 8 + +define weak double @"test2$double$.getMult"(double %0) #0 comdat { entry: %fmul = fmul double %0, %0 ret double %fmul - -define i32 @"test2$double$.hello"() +define weak i32 @"test2$double$.hello"() #0 comdat { entry: ret i32 1 +} -define double @"test2$double$.getValue"(i64 %0) +define weak double @"test2$double$.getValue"(i64 %0) #0 comdat { entry: %blob = alloca %Blob, align 8 store i64 %0, ptr %blob, align 8 %1 = load double, ptr %blob, align 8 ret double %1 - diff --git a/test/test_suite/generic/generic_idents.c3t b/test/test_suite/generic/generic_idents.c3t index c6c20e595..a5615128b 100644 --- a/test/test_suite/generic/generic_idents.c3t +++ b/test/test_suite/generic/generic_idents.c3t @@ -29,13 +29,13 @@ fn double getIt2(double i) /* #expect: gen.int.ll -define i32 @"gen$int$.mult"(i32 %0) #0 { +define weak i32 @"gen$int$.mult"(i32 %0) #0 { entry: %mul = mul i32 %0, %0 ret i32 %mul } -define i32 @"gen$int$.addMult"(i32 %0, i32 %1, i32 %2) #0 { +define weak i32 @"gen$int$.addMult"(i32 %0, i32 %1, i32 %2) #0 { entry: %mul = mul i32 %0, %1 %add = add i32 %mul, %2 @@ -58,14 +58,14 @@ entry: ret double %1 } -declare i32 @"gen$int$.mult"(i32) +declare extern_weak i32 @"gen$int$.mult"(i32) -declare double @"gen$double$.addMult"(double, double, double) +declare extern_weak double @"gen$double$.addMult"(double, double, double) // #expect: gen.double.ll -define double @"gen$double$.addMult"(double %0, double %1, double %2) +define weak double @"gen$double$.addMult"(double %0, double %1, double %2) entry: %fmul = fmul double %0, %1 %fadd = fadd double %fmul, %2 diff --git a/test/test_suite/generic/generic_over_fn.c3t b/test/test_suite/generic/generic_over_fn.c3t index 528bf59ed..0a45cd42f 100644 --- a/test/test_suite/generic/generic_over_fn.c3t +++ b/test/test_suite/generic/generic_over_fn.c3t @@ -205,5 +205,5 @@ loop.exit: ; preds = %loop.cond ret void } +declare extern_weak void @"test_generic$sa$int$fn$int$int$$int$$.sort"(ptr, i64, i64, i64, ptr) #0 -declare void @"test_generic$sa$int$fn$int$int$$int$$.sort"(ptr, i64, i64, i64, ptr) #0 diff --git a/test/test_suite/import/access_other_module.c3t b/test/test_suite/import/access_other_module.c3t index 118976d07..4853506ca 100644 --- a/test/test_suite/import/access_other_module.c3t +++ b/test/test_suite/import/access_other_module.c3t @@ -9,7 +9,7 @@ fn void main() /* #expect: foo.ll -@libc.EXIT_SUCCESS = external constant i32, align 4 +@libc.EXIT_SUCCESS = extern_weak constant i32, align 4 define void @foo.main() #0 { entry: