[CUDA] Fix crash with printf without any _cl_var_arg calls
@@ -217,7 +217,8 @@ void pocl_cuda_fix_printf(llvm::Module *module)
// Replace calls to _cl_va_arg with reads from new i64 array argument
llvm::Function *cl_va_arg = module->getFunction("_cl_va_arg");
- assert(cl_va_arg);
+ if (cl_va_arg)
+ {
llvm::Argument *args_in = &*++new_cl_printf->getArgumentList().begin();
std::vector<llvm::Value*> va_arg_calls(cl_va_arg->users().begin(),
cl_va_arg->users().end());
@@ -255,6 +256,10 @@ void pocl_cuda_fix_printf(llvm::Module *module)
call->eraseFromParent();
}
+ // Remove function from module
+ cl_va_arg->eraseFromParent();
+ }
+
// Loop over function callers
// Generate array of i64 arguments to replace variadic arguments
std::vector<llvm::Value*> callers(cl_printf->users().begin(),
@@ -315,8 +320,7 @@ void pocl_cuda_fix_printf(llvm::Module *module)
new_arg->takeName(&*old_arg);
old_arg->replaceAllUsesWith(&*new_arg);
- // Remove old functions
- cl_va_arg->eraseFromParent();
+ // Remove old function
cl_printf->eraseFromParent();
}
