summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorVedant Kumar <vsk@apple.com>2017-10-03 01:27:24 +0000
committerVedant Kumar <vsk@apple.com>2017-10-03 01:27:24 +0000
commit8a7153312bc628fe1516839d9b6c3a41d34a6e55 (patch)
tree06df90da42c65ead2d8d32c94c0977edf609c591 /clang/lib
parent675cf03f6eca64a8586370f60b98a942a7bb325d (diff)
downloadbcm5719-llvm-8a7153312bc628fe1516839d9b6c3a41d34a6e55.tar.gz
bcm5719-llvm-8a7153312bc628fe1516839d9b6c3a41d34a6e55.zip
[ubsan] Save a ptrtoint when emitting alignment checks
The alignment check emits a ptrtoint instruction which can be reused in the call to the diagnostic handler. llvm-svn: 314749
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/CodeGen/CGExpr.cpp15
1 files changed, 10 insertions, 5 deletions
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index ba970b9bde1..24de6da2821 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -656,6 +656,7 @@ void CodeGenFunction::EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc,
}
uint64_t AlignVal = 0;
+ llvm::Value *PtrAsInt = nullptr;
if (SanOpts.has(SanitizerKind::Alignment) &&
!SkippedChecks.has(SanitizerKind::Alignment)) {
@@ -666,11 +667,11 @@ void CodeGenFunction::EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc,
// The glvalue must be suitably aligned.
if (AlignVal > 1 &&
(!PtrToAlloca || PtrToAlloca->getAlignment() < AlignVal)) {
- llvm::Value *Align =
- Builder.CreateAnd(Builder.CreatePtrToInt(Ptr, IntPtrTy),
- llvm::ConstantInt::get(IntPtrTy, AlignVal - 1));
+ PtrAsInt = Builder.CreatePtrToInt(Ptr, IntPtrTy);
+ llvm::Value *Align = Builder.CreateAnd(
+ PtrAsInt, llvm::ConstantInt::get(IntPtrTy, AlignVal - 1));
llvm::Value *Aligned =
- Builder.CreateICmpEQ(Align, llvm::ConstantInt::get(IntPtrTy, 0));
+ Builder.CreateICmpEQ(Align, llvm::ConstantInt::get(IntPtrTy, 0));
Checks.push_back(std::make_pair(Aligned, SanitizerKind::Alignment));
}
}
@@ -683,7 +684,8 @@ void CodeGenFunction::EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc,
EmitCheckSourceLocation(Loc), EmitCheckTypeDescriptor(Ty),
llvm::ConstantInt::get(Int8Ty, AlignVal ? llvm::Log2_64(AlignVal) : 1),
llvm::ConstantInt::get(Int8Ty, TCK)};
- EmitCheck(Checks, SanitizerHandler::TypeMismatch, StaticData, Ptr);
+ EmitCheck(Checks, SanitizerHandler::TypeMismatch, StaticData,
+ PtrAsInt ? PtrAsInt : Ptr);
}
// If possible, check that the vptr indicates that there is a subobject of
@@ -2599,6 +2601,9 @@ llvm::Constant *CodeGenFunction::EmitCheckTypeDescriptor(QualType T) {
llvm::Value *CodeGenFunction::EmitCheckValue(llvm::Value *V) {
llvm::Type *TargetTy = IntPtrTy;
+ if (V->getType() == TargetTy)
+ return V;
+
// Floating-point types which fit into intptr_t are bitcast to integers
// and then passed directly (after zero-extension, if necessary).
if (V->getType()->isFloatingPointTy()) {
OpenPOWER on IntegriCloud