diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2017-03-23 02:59:58 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2017-03-23 02:59:58 -0400 |
| commit | d6856859d3082d9b66aac7c25ceb2abcd13e2f7c (patch) | |
| tree | dacade36cf18d88b1c21414130b33da91d7f7784 /src/codegen.cpp | |
| parent | 01b2bf4a44c586f2fa51e8824be608b92d82fed4 (diff) | |
| download | zig-d6856859d3082d9b66aac7c25ceb2abcd13e2f7c.tar.gz zig-d6856859d3082d9b66aac7c25ceb2abcd13e2f7c.zip | |
improvements for windows and libc integration
* standard library knows if it is linking against libc and will
sometimes call libc functions in that case instead of providing
redundant definitions
* fix infinite loop bug when resolving use declarations
* allow calling the same C function from different C imports.
closes #277
* push more logic from compiler to std/bootstrap.zig
* standard library provides way to access errno
closes #274
* fix compile error in standard library for windows
* add implementation of getRandomBytes for windows
Diffstat (limited to 'src/codegen.cpp')
| -rw-r--r-- | src/codegen.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp index 3babaac0e4..03629b2da1 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -272,7 +272,17 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) { } TypeTableEntry *fn_type = fn_table_entry->type_entry; - fn_table_entry->llvm_value = LLVMAddFunction(g->module, buf_ptr(symbol_name), fn_type->data.fn.raw_type_ref); + LLVMTypeRef fn_llvm_type = fn_type->data.fn.raw_type_ref; + if (!fn_table_entry->internal_linkage && fn_table_entry->body_node == nullptr) { + LLVMValueRef existing_llvm_fn = LLVMGetNamedFunction(g->module, buf_ptr(symbol_name)); + if (existing_llvm_fn) { + fn_table_entry->llvm_value = LLVMConstBitCast(existing_llvm_fn, LLVMPointerType(fn_llvm_type, 0)); + } else { + fn_table_entry->llvm_value = LLVMAddFunction(g->module, buf_ptr(symbol_name), fn_llvm_type); + } + } else { + fn_table_entry->llvm_value = LLVMAddFunction(g->module, buf_ptr(symbol_name), fn_llvm_type); + } switch (fn_table_entry->fn_inline) { case FnInlineAlways: |
