From 9d54400bba7eb04bca80fce97fa170452d19eaf1 Mon Sep 17 00:00:00 2001 From: Serge Guelton Date: Tue, 11 Apr 2017 15:01:18 +0000 Subject: Module::getOrInsertFunction is using C-style vararg instead of variadic templates. From a user prospective, it forces the use of an annoying nullptr to mark the end of the vararg, and there's not type checking on the arguments. The variadic template is an obvious solution to both issues. Differential Revision: https://reviews.llvm.org/D31070 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@299949 91177308-0d34-0410-b5e6-96231b3b80d8 --- examples/BrainF/BrainF.cpp | 8 ++++---- examples/BrainF/BrainFDriver.cpp | 2 +- examples/Fibonacci/fibonacci.cpp | 3 +-- examples/HowToUseJIT/HowToUseJIT.cpp | 7 ++----- examples/ParallelJIT/ParallelJIT.cpp | 6 ++---- 5 files changed, 10 insertions(+), 16 deletions(-) (limited to 'examples') diff --git a/examples/BrainF/BrainF.cpp b/examples/BrainF/BrainF.cpp index 91d813a6c3b..8af34d04701 100644 --- a/examples/BrainF/BrainF.cpp +++ b/examples/BrainF/BrainF.cpp @@ -74,18 +74,18 @@ void BrainF::header(LLVMContext& C) { //declare i32 @getchar() getchar_func = cast(module-> - getOrInsertFunction("getchar", IntegerType::getInt32Ty(C), NULL)); + getOrInsertFunction("getchar", IntegerType::getInt32Ty(C))); //declare i32 @putchar(i32) putchar_func = cast(module-> getOrInsertFunction("putchar", IntegerType::getInt32Ty(C), - IntegerType::getInt32Ty(C), NULL)); + IntegerType::getInt32Ty(C))); //Function header //define void @brainf() brainf_func = cast(module-> - getOrInsertFunction("brainf", Type::getVoidTy(C), NULL)); + getOrInsertFunction("brainf", Type::getVoidTy(C))); builder = new IRBuilder<>(BasicBlock::Create(C, label, brainf_func)); @@ -156,7 +156,7 @@ void BrainF::header(LLVMContext& C) { //declare i32 @puts(i8 *) Function *puts_func = cast(module-> getOrInsertFunction("puts", IntegerType::getInt32Ty(C), - PointerType::getUnqual(IntegerType::getInt8Ty(C)), NULL)); + PointerType::getUnqual(IntegerType::getInt8Ty(C)))); //brainf.aberror: aberrorbb = BasicBlock::Create(C, label, brainf_func); diff --git a/examples/BrainF/BrainFDriver.cpp b/examples/BrainF/BrainFDriver.cpp index d704506d244..65f8033a7e2 100644 --- a/examples/BrainF/BrainFDriver.cpp +++ b/examples/BrainF/BrainFDriver.cpp @@ -77,7 +77,7 @@ void addMainFunction(Module *mod) { getOrInsertFunction("main", IntegerType::getInt32Ty(mod->getContext()), IntegerType::getInt32Ty(mod->getContext()), PointerType::getUnqual(PointerType::getUnqual( - IntegerType::getInt8Ty(mod->getContext()))), NULL)); + IntegerType::getInt8Ty(mod->getContext()))))); { Function::arg_iterator args = main_func->arg_begin(); Value *arg_0 = &*args++; diff --git a/examples/Fibonacci/fibonacci.cpp b/examples/Fibonacci/fibonacci.cpp index 16e52bf0409..662cb01dd37 100644 --- a/examples/Fibonacci/fibonacci.cpp +++ b/examples/Fibonacci/fibonacci.cpp @@ -54,8 +54,7 @@ static Function *CreateFibFunction(Module *M, LLVMContext &Context) { // to return an int and take an int parameter. Function *FibF = cast(M->getOrInsertFunction("fib", Type::getInt32Ty(Context), - Type::getInt32Ty(Context), - nullptr)); + Type::getInt32Ty(Context))); // Add a basic block to the function. BasicBlock *BB = BasicBlock::Create(Context, "EntryBlock", FibF); diff --git a/examples/HowToUseJIT/HowToUseJIT.cpp b/examples/HowToUseJIT/HowToUseJIT.cpp index 0050d27b45d..f141fa5a7f5 100644 --- a/examples/HowToUseJIT/HowToUseJIT.cpp +++ b/examples/HowToUseJIT/HowToUseJIT.cpp @@ -69,11 +69,9 @@ int main() { // Create the add1 function entry and insert this entry into module M. The // function will have a return type of "int" and take an argument of "int". - // The '0' terminates the list of argument types. Function *Add1F = cast(M->getOrInsertFunction("add1", Type::getInt32Ty(Context), - Type::getInt32Ty(Context), - nullptr)); + Type::getInt32Ty(Context))); // Add a basic block to the function. As before, it automatically inserts // because of the last argument. @@ -102,8 +100,7 @@ int main() { // Now we're going to create function `foo', which returns an int and takes no // arguments. Function *FooF = - cast(M->getOrInsertFunction("foo", Type::getInt32Ty(Context), - nullptr)); + cast(M->getOrInsertFunction("foo", Type::getInt32Ty(Context))); // Add a basic block to the FooF function. BB = BasicBlock::Create(Context, "EntryBlock", FooF); diff --git a/examples/ParallelJIT/ParallelJIT.cpp b/examples/ParallelJIT/ParallelJIT.cpp index 6fb8bd61982..f1932d2471c 100644 --- a/examples/ParallelJIT/ParallelJIT.cpp +++ b/examples/ParallelJIT/ParallelJIT.cpp @@ -54,8 +54,7 @@ static Function* createAdd1(Module *M) { Function *Add1F = cast(M->getOrInsertFunction("add1", Type::getInt32Ty(M->getContext()), - Type::getInt32Ty(M->getContext()), - nullptr)); + Type::getInt32Ty(M->getContext()))); // Add a basic block to the function. As before, it automatically inserts // because of the last argument. @@ -85,8 +84,7 @@ static Function *CreateFibFunction(Module *M) { Function *FibF = cast(M->getOrInsertFunction("fib", Type::getInt32Ty(M->getContext()), - Type::getInt32Ty(M->getContext()), - nullptr)); + Type::getInt32Ty(M->getContext()))); // Add a basic block to the function. BasicBlock *BB = BasicBlock::Create(M->getContext(), "EntryBlock", FibF); -- cgit v1.2.3