aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/Function.cpp
diff options
context:
space:
mode:
authorJeroen Dobbelaere <jeroen.dobbelaere@synopsys.com>2021-06-14 14:52:29 +0200
committerJeroen Dobbelaere <jeroen.dobbelaere@synopsys.com>2021-06-14 14:52:29 +0200
commitbb8ce25e88218be60d2a4ea9c9b0b721809eff27 (patch)
treee72f60d66fe0fce564a53648aae5dae7b9340079 /llvm/lib/IR/Function.cpp
parent9f967eed89e66e39909c59ec0246dc2877d75f51 (diff)
downloadllvm-bb8ce25e88218be60d2a4ea9c9b0b721809eff27.zip
llvm-bb8ce25e88218be60d2a4ea9c9b0b721809eff27.tar.gz
llvm-bb8ce25e88218be60d2a4ea9c9b0b721809eff27.tar.bz2
Intrinsic::getName: require a Module argument
Ensure that we provide a `Module` when checking if a rename of an intrinsic is necessary. This fixes the issue that was detected by https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=32288 (as mentioned by @fhahn), after committing D91250. Note that the `LLVMIntrinsicCopyOverloadedName` is being deprecated in favor of `LLVMIntrinsicCopyOverloadedName2`. Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D99173
Diffstat (limited to 'llvm/lib/IR/Function.cpp')
-rw-r--r--llvm/lib/IR/Function.cpp42
1 files changed, 29 insertions, 13 deletions
diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp
index 25c59d0..8f1148d 100644
--- a/llvm/lib/IR/Function.cpp
+++ b/llvm/lib/IR/Function.cpp
@@ -831,37 +831,53 @@ static std::string getMangledTypeStr(Type *Ty, bool &HasUnnamedType) {
return Result;
}
+StringRef Intrinsic::getBaseName(ID id) {
+ assert(id < num_intrinsics && "Invalid intrinsic ID!");
+ return IntrinsicNameTable[id];
+}
+
StringRef Intrinsic::getName(ID id) {
assert(id < num_intrinsics && "Invalid intrinsic ID!");
assert(!Intrinsic::isOverloaded(id) &&
"This version of getName does not support overloading");
- return IntrinsicNameTable[id];
+ return getBaseName(id);
}
-std::string Intrinsic::getName(ID Id, ArrayRef<Type *> Tys, Module *M,
- FunctionType *FT) {
- assert(Id < num_intrinsics && "Invalid intrinsic ID!");
+static std::string getIntrinsicNameImpl(Intrinsic::ID Id, ArrayRef<Type *> Tys,
+ Module *M, FunctionType *FT,
+ bool EarlyModuleCheck) {
+
+ assert(Id < Intrinsic::num_intrinsics && "Invalid intrinsic ID!");
assert((Tys.empty() || Intrinsic::isOverloaded(Id)) &&
"This version of getName is for overloaded intrinsics only");
+ (void)EarlyModuleCheck;
+ assert((!EarlyModuleCheck || M ||
+ !any_of(Tys, [](Type *T) { return isa<PointerType>(T); })) &&
+ "Intrinsic overloading on pointer types need to provide a Module");
bool HasUnnamedType = false;
- std::string Result(IntrinsicNameTable[Id]);
- for (Type *Ty : Tys) {
+ std::string Result(Intrinsic::getBaseName(Id));
+ for (Type *Ty : Tys)
Result += "." + getMangledTypeStr(Ty, HasUnnamedType);
- }
- assert((M || !HasUnnamedType) && "unnamed types need a module");
- if (M && HasUnnamedType) {
+ if (HasUnnamedType) {
+ assert(M && "unnamed types need a module");
if (!FT)
- FT = getType(M->getContext(), Id, Tys);
+ FT = Intrinsic::getType(M->getContext(), Id, Tys);
else
- assert((FT == getType(M->getContext(), Id, Tys)) &&
+ assert((FT == Intrinsic::getType(M->getContext(), Id, Tys)) &&
"Provided FunctionType must match arguments");
return M->getUniqueIntrinsicName(Result, Id, FT);
}
return Result;
}
-std::string Intrinsic::getName(ID Id, ArrayRef<Type *> Tys) {
- return getName(Id, Tys, nullptr, nullptr);
+std::string Intrinsic::getName(ID Id, ArrayRef<Type *> Tys, Module *M,
+ FunctionType *FT) {
+ assert(M && "We need to have a Module");
+ return getIntrinsicNameImpl(Id, Tys, M, FT, true);
+}
+
+std::string Intrinsic::getNameNoUnnamedTypes(ID Id, ArrayRef<Type *> Tys) {
+ return getIntrinsicNameImpl(Id, Tys, nullptr, nullptr, false);
}
/// IIT_Info - These are enumerators that describe the entries returned by the