aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/IR/FunctionTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/unittests/IR/FunctionTest.cpp')
-rw-r--r--llvm/unittests/IR/FunctionTest.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/llvm/unittests/IR/FunctionTest.cpp b/llvm/unittests/IR/FunctionTest.cpp
index 7ba7584..8ed7699 100644
--- a/llvm/unittests/IR/FunctionTest.cpp
+++ b/llvm/unittests/IR/FunctionTest.cpp
@@ -625,4 +625,23 @@ TEST(FunctionTest, Personality) {
EXPECT_FALSE(LLVMHasPersonalityFn(wrap(F)));
}
+TEST(FunctionTest, LLVMGetOrInsertFunction) {
+ LLVMContext Ctx;
+ Module M("test", Ctx);
+ Type *Int8Ty = Type::getInt8Ty(Ctx);
+ FunctionType *FTy = FunctionType::get(Int8Ty, false);
+
+ // Create the function using the C API
+ LLVMValueRef FuncRef = LLVMGetOrInsertFunction(wrap(&M), "F", 1, wrap(FTy));
+
+ // Verify that the returned value is a function and has the correct type
+ Function *Func = unwrap<Function>(FuncRef);
+ EXPECT_EQ(Func->getName(), "F");
+ EXPECT_EQ(Func->getFunctionType(), FTy);
+
+ // Call LLVMGetOrInsertFunction again to ensure it returns the same function
+ LLVMValueRef FuncRef2 = LLVMGetOrInsertFunction(wrap(&M), "F", 1, wrap(FTy));
+ EXPECT_EQ(FuncRef, FuncRef2);
+}
+
} // end namespace