Also weaken libc and generic templates.

This commit is contained in:
Christoffer Lerno
2024-10-12 02:13:35 +02:00
parent a38c7f6e49
commit 8ce171877e
8 changed files with 29 additions and 50 deletions

View File

@@ -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;

View File

@@ -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)

View File

@@ -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");

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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: