summaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenFunction.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/CodeGen/CodeGenFunction.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenFunction.cpp36
1 files changed, 5 insertions, 31 deletions
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp
index 4a7c84562deef..8ce488f35dd32 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -2154,39 +2154,13 @@ void CodeGenFunction::emitAlignmentAssumption(llvm::Value *PtrValue,
SourceLocation AssumptionLoc,
llvm::Value *Alignment,
llvm::Value *OffsetValue) {
- if (Alignment->getType() != IntPtrTy)
- Alignment =
- Builder.CreateIntCast(Alignment, IntPtrTy, false, "casted.align");
- if (OffsetValue && OffsetValue->getType() != IntPtrTy)
- OffsetValue =
- Builder.CreateIntCast(OffsetValue, IntPtrTy, true, "casted.offset");
- llvm::Value *TheCheck = nullptr;
+ llvm::Value *TheCheck;
+ llvm::Instruction *Assumption = Builder.CreateAlignmentAssumption(
+ CGM.getDataLayout(), PtrValue, Alignment, OffsetValue, &TheCheck);
if (SanOpts.has(SanitizerKind::Alignment)) {
- llvm::Value *PtrIntValue =
- Builder.CreatePtrToInt(PtrValue, IntPtrTy, "ptrint");
-
- if (OffsetValue) {
- bool IsOffsetZero = false;
- if (const auto *CI = dyn_cast<llvm::ConstantInt>(OffsetValue))
- IsOffsetZero = CI->isZero();
-
- if (!IsOffsetZero)
- PtrIntValue = Builder.CreateSub(PtrIntValue, OffsetValue, "offsetptr");
- }
-
- llvm::Value *Zero = llvm::ConstantInt::get(IntPtrTy, 0);
- llvm::Value *Mask =
- Builder.CreateSub(Alignment, llvm::ConstantInt::get(IntPtrTy, 1));
- llvm::Value *MaskedPtr = Builder.CreateAnd(PtrIntValue, Mask, "maskedptr");
- TheCheck = Builder.CreateICmpEQ(MaskedPtr, Zero, "maskcond");
+ emitAlignmentAssumptionCheck(PtrValue, Ty, Loc, AssumptionLoc, Alignment,
+ OffsetValue, TheCheck, Assumption);
}
- llvm::Instruction *Assumption = Builder.CreateAlignmentAssumption(
- CGM.getDataLayout(), PtrValue, Alignment, OffsetValue);
-
- if (!SanOpts.has(SanitizerKind::Alignment))
- return;
- emitAlignmentAssumptionCheck(PtrValue, Ty, Loc, AssumptionLoc, Alignment,
- OffsetValue, TheCheck, Assumption);
}
void CodeGenFunction::emitAlignmentAssumption(llvm::Value *PtrValue,