@@ -9358,10 +9358,10 @@ void Sema::CheckMaxUnsignedZero(const CallExpr *Call,
9358
9358
///
9359
9359
/// This is to catch typos like `if (memcmp(&a, &b, sizeof(a) > 0))`.
9360
9360
static bool CheckMemorySizeofForComparison(Sema &S, const Expr *E,
9361
- IdentifierInfo *FnName,
9361
+ const IdentifierInfo *FnName,
9362
9362
SourceLocation FnLoc,
9363
9363
SourceLocation RParenLoc) {
9364
- const BinaryOperator *Size = dyn_cast<BinaryOperator>(E);
9364
+ const auto *Size = dyn_cast<BinaryOperator>(E);
9365
9365
if (!Size)
9366
9366
return false;
9367
9367
@@ -9955,7 +9955,7 @@ static const Expr *getStrlenExprArg(const Expr *E) {
9955
9955
}
9956
9956
9957
9957
void Sema::CheckStrncatArguments(const CallExpr *CE,
9958
- IdentifierInfo *FnName) {
9958
+ const IdentifierInfo *FnName) {
9959
9959
// Don't crash if the user has the wrong number of arguments.
9960
9960
if (CE->getNumArgs() < 3)
9961
9961
return;
@@ -10050,7 +10050,7 @@ void CheckFreeArgumentsAddressof(Sema &S, const std::string &CalleeName,
10050
10050
const UnaryOperator *UnaryExpr) {
10051
10051
if (const auto *Lvalue = dyn_cast<DeclRefExpr>(UnaryExpr->getSubExpr())) {
10052
10052
const Decl *D = Lvalue->getDecl();
10053
- if (auto *DD = dyn_cast<DeclaratorDecl>(D)) {
10053
+ if (const auto *DD = dyn_cast<DeclaratorDecl>(D)) {
10054
10054
if (!DD->getType()->isReferenceType())
10055
10055
return CheckFreeArgumentsOnLvalue(S, CalleeName, UnaryExpr, D);
10056
10056
}
@@ -10190,15 +10190,15 @@ Sema::CheckReturnValExpr(Expr *RetValExp, QualType lhsType,
10190
10190
PPC().CheckPPCMMAType(RetValExp->getType(), ReturnLoc);
10191
10191
}
10192
10192
10193
- void Sema::CheckFloatComparison(SourceLocation Loc, Expr *LHS, Expr *RHS ,
10194
- BinaryOperatorKind Opcode) {
10193
+ void Sema::CheckFloatComparison(SourceLocation Loc, const Expr *LHS ,
10194
+ const Expr *RHS, BinaryOperatorKind Opcode) {
10195
10195
if (!BinaryOperator::isEqualityOp(Opcode))
10196
10196
return;
10197
10197
10198
10198
// Match and capture subexpressions such as "(float) X == 0.1".
10199
- FloatingLiteral *FPLiteral;
10200
- CastExpr *FPCast;
10201
- auto getCastAndLiteral = [&FPLiteral, &FPCast](Expr *L, Expr *R) {
10199
+ const FloatingLiteral *FPLiteral;
10200
+ const CastExpr *FPCast;
10201
+ auto getCastAndLiteral = [&FPLiteral, &FPCast](const Expr *L, const Expr *R) {
10202
10202
FPLiteral = dyn_cast<FloatingLiteral>(L->IgnoreParens());
10203
10203
FPCast = dyn_cast<CastExpr>(R->IgnoreParens());
10204
10204
return FPLiteral && FPCast;
@@ -10225,13 +10225,13 @@ void Sema::CheckFloatComparison(SourceLocation Loc, Expr *LHS, Expr *RHS,
10225
10225
}
10226
10226
10227
10227
// Match a more general floating-point equality comparison (-Wfloat-equal).
10228
- Expr* LeftExprSansParen = LHS->IgnoreParenImpCasts();
10229
- Expr* RightExprSansParen = RHS->IgnoreParenImpCasts();
10228
+ const Expr * LeftExprSansParen = LHS->IgnoreParenImpCasts();
10229
+ const Expr * RightExprSansParen = RHS->IgnoreParenImpCasts();
10230
10230
10231
10231
// Special case: check for x == x (which is OK).
10232
10232
// Do not emit warnings for such cases.
10233
- if (auto *DRL = dyn_cast<DeclRefExpr>(LeftExprSansParen))
10234
- if (auto *DRR = dyn_cast<DeclRefExpr>(RightExprSansParen))
10233
+ if (const auto *DRL = dyn_cast<DeclRefExpr>(LeftExprSansParen))
10234
+ if (const auto *DRR = dyn_cast<DeclRefExpr>(RightExprSansParen))
10235
10235
if (DRL->getDecl() == DRR->getDecl())
10236
10236
return;
10237
10237
@@ -10240,22 +10240,21 @@ void Sema::CheckFloatComparison(SourceLocation Loc, Expr *LHS, Expr *RHS,
10240
10240
// is a heuristic: often comparison against such literals are used to
10241
10241
// detect if a value in a variable has not changed. This clearly can
10242
10242
// lead to false negatives.
10243
- if (FloatingLiteral* FLL = dyn_cast<FloatingLiteral>(LeftExprSansParen)) {
10243
+ if (const auto * FLL = dyn_cast<FloatingLiteral>(LeftExprSansParen)) {
10244
10244
if (FLL->isExact())
10245
10245
return;
10246
- } else
10247
- if (FloatingLiteral* FLR = dyn_cast<FloatingLiteral>(RightExprSansParen))
10248
- if (FLR->isExact())
10249
- return;
10246
+ } else if (const auto *FLR = dyn_cast<FloatingLiteral>(RightExprSansParen))
10247
+ if (FLR->isExact())
10248
+ return;
10250
10249
10251
10250
// Check for comparisons with builtin types.
10252
- if (CallExpr* CL = dyn_cast<CallExpr>(LeftExprSansParen))
10253
- if ( CL->getBuiltinCallee())
10254
- return;
10251
+ if (const auto * CL = dyn_cast<CallExpr>(LeftExprSansParen);
10252
+ CL && CL->getBuiltinCallee())
10253
+ return;
10255
10254
10256
- if (CallExpr* CR = dyn_cast<CallExpr>(RightExprSansParen))
10257
- if ( CR->getBuiltinCallee())
10258
- return;
10255
+ if (const auto * CR = dyn_cast<CallExpr>(RightExprSansParen);
10256
+ CR && CR->getBuiltinCallee())
10257
+ return;
10259
10258
10260
10259
// Emit the diagnostic.
10261
10260
Diag(Loc, diag::warn_floatingpoint_eq)
@@ -10302,18 +10301,18 @@ struct IntRange {
10302
10301
static IntRange forValueOfCanonicalType(ASTContext &C, const Type *T) {
10303
10302
assert(T->isCanonicalUnqualified());
10304
10303
10305
- if (const VectorType *VT = dyn_cast<VectorType>(T))
10304
+ if (const auto *VT = dyn_cast<VectorType>(T))
10306
10305
T = VT->getElementType().getTypePtr();
10307
- if (const ComplexType *CT = dyn_cast<ComplexType>(T))
10306
+ if (const auto *CT = dyn_cast<ComplexType>(T))
10308
10307
T = CT->getElementType().getTypePtr();
10309
- if (const AtomicType *AT = dyn_cast<AtomicType>(T))
10308
+ if (const auto *AT = dyn_cast<AtomicType>(T))
10310
10309
T = AT->getValueType().getTypePtr();
10311
10310
10312
10311
if (!C.getLangOpts().CPlusPlus) {
10313
10312
// For enum types in C code, use the underlying datatype.
10314
- if (const EnumType *ET = dyn_cast<EnumType>(T))
10313
+ if (const auto *ET = dyn_cast<EnumType>(T))
10315
10314
T = ET->getDecl()->getIntegerType().getDesugaredType(C).getTypePtr();
10316
- } else if (const EnumType *ET = dyn_cast<EnumType>(T)) {
10315
+ } else if (const auto *ET = dyn_cast<EnumType>(T)) {
10317
10316
// For enum types in C++, use the known bit width of the enumerators.
10318
10317
EnumDecl *Enum = ET->getDecl();
10319
10318
// In C++11, enums can have a fixed underlying type. Use this type to
@@ -10432,8 +10431,7 @@ struct IntRange {
10432
10431
10433
10432
} // namespace
10434
10433
10435
- static IntRange GetValueRange(ASTContext &C, llvm::APSInt &value,
10436
- unsigned MaxWidth) {
10434
+ static IntRange GetValueRange(llvm::APSInt &value, unsigned MaxWidth) {
10437
10435
if (value.isSigned() && value.isNegative())
10438
10436
return IntRange(value.getSignificantBits(), false);
10439
10437
@@ -10445,23 +10443,22 @@ static IntRange GetValueRange(ASTContext &C, llvm::APSInt &value,
10445
10443
return IntRange(value.getActiveBits(), true);
10446
10444
}
10447
10445
10448
- static IntRange GetValueRange(ASTContext &C, APValue &result, QualType Ty,
10449
- unsigned MaxWidth) {
10446
+ static IntRange GetValueRange(APValue &result, QualType Ty, unsigned MaxWidth) {
10450
10447
if (result.isInt())
10451
- return GetValueRange(C, result.getInt(), MaxWidth);
10448
+ return GetValueRange(result.getInt(), MaxWidth);
10452
10449
10453
10450
if (result.isVector()) {
10454
- IntRange R = GetValueRange(C, result.getVectorElt(0), Ty, MaxWidth);
10451
+ IntRange R = GetValueRange(result.getVectorElt(0), Ty, MaxWidth);
10455
10452
for (unsigned i = 1, e = result.getVectorLength(); i != e; ++i) {
10456
- IntRange El = GetValueRange(C, result.getVectorElt(i), Ty, MaxWidth);
10453
+ IntRange El = GetValueRange(result.getVectorElt(i), Ty, MaxWidth);
10457
10454
R = IntRange::join(R, El);
10458
10455
}
10459
10456
return R;
10460
10457
}
10461
10458
10462
10459
if (result.isComplexInt()) {
10463
- IntRange R = GetValueRange(C, result.getComplexIntReal(), MaxWidth);
10464
- IntRange I = GetValueRange(C, result.getComplexIntImag(), MaxWidth);
10460
+ IntRange R = GetValueRange(result.getComplexIntReal(), MaxWidth);
10461
+ IntRange I = GetValueRange(result.getComplexIntImag(), MaxWidth);
10465
10462
return IntRange::join(R, I);
10466
10463
}
10467
10464
@@ -10476,7 +10473,7 @@ static IntRange GetValueRange(ASTContext &C, APValue &result, QualType Ty,
10476
10473
10477
10474
static QualType GetExprType(const Expr *E) {
10478
10475
QualType Ty = E->getType();
10479
- if (const AtomicType *AtomicRHS = Ty->getAs<AtomicType>())
10476
+ if (const auto *AtomicRHS = Ty->getAs<AtomicType>())
10480
10477
Ty = AtomicRHS->getValueType();
10481
10478
return Ty;
10482
10479
}
@@ -10503,7 +10500,7 @@ static std::optional<IntRange> TryGetExprRange(ASTContext &C, const Expr *E,
10503
10500
// Try a full evaluation first.
10504
10501
Expr::EvalResult result;
10505
10502
if (E->EvaluateAsRValue(result, C, InConstantContext))
10506
- return GetValueRange(C, result.Val, GetExprType(E), MaxWidth);
10503
+ return GetValueRange(result.Val, GetExprType(E), MaxWidth);
10507
10504
10508
10505
// I think we only want to look through implicit casts here; if the
10509
10506
// user has an explicit widening cast, we should treat the value as
@@ -10856,10 +10853,9 @@ static bool IsSameFloatAfterCast(const APValue &value,
10856
10853
static void AnalyzeImplicitConversions(Sema &S, Expr *E, SourceLocation CC,
10857
10854
bool IsListInit = false);
10858
10855
10859
- static bool IsEnumConstOrFromMacro(Sema &S, Expr *E) {
10856
+ static bool IsEnumConstOrFromMacro(Sema &S, const Expr *E) {
10860
10857
// Suppress cases where we are comparing against an enum constant.
10861
- if (const DeclRefExpr *DR =
10862
- dyn_cast<DeclRefExpr>(E->IgnoreParenImpCasts()))
10858
+ if (const auto *DR = dyn_cast<DeclRefExpr>(E->IgnoreParenImpCasts()))
10863
10859
if (isa<EnumConstantDecl>(DR->getDecl()))
10864
10860
return true;
10865
10861
@@ -10877,7 +10873,7 @@ static bool IsEnumConstOrFromMacro(Sema &S, Expr *E) {
10877
10873
return false;
10878
10874
}
10879
10875
10880
- static bool isKnownToHaveUnsignedValue(Expr *E) {
10876
+ static bool isKnownToHaveUnsignedValue(const Expr *E) {
10881
10877
return E->getType()->isIntegerType() &&
10882
10878
(!E->getType()->isSignedIntegerType() ||
10883
10879
!E->IgnoreParenImpCasts()->getType()->isSignedIntegerType());
@@ -11008,9 +11004,9 @@ struct PromotedRange {
11008
11004
};
11009
11005
}
11010
11006
11011
- static bool HasEnumType(Expr *E) {
11007
+ static bool HasEnumType(const Expr *E) {
11012
11008
// Strip off implicit integral promotions.
11013
- while (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) {
11009
+ while (const auto *ICE = dyn_cast<ImplicitCastExpr>(E)) {
11014
11010
if (ICE->getCastKind() != CK_IntegralCast &&
11015
11011
ICE->getCastKind() != CK_NoOp)
11016
11012
break;
@@ -11128,7 +11124,7 @@ static bool CheckTautologicalComparison(Sema &S, BinaryOperator *E,
11128
11124
// If this is a comparison to an enum constant, include that
11129
11125
// constant in the diagnostic.
11130
11126
const EnumConstantDecl *ED = nullptr;
11131
- if (const DeclRefExpr *DR = dyn_cast<DeclRefExpr>(Constant))
11127
+ if (const auto *DR = dyn_cast<DeclRefExpr>(Constant))
11132
11128
ED = dyn_cast<EnumConstantDecl>(DR->getDecl());
11133
11129
11134
11130
// Should be enough for uint128 (39 decimal digits)
@@ -11503,9 +11499,9 @@ static void AnalyzeAssignment(Sema &S, BinaryOperator *E) {
11503
11499
}
11504
11500
11505
11501
/// Diagnose an implicit cast; purely a helper for CheckImplicitConversion.
11506
- static void DiagnoseImpCast(Sema &S, Expr *E, QualType SourceType, QualType T ,
11507
- SourceLocation CContext, unsigned diag,
11508
- bool pruneControlFlow = false) {
11502
+ static void DiagnoseImpCast(Sema &S, const Expr *E, QualType SourceType,
11503
+ QualType T, SourceLocation CContext, unsigned diag,
11504
+ bool PruneControlFlow = false) {
11509
11505
// For languages like HLSL and OpenCL, implicit conversion diagnostics listing
11510
11506
// address space annotations isn't really useful. The warnings aren't because
11511
11507
// you're converting a `private int` to `unsigned int`, it is because you're
@@ -11514,7 +11510,7 @@ static void DiagnoseImpCast(Sema &S, Expr *E, QualType SourceType, QualType T,
11514
11510
SourceType = S.getASTContext().removeAddrSpaceQualType(SourceType);
11515
11511
if (T.hasAddressSpace())
11516
11512
T = S.getASTContext().removeAddrSpaceQualType(T);
11517
- if (pruneControlFlow ) {
11513
+ if (PruneControlFlow ) {
11518
11514
S.DiagRuntimeBehavior(E->getExprLoc(), E,
11519
11515
S.PDiag(diag)
11520
11516
<< SourceType << T << E->getSourceRange()
@@ -11526,26 +11522,25 @@ static void DiagnoseImpCast(Sema &S, Expr *E, QualType SourceType, QualType T,
11526
11522
}
11527
11523
11528
11524
/// Diagnose an implicit cast; purely a helper for CheckImplicitConversion.
11529
- static void DiagnoseImpCast(Sema &S, Expr *E, QualType T,
11530
- SourceLocation CContext,
11531
- unsigned diag, bool pruneControlFlow = false) {
11532
- DiagnoseImpCast(S, E, E->getType(), T, CContext, diag, pruneControlFlow );
11525
+ static void DiagnoseImpCast(Sema &S, const Expr *E, QualType T,
11526
+ SourceLocation CContext, unsigned diag,
11527
+ bool PruneControlFlow = false) {
11528
+ DiagnoseImpCast(S, E, E->getType(), T, CContext, diag, PruneControlFlow );
11533
11529
}
11534
11530
11535
11531
/// Diagnose an implicit cast from a floating point value to an integer value.
11536
- static void DiagnoseFloatingImpCast(Sema &S, Expr *E, QualType T,
11532
+ static void DiagnoseFloatingImpCast(Sema &S, const Expr *E, QualType T,
11537
11533
SourceLocation CContext) {
11538
- const bool IsBool = T->isSpecificBuiltinType(BuiltinType::Bool);
11539
- const bool PruneWarnings = S.inTemplateInstantiation();
11534
+ bool IsBool = T->isSpecificBuiltinType(BuiltinType::Bool);
11535
+ bool PruneWarnings = S.inTemplateInstantiation();
11540
11536
11541
- Expr *InnerE = E->IgnoreParenImpCasts();
11537
+ const Expr *InnerE = E->IgnoreParenImpCasts();
11542
11538
// We also want to warn on, e.g., "int i = -1.234"
11543
- if (UnaryOperator *UOp = dyn_cast<UnaryOperator>(InnerE))
11539
+ if (const auto *UOp = dyn_cast<UnaryOperator>(InnerE))
11544
11540
if (UOp->getOpcode() == UO_Minus || UOp->getOpcode() == UO_Plus)
11545
11541
InnerE = UOp->getSubExpr()->IgnoreParenImpCasts();
11546
11542
11547
- const bool IsLiteral =
11548
- isa<FloatingLiteral>(E) || isa<FloatingLiteral>(InnerE);
11543
+ bool IsLiteral = isa<FloatingLiteral>(E) || isa<FloatingLiteral>(InnerE);
11549
11544
11550
11545
llvm::APFloat Value(0.0);
11551
11546
bool IsConstant =
@@ -11703,37 +11698,37 @@ static std::string PrettyPrintInRange(const llvm::APSInt &Value,
11703
11698
return toString(ValueInRange, 10);
11704
11699
}
11705
11700
11706
- static bool IsImplicitBoolFloatConversion(Sema &S, Expr *Ex, bool ToBool) {
11701
+ static bool IsImplicitBoolFloatConversion(Sema &S, const Expr *Ex,
11702
+ bool ToBool) {
11707
11703
if (!isa<ImplicitCastExpr>(Ex))
11708
11704
return false;
11709
11705
11710
- Expr *InnerE = Ex->IgnoreParenImpCasts();
11706
+ const Expr *InnerE = Ex->IgnoreParenImpCasts();
11711
11707
const Type *Target = S.Context.getCanonicalType(Ex->getType()).getTypePtr();
11712
11708
const Type *Source =
11713
11709
S.Context.getCanonicalType(InnerE->getType()).getTypePtr();
11714
11710
if (Target->isDependentType())
11715
11711
return false;
11716
11712
11717
- const BuiltinType *FloatCandidateBT =
11718
- dyn_cast<BuiltinType>(ToBool ? Source : Target);
11713
+ const auto *FloatCandidateBT =
11714
+ dyn_cast<BuiltinType>(ToBool ? Source : Target);
11719
11715
const Type *BoolCandidateType = ToBool ? Target : Source;
11720
11716
11721
11717
return (BoolCandidateType->isSpecificBuiltinType(BuiltinType::Bool) &&
11722
11718
FloatCandidateBT && (FloatCandidateBT->isFloatingPoint()));
11723
11719
}
11724
11720
11725
- static void CheckImplicitArgumentConversions(Sema &S, CallExpr *TheCall,
11721
+ static void CheckImplicitArgumentConversions(Sema &S, const CallExpr *TheCall,
11726
11722
SourceLocation CC) {
11727
- unsigned NumArgs = TheCall->getNumArgs();
11728
- for (unsigned i = 0; i < NumArgs; ++i) {
11729
- Expr *CurrA = TheCall->getArg(i);
11723
+ for (unsigned I = 0, N = TheCall->getNumArgs(); I < N; ++I) {
11724
+ const Expr *CurrA = TheCall->getArg(I);
11730
11725
if (!IsImplicitBoolFloatConversion(S, CurrA, true))
11731
11726
continue;
11732
11727
11733
- bool IsSwapped = ((i > 0) &&
11734
- IsImplicitBoolFloatConversion( S, TheCall->getArg(i - 1), false));
11735
- IsSwapped |= ((i < (NumArgs - 1)) &&
11736
- IsImplicitBoolFloatConversion( S, TheCall->getArg(i + 1), false));
11728
+ bool IsSwapped = ((I > 0) && IsImplicitBoolFloatConversion(
11729
+ S, TheCall->getArg(I - 1), false));
11730
+ IsSwapped |= ((I < (N - 1)) && IsImplicitBoolFloatConversion(
11731
+ S, TheCall->getArg(I + 1), false));
11737
11732
if (IsSwapped) {
11738
11733
// Warn on this floating-point to bool conversion.
11739
11734
DiagnoseImpCast(S, CurrA->IgnoreParenImpCasts(),
@@ -12568,7 +12563,7 @@ static void AnalyzeImplicitConversions(
12568
12563
}
12569
12564
12570
12565
// Check implicit argument conversions for function calls.
12571
- if (CallExpr *Call = dyn_cast<CallExpr>(SourceExpr))
12566
+ if (const auto *Call = dyn_cast<CallExpr>(SourceExpr))
12572
12567
CheckImplicitArgumentConversions(S, Call, CC);
12573
12568
12574
12569
// Go ahead and check any implicit conversions we might have skipped.
0 commit comments