|
24 | 24 | #include "clang/AST/Attr.h" |
25 | 25 | #include "clang/AST/DeclObjC.h" |
26 | 26 | #include "clang/AST/Expr.h" |
27 | | -#include "clang/AST/ParentMapContext.h" |
28 | 27 | #include "clang/AST/RecordLayout.h" |
29 | 28 | #include "clang/AST/StmtVisitor.h" |
30 | 29 | #include "clang/Basic/CodeGenOptions.h" |
@@ -196,24 +195,13 @@ static bool CanElideOverflowCheck(const ASTContext &Ctx, const BinOpInfo &Op) { |
196 | 195 | if (!Op.mayHaveIntegerOverflow()) |
197 | 196 | return true; |
198 | 197 |
|
199 | | - const UnaryOperator *UO = dyn_cast<UnaryOperator>(Op.E); |
200 | | - |
201 | | - if (UO && UO->getOpcode() == UO_Minus && |
202 | | - Ctx.getLangOpts().isOverflowPatternExcluded( |
203 | | - LangOptions::OverflowPatternExclusionKind::NegUnsignedConst) && |
204 | | - UO->isIntegerConstantExpr(Ctx)) |
205 | | - return true; |
206 | | - |
207 | 198 | // If a unary op has a widened operand, the op cannot overflow. |
208 | | - if (UO) |
| 199 | + if (const auto *UO = dyn_cast<UnaryOperator>(Op.E)) |
209 | 200 | return !UO->canOverflow(); |
210 | 201 |
|
211 | 202 | // We usually don't need overflow checks for binops with widened operands. |
212 | 203 | // Multiplication with promoted unsigned operands is a special case. |
213 | 204 | const auto *BO = cast<BinaryOperator>(Op.E); |
214 | | - if (BO->hasExcludedOverflowPattern()) |
215 | | - return true; |
216 | | - |
217 | 205 | auto OptionalLHSTy = getUnwidenedIntegerType(Ctx, BO->getLHS()); |
218 | 206 | if (!OptionalLHSTy) |
219 | 207 | return false; |
@@ -2778,26 +2766,6 @@ llvm::Value *ScalarExprEmitter::EmitIncDecConsiderOverflowBehavior( |
2778 | 2766 | llvm_unreachable("Unknown SignedOverflowBehaviorTy"); |
2779 | 2767 | } |
2780 | 2768 |
|
2781 | | -/// For the purposes of overflow pattern exclusion, does this match the |
2782 | | -/// "while(i--)" pattern? |
2783 | | -static bool matchesPostDecrInWhile(const UnaryOperator *UO, bool isInc, |
2784 | | - bool isPre, ASTContext &Ctx) { |
2785 | | - if (isInc || isPre) |
2786 | | - return false; |
2787 | | - |
2788 | | - // -fsanitize-overflow-pattern-exclusion=post-decr-while |
2789 | | - if (!Ctx.getLangOpts().isOverflowPatternExcluded( |
2790 | | - LangOptions::OverflowPatternExclusionKind::PostDecrInWhile)) |
2791 | | - return false; |
2792 | | - |
2793 | | - // all Parents (usually just one) must be a WhileStmt |
2794 | | - for (const auto &Parent : Ctx.getParentMapContext().getParents(*UO)) |
2795 | | - if (!Parent.get<WhileStmt>()) |
2796 | | - return false; |
2797 | | - |
2798 | | - return true; |
2799 | | -} |
2800 | | - |
2801 | 2769 | namespace { |
2802 | 2770 | /// Handles check and update for lastprivate conditional variables. |
2803 | 2771 | class OMPLastprivateConditionalUpdateRAII { |
@@ -2909,10 +2877,6 @@ ScalarExprEmitter::EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV, |
2909 | 2877 | } else if (type->isIntegerType()) { |
2910 | 2878 | QualType promotedType; |
2911 | 2879 | bool canPerformLossyDemotionCheck = false; |
2912 | | - |
2913 | | - bool excludeOverflowPattern = |
2914 | | - matchesPostDecrInWhile(E, isInc, isPre, CGF.getContext()); |
2915 | | - |
2916 | 2880 | if (CGF.getContext().isPromotableIntegerType(type)) { |
2917 | 2881 | promotedType = CGF.getContext().getPromotedIntegerType(type); |
2918 | 2882 | assert(promotedType != type && "Shouldn't promote to the same type."); |
@@ -2972,8 +2936,7 @@ ScalarExprEmitter::EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV, |
2972 | 2936 | } else if (E->canOverflow() && type->isSignedIntegerOrEnumerationType()) { |
2973 | 2937 | value = EmitIncDecConsiderOverflowBehavior(E, value, isInc); |
2974 | 2938 | } else if (E->canOverflow() && type->isUnsignedIntegerType() && |
2975 | | - CGF.SanOpts.has(SanitizerKind::UnsignedIntegerOverflow) && |
2976 | | - !excludeOverflowPattern) { |
| 2939 | + CGF.SanOpts.has(SanitizerKind::UnsignedIntegerOverflow)) { |
2977 | 2940 | value = EmitOverflowCheckedBinOp(createBinOpInfoFromIncDec( |
2978 | 2941 | E, value, isInc, E->getFPFeaturesInEffect(CGF.getLangOpts()))); |
2979 | 2942 | } else { |
|
0 commit comments