[llvm] 81cfb90 - [IR] Add a few asserts to provide a better failure signature if you try to create a load/store/alloca with no alignment or insertion position
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 14 18:48:29 PDT 2020
Author: Craig Topper
Date: 2020-07-14T18:47:44-07:00
New Revision: 81cfb90f858e510ec5c570a264fe57203e96a193
URL: https://github.com/llvm/llvm-project/commit/81cfb90f858e510ec5c570a264fe57203e96a193
DIFF: https://github.com/llvm/llvm-project/commit/81cfb90f858e510ec5c570a264fe57203e96a193.diff
LOG: [IR] Add a few asserts to provide a better failure signature if you try to create a load/store/alloca with no alignment or insertion position
If no alignment is specified we try to find the datalayout by using the insert position to get the module so we can get the datalayout. But if those are null, then we deference a null pointer.
This patch adds asserts to make the failure a little more obvious than just seg faulting.
Differential Revision: https://reviews.llvm.org/D83829
Added:
Modified:
llvm/lib/IR/Instructions.cpp
Removed:
################################################################################
diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp
index f650ad9130ac..2f17a0d73af4 100644
--- a/llvm/lib/IR/Instructions.cpp
+++ b/llvm/lib/IR/Instructions.cpp
@@ -1262,11 +1262,15 @@ static Value *getAISize(LLVMContext &Context, Value *Amt) {
}
static Align computeAllocaDefaultAlign(Type *Ty, BasicBlock *BB) {
+ assert(BB && "Insertion BB cannot be null when alignment not provided!");
+ assert(BB->getParent() &&
+ "BB must be in a Function when alignment not provided!");
const DataLayout &DL = BB->getModule()->getDataLayout();
return DL.getPrefTypeAlign(Ty);
}
static Align computeAllocaDefaultAlign(Type *Ty, Instruction *I) {
+ assert(I && "Insertion position cannot be null when alignment not provided!");
return computeAllocaDefaultAlign(Ty, I->getParent());
}
@@ -1342,11 +1346,15 @@ void LoadInst::AssertOK() {
}
static Align computeLoadStoreDefaultAlign(Type *Ty, BasicBlock *BB) {
+ assert(BB && "Insertion BB cannot be null when alignment not provided!");
+ assert(BB->getParent() &&
+ "BB must be in a Function when alignment not provided!");
const DataLayout &DL = BB->getModule()->getDataLayout();
return DL.getABITypeAlign(Ty);
}
static Align computeLoadStoreDefaultAlign(Type *Ty, Instruction *I) {
+ assert(I && "Insertion position cannot be null when alignment not provided!");
return computeLoadStoreDefaultAlign(Ty, I->getParent());
}
More information about the llvm-commits
mailing list