@@ -16371,7 +16371,8 @@ inline QualType Sema::CheckBitwiseOperands(ExprResult &LHS, ExprResult &RHS,
1637116371// C99 6.5.[13,14]
1637216372inline QualType Sema::CheckLogicalOperands(ExprResult &LHS, ExprResult &RHS,
1637316373 SourceLocation Loc,
16374- BinaryOperatorKind Opc) {
16374+ BinaryOperatorKind Opc,
16375+ bool Diagnose) {
1637516376 // Check vector operands differently.
1637616377 if (LHS.get()->getType()->isVectorType() ||
1637716378 RHS.get()->getType()->isVectorType())
@@ -16402,7 +16403,8 @@ inline QualType Sema::CheckLogicalOperands(ExprResult &LHS, ExprResult &RHS,
1640216403 // Diagnose cases where the user write a logical and/or but probably meant a
1640316404 // bitwise one. We do this when the LHS is a non-bool integer and the RHS
1640416405 // is a constant.
16405- if (!EnumConstantInBoolContext && LHS.get()->getType()->isIntegerType() &&
16406+ if (Diagnose && !EnumConstantInBoolContext &&
16407+ LHS.get()->getType()->isIntegerType() &&
1640616408 !LHS.get()->getType()->isBooleanType() &&
1640716409 RHS.get()->getType()->isIntegerType() && !RHS.get()->isValueDependent() &&
1640816410 // Don't warn in macros or template instantiations.
@@ -18107,7 +18109,8 @@ static bool needsConversionOfHalfVec(bool OpRequiresConversion, ASTContext &Ctx,
1810718109
1810818110ExprResult Sema::CreateBuiltinBinOp(SourceLocation OpLoc,
1810918111 BinaryOperatorKind Opc, Expr *LHSExpr,
18110- Expr *RHSExpr, bool ForFoldExpression) {
18112+ Expr *RHSExpr, bool ForFoldExpression,
18113+ bool ForBoundsCheckExpression) {
1811118114 if (getLangOpts().CPlusPlus11 && isa<InitListExpr>(RHSExpr)) {
1811218115 // The syntax only allows initializer lists on the RHS of assignment,
1811318116 // so we don't need to worry about accepting invalid code for
@@ -18264,7 +18267,8 @@ ExprResult Sema::CreateBuiltinBinOp(SourceLocation OpLoc,
1826418267 case BO_LAnd:
1826518268 case BO_LOr:
1826618269 ConvertHalfVec = true;
18267- ResultTy = CheckLogicalOperands(LHS, RHS, OpLoc, Opc);
18270+ ResultTy = CheckLogicalOperands(LHS, RHS, OpLoc, Opc,
18271+ /*Diagnose=*/!ForBoundsCheckExpression);
1826818272 break;
1826918273 case BO_MulAssign:
1827018274 case BO_DivAssign:
@@ -26025,7 +26029,9 @@ ExprResult BoundsCheckBuilder::BuildImplicitPointerArith(Sema &S,
2602526029 Pointer = CastResult.get();
2602626030 }
2602726031
26028- return S.CreateBuiltinBinOp(SourceLocation(), Opc, Pointer, RHS);
26032+ return S.CreateBuiltinBinOp(SourceLocation(), Opc, Pointer, RHS,
26033+ /*ForFoldExpression=*/false,
26034+ /*ForBoundsCheckExpression=*/true);
2602926035}
2603026036
2603126037OpaqueValueExpr *BoundsCheckBuilder::OpaqueWrap(Sema &S, Expr *E) {
@@ -26044,7 +26050,9 @@ bool BoundsCheckBuilder::BuildIndexBounds(Sema &S, Expr *Min, Expr *Max,
2604426050 if (!(Max = Upper.get()))
2604526051 return false;
2604626052 }
26047- ExprResult Count = S.CreateBuiltinBinOp(Max->getBeginLoc(), BO_Sub, Max, Min);
26053+ ExprResult Count = S.CreateBuiltinBinOp(Max->getBeginLoc(), BO_Sub, Max, Min,
26054+ /*ForFoldExpression=*/false,
26055+ /*ForBoundsCheckExpression=*/true);
2604826056 if (!Count.get())
2604926057 return false;
2605026058
@@ -26067,7 +26075,8 @@ bool BoundsCheckBuilder::BuildIndexBounds(Sema &S, Expr *Min, Expr *Max,
2606726075 R.push_back(OpaqueStart);
2606826076 IsSigned |= OpaqueStart->getType()->isSignedIntegerOrEnumerationType();
2606926077 ExprResult CountTotal = S.CreateBuiltinBinOp(
26070- OpaqueStart->getBeginLoc(), BO_Add, OpaqueStart, AccessCount);
26078+ OpaqueStart->getBeginLoc(), BO_Add, OpaqueStart, AccessCount,
26079+ /*ForFoldExpression=*/false, /*ForBoundsCheckExpression=*/true);
2607126080 if (!(AccessCount = CountTotal.get()))
2607226081 return false;
2607326082 }
@@ -26252,7 +26261,9 @@ ExprResult BoundsCheckBuilder::Build(Sema &S, Expr *GuardedValue) {
2625226261 if (NullCheck.isInvalid())
2625326262 return ExprError();
2625426263 // !Ptr || 0 <= Count <= (Upper - Ptr)
26255- Cond = S.CreateBuiltinBinOp(Loc, BO_LOr, NullCheck.get(), Cond.get());
26264+ Cond = S.CreateBuiltinBinOp(Loc, BO_LOr, NullCheck.get(), Cond.get(),
26265+ /*ForFoldExpression=*/false,
26266+ /*ForBoundsCheckExpression=*/true);
2625626267 if (Cond.isInvalid())
2625726268 return ExprError();
2625826269 }
@@ -26267,8 +26278,10 @@ ExprResult BoundsCheckBuilder::Build(Sema &S, Expr *GuardedValue) {
2626726278 ExprResult BasePtrBoundsCheck = BuildLEChecks(S, Loc, Bounds, OVEs);
2626826279 if (!BasePtrBoundsCheck.get())
2626926280 return ExprError();
26270- Cond = S.CreateBuiltinBinOp(
26271- Loc, BO_LAnd, BasePtrBoundsCheck.get(), Cond.get());
26281+ Cond =
26282+ S.CreateBuiltinBinOp(Loc, BO_LAnd, BasePtrBoundsCheck.get(), Cond.get(),
26283+ /*ForFoldExpression=*/false,
26284+ /*ForBoundsCheckExpression=*/true);
2627226285 if (!Cond.get())
2627326286 return ExprError();
2627426287 }
@@ -26308,15 +26321,18 @@ ExprResult BoundsCheckBuilder::BuildLEChecks(
2630826321 Bound = OVEs.back();
2630926322 }
2631026323
26311- ExprResult LEBounds = S.CreateBuiltinBinOp(Loc, BO_LE, Bound, Next);
26324+ ExprResult LEBounds = S.CreateBuiltinBinOp(
26325+ Loc, BO_LE, Bound, Next, /*ForFoldExpression=*/false,
26326+ /*ForBoundsCheckExpression=*/true);
2631226327 if (LEBounds.isInvalid())
2631326328 return ExprError();
2631426329
2631526330 if (!CondAccum) {
2631626331 CondAccum = LEBounds.get();
2631726332 } else {
26318- ExprResult CondAnd = S.CreateBuiltinBinOp(Loc, BO_LAnd,
26319- CondAccum, LEBounds.get());
26333+ ExprResult CondAnd = S.CreateBuiltinBinOp(
26334+ Loc, BO_LAnd, CondAccum, LEBounds.get(), /*ForFoldExpression=*/false,
26335+ /*ForBoundsCheckExpression=*/true);
2632026336 if (CondAnd.isInvalid())
2632126337 return ExprError();
2632226338 CondAccum = CondAnd.get();
0 commit comments