summaryrefslogtreecommitdiff
path: root/llvm
diff options
context:
space:
mode:
authorRoman Lebedev <lebedev.ri@gmail.com>2019-01-15 09:44:13 +0000
committerRoman Lebedev <lebedev.ri@gmail.com>2019-01-15 09:44:13 +0000
commit79ce8bef6245e0c3fed3d4549fb2fdb8bd966677 (patch)
tree6a333bb8483fb6ce589dc1565ad3c7f98ebdf40b /llvm
parent17d4126da0862ec1be94da8bd3d432779b1044a0 (diff)
[llvm][IRBuilder] Introspection for CreateAlignmentAssumption*() functions
Summary: Clang calls these functions to produce IR for assume-aligned attributes. I would like to teach UBSAN to verify these assumptions. For that, i need to access the final pointer on which the check is performed, and the actual `icmp` that does the check. The alternative to this would be to fully re-implement this in clang. This is a second commit, the original one was r351104, which was mass-reverted in r351159 because 2 compiler-rt tests were failing. Reviewers: spatel, dneilson, craig.topper, dblaikie, hfinkel Reviewed By: hfinkel Subscribers: hfinkel, llvm-commits Differential Revision: https://reviews.llvm.org/D54588
Diffstat (limited to 'llvm')
-rw-r--r--llvm/include/llvm/IR/IRBuilder.h26
1 files changed, 19 insertions, 7 deletions
diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h
index 32c06419c2a..fac2ff46c45 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -2234,11 +2234,12 @@ public:
private:
/// Helper function that creates an assume intrinsic call that
/// represents an alignment assumption on the provided Ptr, Mask, Type
- /// and Offset.
+ /// and Offset. It may be sometimes useful to do some other logic
+ /// based on this alignment check, thus it can be stored into 'TheCheck'.
CallInst *CreateAlignmentAssumptionHelper(const DataLayout &DL,
Value *PtrValue, Value *Mask,
- Type *IntPtrTy,
- Value *OffsetValue) {
+ Type *IntPtrTy, Value *OffsetValue,
+ Value **TheCheck) {
Value *PtrIntValue = CreatePtrToInt(PtrValue, IntPtrTy, "ptrint");
if (OffsetValue) {
@@ -2257,6 +2258,9 @@ private:
Value *Zero = ConstantInt::get(IntPtrTy, 0);
Value *MaskedPtr = CreateAnd(PtrIntValue, Mask, "maskedptr");
Value *InvCond = CreateICmpEQ(MaskedPtr, Zero, "maskcond");
+ if (TheCheck)
+ *TheCheck = InvCond;
+
return CreateAssumption(InvCond);
}
@@ -2267,9 +2271,13 @@ public:
/// An optional offset can be provided, and if it is provided, the offset
/// must be subtracted from the provided pointer to get the pointer with the
/// specified alignment.
+ ///
+ /// It may be sometimes useful to do some other logic
+ /// based on this alignment check, thus it can be stored into 'TheCheck'.
CallInst *CreateAlignmentAssumption(const DataLayout &DL, Value *PtrValue,
unsigned Alignment,
- Value *OffsetValue = nullptr) {
+ Value *OffsetValue = nullptr,
+ Value **TheCheck = nullptr) {
assert(isa<PointerType>(PtrValue->getType()) &&
"trying to create an alignment assumption on a non-pointer?");
auto *PtrTy = cast<PointerType>(PtrValue->getType());
@@ -2277,7 +2285,7 @@ public:
Value *Mask = ConstantInt::get(IntPtrTy, Alignment > 0 ? Alignment - 1 : 0);
return CreateAlignmentAssumptionHelper(DL, PtrValue, Mask, IntPtrTy,
- OffsetValue);
+ OffsetValue, TheCheck);
}
/// Create an assume intrinsic call that represents an alignment
@@ -2287,11 +2295,15 @@ public:
/// must be subtracted from the provided pointer to get the pointer with the
/// specified alignment.
///
+ /// It may be sometimes useful to do some other logic
+ /// based on this alignment check, thus it can be stored into 'TheCheck'.
+ ///
/// This overload handles the condition where the Alignment is dependent
/// on an existing value rather than a static value.
CallInst *CreateAlignmentAssumption(const DataLayout &DL, Value *PtrValue,
Value *Alignment,
- Value *OffsetValue = nullptr) {
+ Value *OffsetValue = nullptr,
+ Value **TheCheck = nullptr) {
assert(isa<PointerType>(PtrValue->getType()) &&
"trying to create an alignment assumption on a non-pointer?");
auto *PtrTy = cast<PointerType>(PtrValue->getType());
@@ -2309,7 +2321,7 @@ public:
ConstantInt::get(IntPtrTy, 0), "mask");
return CreateAlignmentAssumptionHelper(DL, PtrValue, Mask, IntPtrTy,
- OffsetValue);
+ OffsetValue, TheCheck);
}
};