|
@@ -406,7 +406,7 @@ public:
|
|
case LangOptions::SOB_Defined:
|
|
case LangOptions::SOB_Defined:
|
|
return Builder.CreateMul(Ops.LHS, Ops.RHS, "mul");
|
|
return Builder.CreateMul(Ops.LHS, Ops.RHS, "mul");
|
|
case LangOptions::SOB_Undefined:
|
|
case LangOptions::SOB_Undefined:
|
|
- if (!CGF.getLangOpts().SanitizeSignedIntegerOverflow)
|
|
|
|
|
|
+ if (!CGF.SanOpts->SignedIntegerOverflow)
|
|
return Builder.CreateNSWMul(Ops.LHS, Ops.RHS, "mul");
|
|
return Builder.CreateNSWMul(Ops.LHS, Ops.RHS, "mul");
|
|
// Fall through.
|
|
// Fall through.
|
|
case LangOptions::SOB_Trapping:
|
|
case LangOptions::SOB_Trapping:
|
|
@@ -414,8 +414,7 @@ public:
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if (Ops.Ty->isUnsignedIntegerType() &&
|
|
|
|
- CGF.getLangOpts().SanitizeUnsignedIntegerOverflow)
|
|
|
|
|
|
+ if (Ops.Ty->isUnsignedIntegerType() && CGF.SanOpts->UnsignedIntegerOverflow)
|
|
return EmitOverflowCheckedBinOp(Ops);
|
|
return EmitOverflowCheckedBinOp(Ops);
|
|
|
|
|
|
if (Ops.LHS->getType()->isFPOrFPVectorTy())
|
|
if (Ops.LHS->getType()->isFPOrFPVectorTy())
|
|
@@ -730,9 +729,10 @@ Value *ScalarExprEmitter::EmitScalarConversion(Value *Src, QualType SrcType,
|
|
|
|
|
|
// An overflowing conversion has undefined behavior if either the source type
|
|
// An overflowing conversion has undefined behavior if either the source type
|
|
// or the destination type is a floating-point type.
|
|
// or the destination type is a floating-point type.
|
|
- if (CGF.getLangOpts().SanitizeFloatCastOverflow &&
|
|
|
|
|
|
+ if (CGF.SanOpts->FloatCastOverflow &&
|
|
(OrigSrcType->isFloatingType() || DstType->isFloatingType()))
|
|
(OrigSrcType->isFloatingType() || DstType->isFloatingType()))
|
|
- EmitFloatConversionCheck(OrigSrc, OrigSrcType, Src, SrcType, DstType, DstTy);
|
|
|
|
|
|
+ EmitFloatConversionCheck(OrigSrc, OrigSrcType, Src, SrcType, DstType,
|
|
|
|
+ DstTy);
|
|
|
|
|
|
// Cast to half via float
|
|
// Cast to half via float
|
|
if (DstType->isHalfType())
|
|
if (DstType->isHalfType())
|
|
@@ -1406,7 +1406,7 @@ EmitAddConsiderOverflowBehavior(const UnaryOperator *E,
|
|
case LangOptions::SOB_Defined:
|
|
case LangOptions::SOB_Defined:
|
|
return Builder.CreateAdd(InVal, NextVal, IsInc ? "inc" : "dec");
|
|
return Builder.CreateAdd(InVal, NextVal, IsInc ? "inc" : "dec");
|
|
case LangOptions::SOB_Undefined:
|
|
case LangOptions::SOB_Undefined:
|
|
- if (!CGF.getLangOpts().SanitizeSignedIntegerOverflow)
|
|
|
|
|
|
+ if (!CGF.SanOpts->SignedIntegerOverflow)
|
|
return Builder.CreateNSWAdd(InVal, NextVal, IsInc ? "inc" : "dec");
|
|
return Builder.CreateNSWAdd(InVal, NextVal, IsInc ? "inc" : "dec");
|
|
// Fall through.
|
|
// Fall through.
|
|
case LangOptions::SOB_Trapping:
|
|
case LangOptions::SOB_Trapping:
|
|
@@ -1466,9 +1466,8 @@ ScalarExprEmitter::EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV,
|
|
type->isSignedIntegerOrEnumerationType()) {
|
|
type->isSignedIntegerOrEnumerationType()) {
|
|
value = EmitAddConsiderOverflowBehavior(E, value, amt, isInc);
|
|
value = EmitAddConsiderOverflowBehavior(E, value, amt, isInc);
|
|
} else if (value->getType()->getPrimitiveSizeInBits() >=
|
|
} else if (value->getType()->getPrimitiveSizeInBits() >=
|
|
- CGF.IntTy->getBitWidth() &&
|
|
|
|
- type->isUnsignedIntegerType() &&
|
|
|
|
- CGF.getLangOpts().SanitizeUnsignedIntegerOverflow) {
|
|
|
|
|
|
+ CGF.IntTy->getBitWidth() && type->isUnsignedIntegerType() &&
|
|
|
|
+ CGF.SanOpts->UnsignedIntegerOverflow) {
|
|
BinOpInfo BinOp;
|
|
BinOpInfo BinOp;
|
|
BinOp.LHS = value;
|
|
BinOp.LHS = value;
|
|
BinOp.RHS = llvm::ConstantInt::get(value->getType(), 1, false);
|
|
BinOp.RHS = llvm::ConstantInt::get(value->getType(), 1, false);
|
|
@@ -1927,10 +1926,10 @@ void ScalarExprEmitter::EmitUndefinedBehaviorIntegerDivAndRemCheck(
|
|
const BinOpInfo &Ops, llvm::Value *Zero, bool isDiv) {
|
|
const BinOpInfo &Ops, llvm::Value *Zero, bool isDiv) {
|
|
llvm::Value *Cond = 0;
|
|
llvm::Value *Cond = 0;
|
|
|
|
|
|
- if (CGF.getLangOpts().SanitizeIntegerDivideByZero)
|
|
|
|
|
|
+ if (CGF.SanOpts->IntegerDivideByZero)
|
|
Cond = Builder.CreateICmpNE(Ops.RHS, Zero);
|
|
Cond = Builder.CreateICmpNE(Ops.RHS, Zero);
|
|
|
|
|
|
- if (CGF.getLangOpts().SanitizeSignedIntegerOverflow &&
|
|
|
|
|
|
+ if (CGF.SanOpts->SignedIntegerOverflow &&
|
|
Ops.Ty->hasSignedIntegerRepresentation()) {
|
|
Ops.Ty->hasSignedIntegerRepresentation()) {
|
|
llvm::IntegerType *Ty = cast<llvm::IntegerType>(Zero->getType());
|
|
llvm::IntegerType *Ty = cast<llvm::IntegerType>(Zero->getType());
|
|
|
|
|
|
@@ -1949,12 +1948,12 @@ void ScalarExprEmitter::EmitUndefinedBehaviorIntegerDivAndRemCheck(
|
|
}
|
|
}
|
|
|
|
|
|
Value *ScalarExprEmitter::EmitDiv(const BinOpInfo &Ops) {
|
|
Value *ScalarExprEmitter::EmitDiv(const BinOpInfo &Ops) {
|
|
- if ((CGF.getLangOpts().SanitizeIntegerDivideByZero ||
|
|
|
|
- CGF.getLangOpts().SanitizeSignedIntegerOverflow) &&
|
|
|
|
|
|
+ if ((CGF.SanOpts->IntegerDivideByZero ||
|
|
|
|
+ CGF.SanOpts->SignedIntegerOverflow) &&
|
|
Ops.Ty->isIntegerType()) {
|
|
Ops.Ty->isIntegerType()) {
|
|
llvm::Value *Zero = llvm::Constant::getNullValue(ConvertType(Ops.Ty));
|
|
llvm::Value *Zero = llvm::Constant::getNullValue(ConvertType(Ops.Ty));
|
|
EmitUndefinedBehaviorIntegerDivAndRemCheck(Ops, Zero, true);
|
|
EmitUndefinedBehaviorIntegerDivAndRemCheck(Ops, Zero, true);
|
|
- } else if (CGF.getLangOpts().SanitizeFloatDivideByZero &&
|
|
|
|
|
|
+ } else if (CGF.SanOpts->FloatDivideByZero &&
|
|
Ops.Ty->isRealFloatingType()) {
|
|
Ops.Ty->isRealFloatingType()) {
|
|
llvm::Value *Zero = llvm::Constant::getNullValue(ConvertType(Ops.Ty));
|
|
llvm::Value *Zero = llvm::Constant::getNullValue(ConvertType(Ops.Ty));
|
|
EmitBinOpCheck(Builder.CreateFCmpUNE(Ops.RHS, Zero), Ops);
|
|
EmitBinOpCheck(Builder.CreateFCmpUNE(Ops.RHS, Zero), Ops);
|
|
@@ -1980,7 +1979,7 @@ Value *ScalarExprEmitter::EmitDiv(const BinOpInfo &Ops) {
|
|
|
|
|
|
Value *ScalarExprEmitter::EmitRem(const BinOpInfo &Ops) {
|
|
Value *ScalarExprEmitter::EmitRem(const BinOpInfo &Ops) {
|
|
// Rem in C can't be a floating point type: C99 6.5.5p2.
|
|
// Rem in C can't be a floating point type: C99 6.5.5p2.
|
|
- if (CGF.getLangOpts().SanitizeIntegerDivideByZero) {
|
|
|
|
|
|
+ if (CGF.SanOpts->IntegerDivideByZero) {
|
|
llvm::Value *Zero = llvm::Constant::getNullValue(ConvertType(Ops.Ty));
|
|
llvm::Value *Zero = llvm::Constant::getNullValue(ConvertType(Ops.Ty));
|
|
|
|
|
|
if (Ops.Ty->isIntegerType())
|
|
if (Ops.Ty->isIntegerType())
|
|
@@ -2038,7 +2037,7 @@ Value *ScalarExprEmitter::EmitOverflowCheckedBinOp(const BinOpInfo &Ops) {
|
|
if (handlerName->empty()) {
|
|
if (handlerName->empty()) {
|
|
// If the signed-integer-overflow sanitizer is enabled, emit a call to its
|
|
// If the signed-integer-overflow sanitizer is enabled, emit a call to its
|
|
// runtime. Otherwise, this is a -ftrapv check, so just emit a trap.
|
|
// runtime. Otherwise, this is a -ftrapv check, so just emit a trap.
|
|
- if (!isSigned || CGF.getLangOpts().SanitizeSignedIntegerOverflow)
|
|
|
|
|
|
+ if (!isSigned || CGF.SanOpts->SignedIntegerOverflow)
|
|
EmitBinOpCheck(Builder.CreateNot(overflow), Ops);
|
|
EmitBinOpCheck(Builder.CreateNot(overflow), Ops);
|
|
else
|
|
else
|
|
CGF.EmitTrapvCheck(Builder.CreateNot(overflow));
|
|
CGF.EmitTrapvCheck(Builder.CreateNot(overflow));
|
|
@@ -2256,7 +2255,7 @@ Value *ScalarExprEmitter::EmitAdd(const BinOpInfo &op) {
|
|
case LangOptions::SOB_Defined:
|
|
case LangOptions::SOB_Defined:
|
|
return Builder.CreateAdd(op.LHS, op.RHS, "add");
|
|
return Builder.CreateAdd(op.LHS, op.RHS, "add");
|
|
case LangOptions::SOB_Undefined:
|
|
case LangOptions::SOB_Undefined:
|
|
- if (!CGF.getLangOpts().SanitizeSignedIntegerOverflow)
|
|
|
|
|
|
+ if (!CGF.SanOpts->SignedIntegerOverflow)
|
|
return Builder.CreateNSWAdd(op.LHS, op.RHS, "add");
|
|
return Builder.CreateNSWAdd(op.LHS, op.RHS, "add");
|
|
// Fall through.
|
|
// Fall through.
|
|
case LangOptions::SOB_Trapping:
|
|
case LangOptions::SOB_Trapping:
|
|
@@ -2264,8 +2263,7 @@ Value *ScalarExprEmitter::EmitAdd(const BinOpInfo &op) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if (op.Ty->isUnsignedIntegerType() &&
|
|
|
|
- CGF.getLangOpts().SanitizeUnsignedIntegerOverflow)
|
|
|
|
|
|
+ if (op.Ty->isUnsignedIntegerType() && CGF.SanOpts->UnsignedIntegerOverflow)
|
|
return EmitOverflowCheckedBinOp(op);
|
|
return EmitOverflowCheckedBinOp(op);
|
|
|
|
|
|
if (op.LHS->getType()->isFPOrFPVectorTy()) {
|
|
if (op.LHS->getType()->isFPOrFPVectorTy()) {
|
|
@@ -2287,7 +2285,7 @@ Value *ScalarExprEmitter::EmitSub(const BinOpInfo &op) {
|
|
case LangOptions::SOB_Defined:
|
|
case LangOptions::SOB_Defined:
|
|
return Builder.CreateSub(op.LHS, op.RHS, "sub");
|
|
return Builder.CreateSub(op.LHS, op.RHS, "sub");
|
|
case LangOptions::SOB_Undefined:
|
|
case LangOptions::SOB_Undefined:
|
|
- if (!CGF.getLangOpts().SanitizeSignedIntegerOverflow)
|
|
|
|
|
|
+ if (!CGF.SanOpts->SignedIntegerOverflow)
|
|
return Builder.CreateNSWSub(op.LHS, op.RHS, "sub");
|
|
return Builder.CreateNSWSub(op.LHS, op.RHS, "sub");
|
|
// Fall through.
|
|
// Fall through.
|
|
case LangOptions::SOB_Trapping:
|
|
case LangOptions::SOB_Trapping:
|
|
@@ -2295,8 +2293,7 @@ Value *ScalarExprEmitter::EmitSub(const BinOpInfo &op) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if (op.Ty->isUnsignedIntegerType() &&
|
|
|
|
- CGF.getLangOpts().SanitizeUnsignedIntegerOverflow)
|
|
|
|
|
|
+ if (op.Ty->isUnsignedIntegerType() && CGF.SanOpts->UnsignedIntegerOverflow)
|
|
return EmitOverflowCheckedBinOp(op);
|
|
return EmitOverflowCheckedBinOp(op);
|
|
|
|
|
|
if (op.LHS->getType()->isFPOrFPVectorTy()) {
|
|
if (op.LHS->getType()->isFPOrFPVectorTy()) {
|
|
@@ -2383,8 +2380,8 @@ Value *ScalarExprEmitter::EmitShl(const BinOpInfo &Ops) {
|
|
if (Ops.LHS->getType() != RHS->getType())
|
|
if (Ops.LHS->getType() != RHS->getType())
|
|
RHS = Builder.CreateIntCast(RHS, Ops.LHS->getType(), false, "sh_prom");
|
|
RHS = Builder.CreateIntCast(RHS, Ops.LHS->getType(), false, "sh_prom");
|
|
|
|
|
|
- if (CGF.getLangOpts().SanitizeShift && !CGF.getLangOpts().OpenCL
|
|
|
|
- && isa<llvm::IntegerType>(Ops.LHS->getType())) {
|
|
|
|
|
|
+ if (CGF.SanOpts->Shift && !CGF.getLangOpts().OpenCL &&
|
|
|
|
+ isa<llvm::IntegerType>(Ops.LHS->getType())) {
|
|
llvm::Value *WidthMinusOne = GetWidthMinusOneValue(Ops.LHS, RHS);
|
|
llvm::Value *WidthMinusOne = GetWidthMinusOneValue(Ops.LHS, RHS);
|
|
// FIXME: Emit the branching explicitly rather than emitting the check
|
|
// FIXME: Emit the branching explicitly rather than emitting the check
|
|
// twice.
|
|
// twice.
|
|
@@ -2424,8 +2421,8 @@ Value *ScalarExprEmitter::EmitShr(const BinOpInfo &Ops) {
|
|
if (Ops.LHS->getType() != RHS->getType())
|
|
if (Ops.LHS->getType() != RHS->getType())
|
|
RHS = Builder.CreateIntCast(RHS, Ops.LHS->getType(), false, "sh_prom");
|
|
RHS = Builder.CreateIntCast(RHS, Ops.LHS->getType(), false, "sh_prom");
|
|
|
|
|
|
- if (CGF.getLangOpts().SanitizeShift && !CGF.getLangOpts().OpenCL
|
|
|
|
- && isa<llvm::IntegerType>(Ops.LHS->getType()))
|
|
|
|
|
|
+ if (CGF.SanOpts->Shift && !CGF.getLangOpts().OpenCL &&
|
|
|
|
+ isa<llvm::IntegerType>(Ops.LHS->getType()))
|
|
EmitBinOpCheck(Builder.CreateICmpULE(RHS, GetWidthMinusOneValue(Ops.LHS, RHS)), Ops);
|
|
EmitBinOpCheck(Builder.CreateICmpULE(RHS, GetWidthMinusOneValue(Ops.LHS, RHS)), Ops);
|
|
|
|
|
|
// OpenCL 6.3j: shift values are effectively % word size of LHS.
|
|
// OpenCL 6.3j: shift values are effectively % word size of LHS.
|