@@ -16476,7 +16476,8 @@ inline QualType Sema::CheckBitwiseOperands(ExprResult &LHS, ExprResult &RHS,
16476
16476
// C99 6.5.[13,14]
16477
16477
inline QualType Sema::CheckLogicalOperands(ExprResult &LHS, ExprResult &RHS,
16478
16478
SourceLocation Loc,
16479
- BinaryOperatorKind Opc) {
16479
+ BinaryOperatorKind Opc,
16480
+ bool Diagnose) {
16480
16481
// Check vector operands differently.
16481
16482
if (LHS.get()->getType()->isVectorType() ||
16482
16483
RHS.get()->getType()->isVectorType())
@@ -16507,7 +16508,8 @@ inline QualType Sema::CheckLogicalOperands(ExprResult &LHS, ExprResult &RHS,
16507
16508
// Diagnose cases where the user write a logical and/or but probably meant a
16508
16509
// bitwise one. We do this when the LHS is a non-bool integer and the RHS
16509
16510
// is a constant.
16510
- if (!EnumConstantInBoolContext && LHS.get()->getType()->isIntegerType() &&
16511
+ if (Diagnose && !EnumConstantInBoolContext &&
16512
+ LHS.get()->getType()->isIntegerType() &&
16511
16513
!LHS.get()->getType()->isBooleanType() &&
16512
16514
RHS.get()->getType()->isIntegerType() && !RHS.get()->isValueDependent() &&
16513
16515
// Don't warn in macros or template instantiations.
@@ -18222,7 +18224,8 @@ static bool needsConversionOfHalfVec(bool OpRequiresConversion, ASTContext &Ctx,
18222
18224
18223
18225
ExprResult Sema::CreateBuiltinBinOp(SourceLocation OpLoc,
18224
18226
BinaryOperatorKind Opc, Expr *LHSExpr,
18225
- Expr *RHSExpr, bool ForFoldExpression) {
18227
+ Expr *RHSExpr, bool ForFoldExpression,
18228
+ bool ForBoundsCheckExpression) {
18226
18229
if (getLangOpts().CPlusPlus11 && isa<InitListExpr>(RHSExpr)) {
18227
18230
// The syntax only allows initializer lists on the RHS of assignment,
18228
18231
// so we don't need to worry about accepting invalid code for
@@ -18376,7 +18379,8 @@ ExprResult Sema::CreateBuiltinBinOp(SourceLocation OpLoc,
18376
18379
case BO_LAnd:
18377
18380
case BO_LOr:
18378
18381
ConvertHalfVec = true;
18379
- ResultTy = CheckLogicalOperands(LHS, RHS, OpLoc, Opc);
18382
+ ResultTy = CheckLogicalOperands(LHS, RHS, OpLoc, Opc,
18383
+ /*Diagnose=*/!ForBoundsCheckExpression);
18380
18384
break;
18381
18385
case BO_MulAssign:
18382
18386
case BO_DivAssign:
@@ -26099,7 +26103,9 @@ ExprResult BoundsCheckBuilder::BuildImplicitPointerArith(Sema &S,
26099
26103
Pointer = CastResult.get();
26100
26104
}
26101
26105
26102
- return S.CreateBuiltinBinOp(SourceLocation(), Opc, Pointer, RHS);
26106
+ return S.CreateBuiltinBinOp(SourceLocation(), Opc, Pointer, RHS,
26107
+ /*ForFoldExpression=*/false,
26108
+ /*ForBoundsCheckExpression=*/true);
26103
26109
}
26104
26110
26105
26111
OpaqueValueExpr *BoundsCheckBuilder::OpaqueWrap(Sema &S, Expr *E) {
@@ -26118,7 +26124,9 @@ bool BoundsCheckBuilder::BuildIndexBounds(Sema &S, Expr *Min, Expr *Max,
26118
26124
if (!(Max = Upper.get()))
26119
26125
return false;
26120
26126
}
26121
- ExprResult Count = S.CreateBuiltinBinOp(Max->getBeginLoc(), BO_Sub, Max, Min);
26127
+ ExprResult Count = S.CreateBuiltinBinOp(Max->getBeginLoc(), BO_Sub, Max, Min,
26128
+ /*ForFoldExpression=*/false,
26129
+ /*ForBoundsCheckExpression=*/true);
26122
26130
if (!Count.get())
26123
26131
return false;
26124
26132
@@ -26141,7 +26149,8 @@ bool BoundsCheckBuilder::BuildIndexBounds(Sema &S, Expr *Min, Expr *Max,
26141
26149
R.push_back(OpaqueStart);
26142
26150
IsSigned |= OpaqueStart->getType()->isSignedIntegerOrEnumerationType();
26143
26151
ExprResult CountTotal = S.CreateBuiltinBinOp(
26144
- OpaqueStart->getBeginLoc(), BO_Add, OpaqueStart, AccessCount);
26152
+ OpaqueStart->getBeginLoc(), BO_Add, OpaqueStart, AccessCount,
26153
+ /*ForFoldExpression=*/false, /*ForBoundsCheckExpression=*/true);
26145
26154
if (!(AccessCount = CountTotal.get()))
26146
26155
return false;
26147
26156
}
@@ -26326,7 +26335,9 @@ ExprResult BoundsCheckBuilder::Build(Sema &S, Expr *GuardedValue) {
26326
26335
if (NullCheck.isInvalid())
26327
26336
return ExprError();
26328
26337
// !Ptr || 0 <= Count <= (Upper - Ptr)
26329
- Cond = S.CreateBuiltinBinOp(Loc, BO_LOr, NullCheck.get(), Cond.get());
26338
+ Cond = S.CreateBuiltinBinOp(Loc, BO_LOr, NullCheck.get(), Cond.get(),
26339
+ /*ForFoldExpression=*/false,
26340
+ /*ForBoundsCheckExpression=*/true);
26330
26341
if (Cond.isInvalid())
26331
26342
return ExprError();
26332
26343
}
@@ -26341,8 +26352,10 @@ ExprResult BoundsCheckBuilder::Build(Sema &S, Expr *GuardedValue) {
26341
26352
ExprResult BasePtrBoundsCheck = BuildLEChecks(S, Loc, Bounds, OVEs);
26342
26353
if (!BasePtrBoundsCheck.get())
26343
26354
return ExprError();
26344
- Cond = S.CreateBuiltinBinOp(
26345
- Loc, BO_LAnd, BasePtrBoundsCheck.get(), Cond.get());
26355
+ Cond =
26356
+ S.CreateBuiltinBinOp(Loc, BO_LAnd, BasePtrBoundsCheck.get(), Cond.get(),
26357
+ /*ForFoldExpression=*/false,
26358
+ /*ForBoundsCheckExpression=*/true);
26346
26359
if (!Cond.get())
26347
26360
return ExprError();
26348
26361
}
@@ -26382,15 +26395,18 @@ ExprResult BoundsCheckBuilder::BuildLEChecks(
26382
26395
Bound = OVEs.back();
26383
26396
}
26384
26397
26385
- ExprResult LEBounds = S.CreateBuiltinBinOp(Loc, BO_LE, Bound, Next);
26398
+ ExprResult LEBounds = S.CreateBuiltinBinOp(
26399
+ Loc, BO_LE, Bound, Next, /*ForFoldExpression=*/false,
26400
+ /*ForBoundsCheckExpression=*/true);
26386
26401
if (LEBounds.isInvalid())
26387
26402
return ExprError();
26388
26403
26389
26404
if (!CondAccum) {
26390
26405
CondAccum = LEBounds.get();
26391
26406
} else {
26392
- ExprResult CondAnd = S.CreateBuiltinBinOp(Loc, BO_LAnd,
26393
- CondAccum, LEBounds.get());
26407
+ ExprResult CondAnd = S.CreateBuiltinBinOp(
26408
+ Loc, BO_LAnd, CondAccum, LEBounds.get(), /*ForFoldExpression=*/false,
26409
+ /*ForBoundsCheckExpression=*/true);
26394
26410
if (CondAnd.isInvalid())
26395
26411
return ExprError();
26396
26412
CondAccum = CondAnd.get();
0 commit comments