diff options
Diffstat (limited to 'llvm/lib/IR/Intrinsics.cpp')
-rw-r--r-- | llvm/lib/IR/Intrinsics.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/llvm/lib/IR/Intrinsics.cpp b/llvm/lib/IR/Intrinsics.cpp index 6797a10..526800e 100644 --- a/llvm/lib/IR/Intrinsics.cpp +++ b/llvm/lib/IR/Intrinsics.cpp @@ -725,6 +725,19 @@ Function *Intrinsic::getOrInsertDeclaration(Module *M, ID id, // There can never be multiple globals with the same name of different types, // because intrinsics must be a specific type. auto *FT = getType(M->getContext(), id, Tys); + Function *F = cast<Function>( + M->getOrInsertFunction( + Tys.empty() ? getName(id) : getName(id, Tys, M, FT), FT) + .getCallee()); + if (F->getFunctionType() == FT) + return F; + + // It's possible that a declaration for this intrinsic already exists with an + // incorrect signature, if the signature has changed, but this particular + // declaration has not been auto-upgraded yet. In that case, rename the + // invalid declaration and insert a new one with the correct signature. The + // invalid declaration will get upgraded later. + F->setName(F->getName() + ".invalid"); return cast<Function>( M->getOrInsertFunction( Tys.empty() ? getName(id) : getName(id, Tys, M, FT), FT) |