diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2025-02-03 18:51:27 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2025-02-03 18:51:27 +0000 |
| commit | 32a711e1c447004eb1fd015925f305ed1d8426de (patch) | |
| tree | 6647b84917053748367f573f9bdc66e809cb17f5 /llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp | |
| parent | ac9a064cb179f3425b310fa2847f8764ac970a4d (diff) | |
Diffstat (limited to 'llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp')
| -rw-r--r-- | llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp index a3cc9bae4708..4fe1df0ab3e4 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp @@ -86,9 +86,9 @@ static void findUses(Value *V, Function &F, // Create a wrapper function with type Ty that calls F (which may have a // different type). Attempt to support common bitcasted function idioms: // - Call with more arguments than needed: arguments are dropped -// - Call with fewer arguments than needed: arguments are filled in with undef +// - Call with fewer arguments than needed: arguments are filled in with poison // - Return value is not needed: drop it -// - Return value needed but not present: supply an undef +// - Return value needed but not present: supply a poison value // // If the all the argument types of trivially castable to one another (i.e. // I32 vs pointer type) then we don't create a wrapper at all (return nullptr @@ -111,6 +111,7 @@ static Function *createWrapper(Function *F, FunctionType *Ty) { Function *Wrapper = Function::Create(Ty, Function::PrivateLinkage, F->getName() + "_bitcast", M); + Wrapper->setAttributes(F->getAttributes()); BasicBlock *BB = BasicBlock::Create(M->getContext(), "body", Wrapper); const DataLayout &DL = BB->getDataLayout(); @@ -160,7 +161,7 @@ static Function *createWrapper(Function *F, FunctionType *Ty) { if (WrapperNeeded && !TypeMismatch) { for (; PI != PE; ++PI) - Args.push_back(UndefValue::get(*PI)); + Args.push_back(PoisonValue::get(*PI)); if (F->isVarArg()) for (; AI != AE; ++AI) Args.push_back(&*AI); @@ -174,7 +175,7 @@ static Function *createWrapper(Function *F, FunctionType *Ty) { ReturnInst::Create(M->getContext(), BB); } else if (ExpectedRtnType->isVoidTy()) { LLVM_DEBUG(dbgs() << "Creating dummy return: " << *RtnType << "\n"); - ReturnInst::Create(M->getContext(), UndefValue::get(RtnType), BB); + ReturnInst::Create(M->getContext(), PoisonValue::get(RtnType), BB); } else if (RtnType == ExpectedRtnType) { ReturnInst::Create(M->getContext(), Call, BB); } else if (CastInst::isBitOrNoopPointerCastable(ExpectedRtnType, RtnType, @@ -201,6 +202,7 @@ static Function *createWrapper(Function *F, FunctionType *Ty) { Wrapper->eraseFromParent(); Wrapper = Function::Create(Ty, Function::PrivateLinkage, F->getName() + "_bitcast_invalid", M); + Wrapper->setAttributes(F->getAttributes()); BasicBlock *BB = BasicBlock::Create(M->getContext(), "body", Wrapper); new UnreachableInst(M->getContext(), BB); Wrapper->setName(F->getName() + "_bitcast_invalid"); @@ -253,8 +255,8 @@ bool FixFunctionBitcasts::runOnModule(Module &M) { if (shouldFixMainFunction(F.getFunctionType(), MainTy)) { LLVM_DEBUG(dbgs() << "Found `main` function with incorrect type: " << *F.getFunctionType() << "\n"); - Value *Args[] = {UndefValue::get(MainArgTys[0]), - UndefValue::get(MainArgTys[1])}; + Value *Args[] = {PoisonValue::get(MainArgTys[0]), + PoisonValue::get(MainArgTys[1])}; CallMain = CallInst::Create(MainTy, Main, Args, "call_main"); Uses.push_back(std::make_pair(CallMain, &F)); } |
