Skip to content

[clang][analyzer] Handle CXXParenInitListExpr alongside InitListExpr #136041

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 2 commits into from
Apr 20, 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
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,8 @@ Code Completion

Static Analyzer
---------------
- Fixed a crash when C++20 parenthesized initializer lists are used. This issue
was causing a crash in clang-tidy. (#GH136041)

New features
^^^^^^^^^^^^
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,9 @@ void DynamicTypePropagation::checkPostCall(const CallEvent &Call,
// aggregates, and in such case no top-frame constructor will be called.
// Figure out if we need to do anything in this case.
// FIXME: Instead of relying on the ParentMap, we should have the
// trigger-statement (InitListExpr in this case) available in this
// callback, ideally as part of CallEvent.
if (isa_and_nonnull<InitListExpr>(
// trigger-statement (InitListExpr or CXXParenListInitExpr in this case)
// available in this callback, ideally as part of CallEvent.
if (isa_and_nonnull<InitListExpr, CXXParenListInitExpr>(
LCtx->getParentMap().getParent(Ctor->getOriginExpr())))
return;

Expand Down
10 changes: 6 additions & 4 deletions clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,9 +644,10 @@ void ExprEngine::handleConstructor(const Expr *E,
// FIXME: For now this code essentially bails out. We need to find the
// correct target region and set it.
// FIXME: Instead of relying on the ParentMap, we should have the
// trigger-statement (InitListExpr in this case) passed down from CFG or
// otherwise always available during construction.
if (isa_and_nonnull<InitListExpr>(LCtx->getParentMap().getParent(E))) {
// trigger-statement (InitListExpr or CXXParenListInitExpr in this case)
// passed down from CFG or otherwise always available during construction.
if (isa_and_nonnull<InitListExpr, CXXParenListInitExpr>(
LCtx->getParentMap().getParent(E))) {
MemRegionManager &MRMgr = getSValBuilder().getRegionManager();
Target = loc::MemRegionVal(MRMgr.getCXXTempObjectRegion(E, LCtx));
CallOpts.IsCtorOrDtorWithImproperlyModeledTargetRegion = true;
Expand Down Expand Up @@ -1017,7 +1018,8 @@ void ExprEngine::VisitCXXNewExpr(const CXXNewExpr *CNE, ExplodedNode *Pred,
// values are properly placed inside the required region, however if an
// initializer list is used, this doesn't happen automatically.
auto *Init = CNE->getInitializer();
bool isInitList = isa_and_nonnull<InitListExpr>(Init);
bool isInitList =
isa_and_nonnull<InitListExpr, CXXParenListInitExpr>(Init);

QualType ObjTy =
isInitList ? Init->getType() : CNE->getType()->getPointeeType();
Expand Down
19 changes: 19 additions & 0 deletions clang/test/Analysis/PR135665.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// RUN: %clang_analyze_cc1 -std=c++20 -analyzer-checker=core -verify %s

// expected-no-diagnostics

template<typename... F>
struct overload : public F...
{
using F::operator()...;
};

template<typename... F>
overload(F&&...) -> overload<F...>;

int main()
{
const auto l = overload([](const int* i) {}); // no-crash

return 0;
}