@@ -11649,19 +11649,30 @@ static void CheckBoolLikeConversion(Sema &S, Expr *E, SourceLocation CC) {
11649
11649
CheckImplicitConversion(S, E->IgnoreParenImpCasts(), S.Context.BoolTy, CC);
11650
11650
}
11651
11651
11652
- /// AnalyzeImplicitConversions - Find and report any interesting
11653
- /// implicit conversions in the given expression. There are a couple
11654
- /// of competing diagnostics here, -Wconversion and -Wsign-compare.
11655
- static void AnalyzeImplicitConversions(Sema &S, Expr *OrigE, SourceLocation CC,
11656
- bool IsListInit/*= false*/) {
11652
+ namespace {
11653
+ struct AnalyzeImplicitConversionsWorkItem {
11654
+ Expr *E;
11655
+ SourceLocation CC;
11656
+ bool IsListInit;
11657
+ };
11658
+ }
11659
+
11660
+ /// Data recursive variant of AnalyzeImplicitConversions. Subexpressions
11661
+ /// that should be visited are added to WorkList.
11662
+ static void AnalyzeImplicitConversions(
11663
+ Sema &S, AnalyzeImplicitConversionsWorkItem Item,
11664
+ llvm::SmallVectorImpl<AnalyzeImplicitConversionsWorkItem> &WorkList) {
11665
+ Expr *OrigE = Item.E;
11666
+ SourceLocation CC = Item.CC;
11667
+
11657
11668
QualType T = OrigE->getType();
11658
11669
Expr *E = OrigE->IgnoreParenImpCasts();
11659
11670
11660
11671
// Propagate whether we are in a C++ list initialization expression.
11661
11672
// If so, we do not issue warnings for implicit int-float conversion
11662
11673
// precision loss, because C++11 narrowing already handles it.
11663
- IsListInit =
11664
- IsListInit || (isa<InitListExpr>(OrigE) && S.getLangOpts().CPlusPlus);
11674
+ bool IsListInit = Item.IsListInit ||
11675
+ (isa<InitListExpr>(OrigE) && S.getLangOpts().CPlusPlus);
11665
11676
11666
11677
if (E->isTypeDependent() || E->isValueDependent())
11667
11678
return;
@@ -11707,15 +11718,16 @@ static void AnalyzeImplicitConversions(Sema &S, Expr *OrigE, SourceLocation CC,
11707
11718
// FIXME: Use a more uniform representation for this.
11708
11719
for (auto *SE : POE->semantics())
11709
11720
if (auto *OVE = dyn_cast<OpaqueValueExpr>(SE))
11710
- AnalyzeImplicitConversions(S, OVE->getSourceExpr(), CC, IsListInit);
11721
+ WorkList.push_back({ OVE->getSourceExpr(), CC, IsListInit} );
11711
11722
}
11712
11723
11713
11724
// Skip past explicit casts.
11714
11725
if (auto *CE = dyn_cast<ExplicitCastExpr>(E)) {
11715
11726
E = CE->getSubExpr()->IgnoreParenImpCasts();
11716
11727
if (!CE->getType()->isVoidType() && E->getType()->isAtomicType())
11717
11728
S.Diag(E->getBeginLoc(), diag::warn_atomic_implicit_seq_cst);
11718
- return AnalyzeImplicitConversions(S, E, CC, IsListInit);
11729
+ WorkList.push_back({E, CC, IsListInit});
11730
+ return;
11719
11731
}
11720
11732
11721
11733
if (BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) {
@@ -11754,7 +11766,7 @@ static void AnalyzeImplicitConversions(Sema &S, Expr *OrigE, SourceLocation CC,
11754
11766
// Ignore checking string literals that are in logical and operators.
11755
11767
// This is a common pattern for asserts.
11756
11768
continue;
11757
- AnalyzeImplicitConversions(S, ChildExpr, CC, IsListInit);
11769
+ WorkList.push_back({ ChildExpr, CC, IsListInit} );
11758
11770
}
11759
11771
11760
11772
if (BO && BO->isLogicalOp()) {
@@ -11778,6 +11790,17 @@ static void AnalyzeImplicitConversions(Sema &S, Expr *OrigE, SourceLocation CC,
11778
11790
}
11779
11791
}
11780
11792
11793
+ /// AnalyzeImplicitConversions - Find and report any interesting
11794
+ /// implicit conversions in the given expression. There are a couple
11795
+ /// of competing diagnostics here, -Wconversion and -Wsign-compare.
11796
+ static void AnalyzeImplicitConversions(Sema &S, Expr *OrigE, SourceLocation CC,
11797
+ bool IsListInit/*= false*/) {
11798
+ llvm::SmallVector<AnalyzeImplicitConversionsWorkItem, 16> WorkList;
11799
+ WorkList.push_back({OrigE, CC, IsListInit});
11800
+ while (!WorkList.empty())
11801
+ AnalyzeImplicitConversions(S, WorkList.pop_back_val(), WorkList);
11802
+ }
11803
+
11781
11804
/// Diagnose integer type and any valid implicit conversion to it.
11782
11805
static bool checkOpenCLEnqueueIntType(Sema &S, Expr *E, const QualType &IntT) {
11783
11806
// Taking into account implicit conversions,
0 commit comments