diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2018-08-25 03:55:32 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2018-08-25 03:55:59 -0400 |
| commit | 02f5a9fa62cc54835467e36b7015a6bcb642583d (patch) | |
| tree | d055b64c39ec3d544499256103f555a7f7005fd3 /src | |
| parent | b95ff12f2fb4aa5c20aecb789a91396557662287 (diff) | |
| download | zig-02f5a9fa62cc54835467e36b7015a6bcb642583d.tar.gz zig-02f5a9fa62cc54835467e36b7015a6bcb642583d.zip | |
fix handling multiple extern vars with the same name
Diffstat (limited to 'src')
| -rw-r--r-- | src/codegen.cpp | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp index 16595be9dd..56d15a43dc 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -5812,12 +5812,16 @@ static void do_code_gen(CodeGen *g) { LLVMValueRef global_value; if (var->linkage == VarLinkageExternal) { - global_value = LLVMAddGlobal(g->module, var->value->type->type_ref, buf_ptr(&var->name)); - - // TODO debug info for the extern variable + LLVMValueRef existing_llvm_var = LLVMGetNamedGlobal(g->module, buf_ptr(&var->name)); + if (existing_llvm_var) { + global_value = LLVMConstBitCast(existing_llvm_var, LLVMPointerType(var->value->type->type_ref, 0)); + } else { + global_value = LLVMAddGlobal(g->module, var->value->type->type_ref, buf_ptr(&var->name)); + // TODO debug info for the extern variable - LLVMSetLinkage(global_value, LLVMExternalLinkage); - LLVMSetAlignment(global_value, var->align_bytes); + LLVMSetLinkage(global_value, LLVMExternalLinkage); + LLVMSetAlignment(global_value, var->align_bytes); + } } else { bool exported = (var->linkage == VarLinkageExport); const char *mangled_name = buf_ptr(get_mangled_name(g, &var->name, exported)); |
