[PATCH] D110584: [Analysis] Be defensive when matching size_t in lib call signatures
Bjorn Pettersson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 28 06:30:41 PDT 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG460efc1fb835: [Analysis] Be defensive when matching size_t in lib call signatures (authored by bjope).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D110584/new/
https://reviews.llvm.org/D110584
Files:
llvm/include/llvm/Analysis/TargetLibraryInfo.h
llvm/lib/Analysis/TargetLibraryInfo.cpp
Index: llvm/lib/Analysis/TargetLibraryInfo.cpp
===================================================================
--- llvm/lib/Analysis/TargetLibraryInfo.cpp
+++ llvm/lib/Analysis/TargetLibraryInfo.cpp
@@ -725,20 +725,13 @@
bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy,
LibFunc F,
- const DataLayout *DL) const {
+ const DataLayout &DL) const {
LLVMContext &Ctx = FTy.getContext();
// FIXME: There is really no guarantee that sizeof(size_t) is equal to
// sizeof(int*) for every target. So the assumption used here to derive the
// SizeTTy based on DataLayout and getIntPtrType isn't always valid.
- Type *SizeTTy = DL ? DL->getIntPtrType(Ctx, /*AddressSpace=*/0) : nullptr;
+ Type *SizeTTy = DL.getIntPtrType(Ctx, /*AddressSpace=*/0);
auto IsSizeTTy = [SizeTTy](Type *Ty) {
- // FIXME: For uknown historical reasons(?) we use a relaxed condition saying
- // that any integer type may size_t, for example if we got no
- // DataLayout. This seems like a potentially error prone relaxation (or why
- // should we only be more strict and checking the exact type when we have a
- // DataLayout?).
- if (!SizeTTy)
- return Ty->isIntegerTy();
return Ty == SizeTTy;
};
unsigned NumParams = FTy.getNumParams();
@@ -1625,10 +1618,11 @@
// avoid string normalization and comparison.
if (FDecl.isIntrinsic()) return false;
- const DataLayout *DL =
- FDecl.getParent() ? &FDecl.getParent()->getDataLayout() : nullptr;
+ const Module *M = FDecl.getParent();
+ assert(M && "Expecting FDecl to be connected to a Module.");
+
return getLibFunc(FDecl.getName(), F) &&
- isValidProtoForLibFunc(*FDecl.getFunctionType(), F, DL);
+ isValidProtoForLibFunc(*FDecl.getFunctionType(), F, M->getDataLayout());
}
void TargetLibraryInfoImpl::disableAllFunctions() {
Index: llvm/include/llvm/Analysis/TargetLibraryInfo.h
===================================================================
--- llvm/include/llvm/Analysis/TargetLibraryInfo.h
+++ llvm/include/llvm/Analysis/TargetLibraryInfo.h
@@ -76,7 +76,7 @@
/// Return true if the function type FTy is valid for the library function
/// F, regardless of whether the function is available.
bool isValidProtoForLibFunc(const FunctionType &FTy, LibFunc F,
- const DataLayout *DL) const;
+ const DataLayout &DL) const;
public:
/// List of known vector-functions libraries.
@@ -115,6 +115,8 @@
///
/// If it is one of the known library functions, return true and set F to the
/// corresponding value.
+ ///
+ /// FDecl is assumed to have a parent Module when using this function.
bool getLibFunc(const Function &FDecl, LibFunc &F) const;
/// Forces a function to be marked as unavailable.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110584.375552.patch
Type: text/x-patch
Size: 2975 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210928/03cfa345/attachment.bin>
More information about the llvm-commits
mailing list