summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen
diff options
context:
space:
mode:
authorVlad Tsyrklevich <vlad@tsyrklevich.net>2019-01-15 03:38:02 +0000
committerVlad Tsyrklevich <vlad@tsyrklevich.net>2019-01-15 03:38:02 +0000
commit86e68fda3b1b3ebe712bb06558b863de2784be29 (patch)
tree38facfcc854f734b96f6ebaba219b649c3514da1 /clang/lib/CodeGen
parent2d5b317cfc9837ed5e3886c4b989538176517d62 (diff)
downloadbcm5719-llvm-86e68fda3b1b3ebe712bb06558b863de2784be29.tar.gz
bcm5719-llvm-86e68fda3b1b3ebe712bb06558b863de2784be29.zip
Revert alignment assumptions changes
Revert r351104-6, r351109, r351110, r351119, r351134, and r351153. These changes fail on the sanitizer bots. llvm-svn: 351159
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r--clang/lib/CodeGen/CGBuiltin.cpp8
-rw-r--r--clang/lib/CodeGen/CGCall.cpp18
-rw-r--r--clang/lib/CodeGen/CGExprScalar.cpp10
-rw-r--r--clang/lib/CodeGen/CGStmtOpenMP.cpp3
-rw-r--r--clang/lib/CodeGen/CodeGenFunction.cpp98
-rw-r--r--clang/lib/CodeGen/CodeGenFunction.h33
6 files changed, 25 insertions, 145 deletions
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index a718f2f19aa..4c17602314e 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -1904,17 +1904,15 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
return RValue::get(Result);
}
case Builtin::BI__builtin_assume_aligned: {
- const Expr *Ptr = E->getArg(0);
- Value *PtrValue = EmitScalarExpr(Ptr);
+ Value *PtrValue = EmitScalarExpr(E->getArg(0));
Value *OffsetValue =
(E->getNumArgs() > 2) ? EmitScalarExpr(E->getArg(2)) : nullptr;
Value *AlignmentValue = EmitScalarExpr(E->getArg(1));
ConstantInt *AlignmentCI = cast<ConstantInt>(AlignmentValue);
- unsigned Alignment = (unsigned)AlignmentCI->getZExtValue();
+ unsigned Alignment = (unsigned) AlignmentCI->getZExtValue();
- EmitAlignmentAssumption(PtrValue, Ptr, /*The expr loc is sufficient.*/ SourceLocation(),
- Alignment, OffsetValue);
+ EmitAlignmentAssumption(PtrValue, Alignment, OffsetValue);
return RValue::get(PtrValue);
}
case Builtin::BI__assume:
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 7d494bb1f1c..455a25434ff 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -2410,10 +2410,7 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,
if (!AVAttr)
if (const auto *TOTy = dyn_cast<TypedefType>(OTy))
AVAttr = TOTy->getDecl()->getAttr<AlignValueAttr>();
- if (AVAttr && !SanOpts.has(SanitizerKind::Alignment)) {
- // If alignment-assumption sanitizer is enabled, we do *not* add
- // alignment attribute here, but emit normal alignment assumption,
- // so the UBSAN check could function.
+ if (AVAttr) {
llvm::Value *AlignmentValue =
EmitScalarExpr(AVAttr->getAlignment());
llvm::ConstantInt *AlignmentCI =
@@ -4538,14 +4535,13 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
llvm::Value *Alignment = EmitScalarExpr(AA->getAlignment());
llvm::ConstantInt *AlignmentCI = cast<llvm::ConstantInt>(Alignment);
- EmitAlignmentAssumption(Ret.getScalarVal(), RetTy, Loc, AA->getLocation(),
- AlignmentCI->getZExtValue(), OffsetValue);
+ EmitAlignmentAssumption(Ret.getScalarVal(), AlignmentCI->getZExtValue(),
+ OffsetValue);
} else if (const auto *AA = TargetDecl->getAttr<AllocAlignAttr>()) {
- llvm::Value *AlignmentVal = CallArgs[AA->getParamIndex().getLLVMIndex()]
- .getRValue(*this)
- .getScalarVal();
- EmitAlignmentAssumption(Ret.getScalarVal(), RetTy, Loc, AA->getLocation(),
- AlignmentVal);
+ llvm::Value *ParamVal =
+ CallArgs[AA->getParamIndex().getLLVMIndex()].getRValue(
+ *this).getScalarVal();
+ EmitAlignmentAssumption(Ret.getScalarVal(), ParamVal);
}
}
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp
index 1c14d4c99a2..f53bb33e463 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -258,11 +258,8 @@ public:
AVAttr = TTy->getDecl()->getAttr<AlignValueAttr>();
} else {
// Assumptions for function parameters are emitted at the start of the
- // function, so there is no need to repeat that here,
- // unless the alignment-assumption sanitizer is enabled,
- // then we prefer the assumption over alignment attribute
- // on IR function param.
- if (isa<ParmVarDecl>(VD) && !CGF.SanOpts.has(SanitizerKind::Alignment))
+ // function, so there is no need to repeat that here.
+ if (isa<ParmVarDecl>(VD))
return;
AVAttr = VD->getAttr<AlignValueAttr>();
@@ -279,8 +276,7 @@ public:
Value *AlignmentValue = CGF.EmitScalarExpr(AVAttr->getAlignment());
llvm::ConstantInt *AlignmentCI = cast<llvm::ConstantInt>(AlignmentValue);
- CGF.EmitAlignmentAssumption(V, E, AVAttr->getLocation(),
- AlignmentCI->getZExtValue());
+ CGF.EmitAlignmentAssumption(V, AlignmentCI->getZExtValue());
}
/// EmitLoadOfLValue - Given an expression with complex type that represents a
diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index eb1304d8934..650f4e8b91a 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -1472,8 +1472,7 @@ static void emitAlignedClause(CodeGenFunction &CGF,
"alignment is not power of 2");
if (Alignment != 0) {
llvm::Value *PtrValue = CGF.EmitScalarExpr(E);
- CGF.EmitAlignmentAssumption(
- PtrValue, E, /*No second loc needed*/ SourceLocation(), Alignment);
+ CGF.EmitAlignmentAssumption(PtrValue, Alignment);
}
}
}
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp
index 1713e40c312..2b25fb469d7 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -2207,49 +2207,6 @@ void CodeGenFunction::unprotectFromPeepholes(PeepholeProtection protection) {
protection.Inst->eraseFromParent();
}
-void CodeGenFunction::EmitAlignmentAssumption(llvm::Value *PtrValue,
- QualType Ty, SourceLocation Loc,
- SourceLocation AssumptionLoc,
- llvm::Value *Alignment,
- llvm::Value *OffsetValue) {
- llvm::Value *TheCheck;
- llvm::Instruction *Assumption = Builder.CreateAlignmentAssumption(
- CGM.getDataLayout(), PtrValue, Alignment, OffsetValue, &TheCheck);
- if (SanOpts.has(SanitizerKind::Alignment)) {
- EmitAlignmentAssumptionCheck(PtrValue, Ty, Loc, AssumptionLoc, Alignment,
- OffsetValue, TheCheck, Assumption);
- }
-}
-
-void CodeGenFunction::EmitAlignmentAssumption(llvm::Value *PtrValue,
- QualType Ty, SourceLocation Loc,
- SourceLocation AssumptionLoc,
- unsigned Alignment,
- llvm::Value *OffsetValue) {
- llvm::Value *TheCheck;
- llvm::Instruction *Assumption = Builder.CreateAlignmentAssumption(
- CGM.getDataLayout(), PtrValue, Alignment, OffsetValue, &TheCheck);
- if (SanOpts.has(SanitizerKind::Alignment)) {
- llvm::Value *AlignmentVal = llvm::ConstantInt::get(IntPtrTy, Alignment);
- EmitAlignmentAssumptionCheck(PtrValue, Ty, Loc, AssumptionLoc, AlignmentVal,
- OffsetValue, TheCheck, Assumption);
- }
-}
-
-void CodeGenFunction::EmitAlignmentAssumption(llvm::Value *PtrValue,
- const Expr *E,
- SourceLocation AssumptionLoc,
- unsigned Alignment,
- llvm::Value *OffsetValue) {
- if (auto *CE = dyn_cast<CastExpr>(E))
- E = CE->getSubExprAsWritten();
- QualType Ty = E->getType();
- SourceLocation Loc = E->getExprLoc();
-
- EmitAlignmentAssumption(PtrValue, Ty, Loc, AssumptionLoc, Alignment,
- OffsetValue);
-}
-
llvm::Value *CodeGenFunction::EmitAnnotationCall(llvm::Value *AnnotationFn,
llvm::Value *AnnotatedVal,
StringRef AnnotationStr,
@@ -2502,61 +2459,6 @@ void CodeGenFunction::EmitMultiVersionResolver(
Builder.ClearInsertionPoint();
}
-// Loc - where the diagnostic will point, where in the source code this
-// alignment has failed.
-// SecondaryLoc - if present (will be present if sufficiently different from
-// Loc), the diagnostic will additionally point a "Note:" to this location.
-// It should be the location where the __attribute__((assume_aligned))
-// was written e.g.
-void CodeGenFunction::EmitAlignmentAssumptionCheck(
- llvm::Value *Ptr, QualType Ty, SourceLocation Loc,
- SourceLocation SecondaryLoc, llvm::Value *Alignment,
- llvm::Value *OffsetValue, llvm::Value *TheCheck,
- llvm::Instruction *Assumption) {
- assert(Assumption && isa<llvm::CallInst>(Assumption) &&
- cast<llvm::CallInst>(Assumption)->getCalledValue() ==
- llvm::Intrinsic::getDeclaration(
- Builder.GetInsertBlock()->getParent()->getParent(),
- llvm::Intrinsic::assume) &&
- "Assumption should be a call to llvm.assume().");
- assert(&(Builder.GetInsertBlock()->back()) == Assumption &&
- "Assumption should be the last instruction of the basic block, "
- "since the basic block is still being generated.");
-
- if (!SanOpts.has(SanitizerKind::Alignment))
- return;
-
- // Don't check pointers to volatile data. The behavior here is implementation-
- // defined.
- if (Ty->getPointeeType().isVolatileQualified())
- return;
-
- // We need to temorairly remove the assumption so we can insert the
- // sanitizer check before it, else the check will be dropped by optimizations.
- Assumption->removeFromParent();
-
- {
- SanitizerScope SanScope(this);
-
- if (!OffsetValue)
- OffsetValue = Builder.getInt1(0); // no offset.
-
- llvm::Constant *StaticData[] = {EmitCheckSourceLocation(Loc),
- EmitCheckSourceLocation(SecondaryLoc),
- EmitCheckTypeDescriptor(Ty)};
- llvm::Value *DynamicData[] = {EmitCheckValue(Ptr),
- EmitCheckValue(Alignment),
- EmitCheckValue(OffsetValue)};
- EmitCheck({std::make_pair(TheCheck, SanitizerKind::Alignment)},
- SanitizerHandler::AlignmentAssumption, StaticData, DynamicData);
- }
-
- // We are now in the (new, empty) "cont" basic block.
- // Reintroduce the assumption.
- Builder.Insert(Assumption);
- // FIXME: Assumption still has it's original basic block as it's Parent.
-}
-
llvm::DebugLoc CodeGenFunction::SourceLocToDebugLoc(SourceLocation Location) {
if (CGDebugInfo *DI = getDebugInfo())
return DI->SourceLocToDebugLoc(Location);
diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h
index 89cb850ab1b..c8b300236f4 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -131,7 +131,6 @@ enum TypeEvaluationKind {
SANITIZER_CHECK(ShiftOutOfBounds, shift_out_of_bounds, 0) \
SANITIZER_CHECK(SubOverflow, sub_overflow, 0) \
SANITIZER_CHECK(TypeMismatch, type_mismatch, 1) \
- SANITIZER_CHECK(AlignmentAssumption, alignment_assumption, 0) \
SANITIZER_CHECK(VLABoundNotPositive, vla_bound_not_positive, 0)
enum SanitizerHandler {
@@ -2634,6 +2633,12 @@ public:
ComplexPairTy EmitComplexPrePostIncDec(const UnaryOperator *E, LValue LV,
bool isInc, bool isPre);
+ void EmitAlignmentAssumption(llvm::Value *PtrValue, unsigned Alignment,
+ llvm::Value *OffsetValue = nullptr) {
+ Builder.CreateAlignmentAssumption(CGM.getDataLayout(), PtrValue, Alignment,
+ OffsetValue);
+ }
+
/// Converts Location to a DebugLoc, if debug information is enabled.
llvm::DebugLoc SourceLocToDebugLoc(SourceLocation Location);
@@ -2797,27 +2802,11 @@ public:
PeepholeProtection protectFromPeepholes(RValue rvalue);
void unprotectFromPeepholes(PeepholeProtection protection);
- void EmitAlignmentAssumptionCheck(llvm::Value *Ptr, QualType Ty,
- SourceLocation Loc,
- SourceLocation AssumptionLoc,
- llvm::Value *Alignment,
- llvm::Value *OffsetValue,
- llvm::Value *TheCheck,
- llvm::Instruction *Assumption);
-
- void EmitAlignmentAssumption(llvm::Value *PtrValue, QualType Ty,
- SourceLocation Loc, SourceLocation AssumptionLoc,
- llvm::Value *Alignment,
- llvm::Value *OffsetValue = nullptr);
-
- void EmitAlignmentAssumption(llvm::Value *PtrValue, QualType Ty,
- SourceLocation Loc, SourceLocation AssumptionLoc,
- unsigned Alignment,
- llvm::Value *OffsetValue = nullptr);
-
- void EmitAlignmentAssumption(llvm::Value *PtrValue, const Expr *E,
- SourceLocation AssumptionLoc, unsigned Alignment,
- llvm::Value *OffsetValue = nullptr);
+ void EmitAlignmentAssumption(llvm::Value *PtrValue, llvm::Value *Alignment,
+ llvm::Value *OffsetValue = nullptr) {
+ Builder.CreateAlignmentAssumption(CGM.getDataLayout(), PtrValue, Alignment,
+ OffsetValue);
+ }
//===--------------------------------------------------------------------===//
// Statement Emission
OpenPOWER on IntegriCloud