| ... | ... | @@ -287,6 +287,15 @@ pub fn supportsTailCall(target: std.Target) bool { |
| 287 | 287 | } |
| 288 | 288 | } |
| 289 | 289 | |
| 290 | /// TODO can this be done with simpler logic / different API binding? |
| 291 | fn deleteLlvmGlobal(llvm_global: *const llvm.Value) void { |
| 292 | if (llvm_global.globalGetValueType().getTypeKind() == .Function) { |
| 293 | llvm_global.deleteFunction(); |
| 294 | return; |
| 295 | } |
| 296 | return llvm_global.deleteGlobal(); |
| 297 | } |
| 298 | |
| 290 | 299 | pub const Object = struct { |
| 291 | 300 | gpa: Allocator, |
| 292 | 301 | module: *Module, |
| ... | ... | @@ -640,7 +649,7 @@ pub const Object = struct { |
| 640 | 649 | |
| 641 | 650 | const new_global_ptr = other_global.constBitCast(llvm_global.typeOf()); |
| 642 | 651 | llvm_global.replaceAllUsesWith(new_global_ptr); |
| 643 | | object.deleteLlvmGlobal(llvm_global); |
| 652 | deleteLlvmGlobal(llvm_global); |
| 644 | 653 | entry.value_ptr.* = new_global_ptr; |
| 645 | 654 | } |
| 646 | 655 | object.extern_collisions.clearRetainingCapacity(); |
| ... | ... | @@ -666,7 +675,7 @@ pub const Object = struct { |
| 666 | 675 | const new_global_ptr = llvm_global.constBitCast(other_global.typeOf()); |
| 667 | 676 | other_global.replaceAllUsesWith(new_global_ptr); |
| 668 | 677 | llvm_global.takeName(other_global); |
| 669 | | other_global.deleteGlobal(); |
| 678 | deleteLlvmGlobal(other_global); |
| 670 | 679 | // Problem: now we need to replace in the decl_map that |
| 671 | 680 | // the extern decl index points to this new global. However we don't |
| 672 | 681 | // know the decl index. |
| ... | ... | @@ -1184,15 +1193,6 @@ pub const Object = struct { |
| 1184 | 1193 | return null; |
| 1185 | 1194 | } |
| 1186 | 1195 | |
| 1187 | | /// TODO can this be done with simpler logic / different API binding? |
| 1188 | | fn deleteLlvmGlobal(o: Object, llvm_global: *const llvm.Value) void { |
| 1189 | | if (o.llvm_module.getNamedFunction(llvm_global.getValueName()) != null) { |
| 1190 | | llvm_global.deleteFunction(); |
| 1191 | | return; |
| 1192 | | } |
| 1193 | | return llvm_global.deleteGlobal(); |
| 1194 | | } |
| 1195 | | |
| 1196 | 1196 | pub fn updateDeclExports( |
| 1197 | 1197 | self: *Object, |
| 1198 | 1198 | module: *Module, |
| ... | ... | @@ -1287,7 +1287,7 @@ pub const Object = struct { |
| 1287 | 1287 | alias.setAliasee(llvm_global); |
| 1288 | 1288 | } else { |
| 1289 | 1289 | _ = self.llvm_module.addAlias( |
| 1290 | | llvm_global.typeOf(), |
| 1290 | llvm_global.globalGetValueType(), |
| 1291 | 1291 | 0, |
| 1292 | 1292 | llvm_global, |
| 1293 | 1293 | exp_name_z, |