Skip to content

[Sema] Avoid deep recursion in AnalyzeImplicitConversions #145734

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions clang/lib/Sema/SemaChecking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11684,15 +11684,6 @@ static void DiagnoseFloatingImpCast(Sema &S, const Expr *E, QualType T,
}
}

static void CheckCommaOperand(Sema &S, Expr *E, QualType T, SourceLocation CC,
bool ExtraCheckForImplicitConversion) {
E = E->IgnoreParenImpCasts();
AnalyzeImplicitConversions(S, E, CC);

if (ExtraCheckForImplicitConversion && E->getType() != T)
S.CheckImplicitConversion(E, T, CC);
}

/// Analyze the given compound assignment for the possible losing of
/// floating-point precision.
static void AnalyzeCompoundAssignment(Sema &S, BinaryOperator *E) {
Expand Down Expand Up @@ -12567,6 +12558,17 @@ struct AnalyzeImplicitConversionsWorkItem {
};
}

static void CheckCommaOperand(
Sema &S, Expr *E, QualType T, SourceLocation CC,
bool ExtraCheckForImplicitConversion,
llvm::SmallVectorImpl<AnalyzeImplicitConversionsWorkItem> &WorkList) {
E = E->IgnoreParenImpCasts();
WorkList.push_back({E, CC, false});

if (ExtraCheckForImplicitConversion && E->getType() != T)
S.CheckImplicitConversion(E, T, CC);
}

/// Data recursive variant of AnalyzeImplicitConversions. Subexpressions
/// that should be visited are added to WorkList.
static void AnalyzeImplicitConversions(
Expand Down Expand Up @@ -12642,9 +12644,9 @@ static void AnalyzeImplicitConversions(
/// how CheckConditionalOperand behaves; it's as-if the correct operand
/// were directly used for the implicit conversion check.
CheckCommaOperand(S, BO->getLHS(), T, BO->getOperatorLoc(),
/*ExtraCheckForImplicitConversion=*/false);
/*ExtraCheckForImplicitConversion=*/false, WorkList);
CheckCommaOperand(S, BO->getRHS(), T, BO->getOperatorLoc(),
/*ExtraCheckForImplicitConversion=*/true);
/*ExtraCheckForImplicitConversion=*/true, WorkList);
return;
}
}
Expand Down
Loading
Loading