mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
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:
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
|
||||
24
test/test_suite/abi/linking_extern.c3t
Normal file
24
test/test_suite/abi/linking_extern.c3t
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user