Skip to content

Commit b8dd148

Browse files
committed
rustllvm: Add a GetOrInsertFunction wrapper
Fixes issue #1161 Test-case-by: Brian Anderson <[email protected]> Signed-off-by: Haitao Li <[email protected]>
1 parent 453168d commit b8dd148

File tree

5 files changed

+23
-1
lines changed

5 files changed

+23
-1
lines changed

src/comp/lib/llvm.rs

+2
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,8 @@ native "cdecl" mod llvm = "rustllvm" {
448448
fn LLVMGetNextFunction(Fn: ValueRef) -> ValueRef;
449449
fn LLVMGetPreviousFunction(Fn: ValueRef) -> ValueRef;
450450
fn LLVMDeleteFunction(Fn: ValueRef);
451+
fn LLVMGetOrInsertFunction(M: ModuleRef, Name: sbuf, FunctionTy: TypeRef)
452+
-> ValueRef;
451453
fn LLVMGetIntrinsicID(Fn: ValueRef) -> uint;
452454
fn LLVMGetFunctionCallConv(Fn: ValueRef) -> uint;
453455
fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: uint);

src/comp/middle/trans.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,8 @@ fn log_fn_time(ccx: @crate_ctxt, name: str, start: time::timeval,
301301

302302
fn decl_fn(llmod: ModuleRef, name: str, cc: uint, llty: TypeRef) -> ValueRef {
303303
let llfn: ValueRef =
304-
str::as_buf(name, {|buf| llvm::LLVMAddFunction(llmod, buf, llty) });
304+
str::as_buf(name, {|buf|
305+
llvm::LLVMGetOrInsertFunction(llmod, buf, llty) });
305306
llvm::LLVMSetFunctionCallConv(llfn, cc);
306307
ret llfn;
307308
}

src/rustllvm/RustWrapper.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,9 @@ extern "C" void LLVMRustEnableSegmentedStacks() {
141141
EnableSegmentedStacks = true;
142142
}
143143

144+
extern "C" LLVMValueRef LLVMGetOrInsertFunction(LLVMModuleRef M,
145+
const char* Name,
146+
LLVMTypeRef FunctionTy) {
147+
return wrap(unwrap(M)->getOrInsertFunction(Name,
148+
unwrap<FunctionType>(FunctionTy)));
149+
}

src/rustllvm/rustllvm.def.in

+1
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ LLVMGetNextParam
364364
LLVMGetNextUse
365365
LLVMGetNumOperands
366366
LLVMGetOperand
367+
LLVMGetOrInsertFunction
367368
LLVMGetParam
368369
LLVMGetParamParent
369370
LLVMGetParamTypes

src/test/run-pass/native-dupe.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
native "cdecl" mod rustrt1 = "rustrt" {
2+
fn pin_task();
3+
}
4+
5+
native "cdecl" mod rustrt2 = "rustrt" {
6+
fn pin_task();
7+
}
8+
9+
fn main() {
10+
rustrt1::pin_task();
11+
rustrt2::pin_task();
12+
}

0 commit comments

Comments
 (0)