Fix bug when a macro calling an extern function was called in another module also declaring and calling the same function. #1690

This commit is contained in:
Christoffer Lerno
2024-12-19 20:39:23 +01:00
parent 13509b9231
commit 627f10cd18
3 changed files with 31 additions and 2 deletions

View File

@@ -8,7 +8,7 @@ None
### Fixes
- Fix case trying to initialize a `char[*]*` from a String.
- Fix Map & HashMap `put_all_for_create` not copying all elements, causing `init_from_map` to create incomplete copy.
- Fix bug when a macro calling an extern function was called in another module also declaring and calling the same function. #1690
### Stdlib changes
- Increase BitWriter.write_bits limit up to 32 bits.
- Updates to `Slice2d`, like `get_xy` and others.

View File

@@ -1298,7 +1298,12 @@ LLVMValueRef llvm_get_ref(GenContext *c, Decl *decl)
}
else
{
backend_ref = decl->backend_ref = LLVMAddFunction(c->module, scratch_buffer_to_string(), type);
const char *name = scratch_buffer_to_string();
if (decl->is_extern && (backend_ref = LLVMGetNamedFunction(c->module, name)))
{
return decl->backend_ref = backend_ref;
}
backend_ref = decl->backend_ref = LLVMAddFunction(c->module, name, type);
}
llvm_append_function_attributes(c, decl);
llvm_set_decl_linkage(c, decl);

View File

@@ -0,0 +1,24 @@
// #target: macos-x64
module abc;
extern fn void puts(char*);
macro void test()
{
puts("b");
}
module test;
import abc;
extern fn void puts(char*);
fn void main()
{
puts("a");
abc::test();
}
/* #expect: test.ll
define void @test.main() #0 {
entry:
call void @puts(ptr @.str)
call void @puts(ptr @.str.1)
ret void
}