]> git.lizzy.rs Git - rust.git/commitdiff
rustllvm: Add a GetOrInsertFunction wrapper
authorHaitao Li <lihaitao@gmail.com>
Mon, 14 Nov 2011 16:32:31 +0000 (00:32 +0800)
committerHaitao Li <lihaitao@gmail.com>
Mon, 14 Nov 2011 16:33:29 +0000 (00:33 +0800)
Fixes issue #1161

Test-case-by: Brian Anderson <banderson@mozilla.com>
Signed-off-by: Haitao Li <lihaitao@gmail.com>
src/comp/lib/llvm.rs
src/comp/middle/trans.rs
src/rustllvm/RustWrapper.cpp
src/rustllvm/rustllvm.def.in
src/test/run-pass/native-dupe.rs [new file with mode: 0644]

index f5b0fbeec8d8d55802272d0ade599df350ea08c0..83edf143f335140fdaadb28f8599ab77d760e2f5 100644 (file)
@@ -448,6 +448,8 @@ fn LLVMAddFunction(M: ModuleRef, Name: sbuf, FunctionTy: TypeRef) ->
     fn LLVMGetNextFunction(Fn: ValueRef) -> ValueRef;
     fn LLVMGetPreviousFunction(Fn: ValueRef) -> ValueRef;
     fn LLVMDeleteFunction(Fn: ValueRef);
+    fn LLVMGetOrInsertFunction(M: ModuleRef, Name: sbuf, FunctionTy: TypeRef)
+       -> ValueRef;
     fn LLVMGetIntrinsicID(Fn: ValueRef) -> uint;
     fn LLVMGetFunctionCallConv(Fn: ValueRef) -> uint;
     fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: uint);
index 8478061bc887dbfacd0d32444fdda777d0444995..36393213fb3103128cbf63e80118b858ec25adc0 100644 (file)
@@ -301,7 +301,8 @@ fn log_fn_time(ccx: @crate_ctxt, name: str, start: time::timeval,
 
 fn decl_fn(llmod: ModuleRef, name: str, cc: uint, llty: TypeRef) -> ValueRef {
     let llfn: ValueRef =
-        str::as_buf(name, {|buf| llvm::LLVMAddFunction(llmod, buf, llty) });
+        str::as_buf(name, {|buf|
+            llvm::LLVMGetOrInsertFunction(llmod, buf, llty) });
     llvm::LLVMSetFunctionCallConv(llfn, cc);
     ret llfn;
 }
index 26d0764934e05d1964cb6855cf8c5b1a3e0bb7f7..c0553b3c1d9ffaf82573a6eb8b874e86605ff69b 100644 (file)
@@ -141,3 +141,9 @@ extern "C" void LLVMRustEnableSegmentedStacks() {
   EnableSegmentedStacks = true;
 }
 
+extern "C" LLVMValueRef LLVMGetOrInsertFunction(LLVMModuleRef M,
+                                                const char* Name,
+                                                LLVMTypeRef FunctionTy) {
+  return wrap(unwrap(M)->getOrInsertFunction(Name,
+                                             unwrap<FunctionType>(FunctionTy)));
+}
index b418ba168c8814ef0495db2b079e860e5cb574be..9712ea60371226a3e4d3de407f3eae242f49a566 100644 (file)
@@ -364,6 +364,7 @@ LLVMGetNextParam
 LLVMGetNextUse
 LLVMGetNumOperands
 LLVMGetOperand
+LLVMGetOrInsertFunction
 LLVMGetParam
 LLVMGetParamParent
 LLVMGetParamTypes
diff --git a/src/test/run-pass/native-dupe.rs b/src/test/run-pass/native-dupe.rs
new file mode 100644 (file)
index 0000000..717db32
--- /dev/null
@@ -0,0 +1,12 @@
+native "cdecl" mod rustrt1 = "rustrt" {
+    fn pin_task();
+}
+
+native "cdecl" mod rustrt2 = "rustrt" {
+    fn pin_task();
+}
+
+fn main() {
+    rustrt1::pin_task();
+    rustrt2::pin_task();
+}