Skip to content

Commit

Permalink
Also weaken libc and generic templates.
Browse files Browse the repository at this point in the history
  • Loading branch information
lerno committed Oct 12, 2024
1 parent a38c7f6 commit 8ce1718
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 50 deletions.
1 change: 1 addition & 0 deletions src/compiler/compiler_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/llvm_codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/compiler/symtab.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
35 changes: 5 additions & 30 deletions test/test_suite/functions/test_regression.c3t
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 12 additions & 12 deletions test/test_suite/functions/test_regression_mingw.c3t
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

10 changes: 5 additions & 5 deletions test/test_suite/generic/generic_idents.c3t
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/test_suite/generic/generic_over_fn.c3t
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/test_suite/import/access_other_module.c3t
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 8ce1718

Please sign in to comment.