Skip to content

Commit 6379f40

Browse files
committed
[clang][analyzer] Handle CXXParenInitListExpr alongside InitListExpr
As reported in #135665, C++20 parenthesis initializer list expressions are not handled correctly and were causing crashes. This commit attempts to fix the issue by handing parenthesis initializer lists along side existing initializer lists.
1 parent 52e10e6 commit 6379f40

File tree

4 files changed

+32
-25
lines changed

4 files changed

+32
-25
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,6 @@ Modified Compiler Flags
219219

220220
- `-Wpadded` option implemented for the `x86_64-windows-msvc` target. Fixes #61702
221221

222-
- The ``-mexecute-only`` and ``-mpure-code`` flags are now accepted for AArch64 targets. (#GH125688)
223-
224-
- The ``-Og`` optimization flag now sets ``-fextend-variable-liveness``,
225-
reducing performance slightly while reducing the number of optimized-out
226-
variables.
227-
228222
Removed Compiler Flags
229223
-------------------------
230224

@@ -432,9 +426,6 @@ Bug Fixes in This Version
432426
using C++23 "deducing this" did not have a diagnostic location (#GH135522)
433427

434428
- Fixed a crash when a ``friend`` function is redefined as deleted. (#GH135506)
435-
- Fixed a crash when ``#embed`` appears as a part of a failed constant
436-
evaluation. The crashes were happening during diagnostics emission due to
437-
unimplemented statement printer. (#GH132641)
438429

439430
Bug Fixes to Compiler Builtins
440431
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -477,11 +468,9 @@ Bug Fixes to C++ Support
477468
by template argument deduction.
478469
- Clang is now better at instantiating the function definition after its use inside
479470
of a constexpr lambda. (#GH125747)
480-
- Fixed a local class member function instantiation bug inside dependent lambdas. (#GH59734), (#GH132208)
481471
- Clang no longer crashes when trying to unify the types of arrays with
482472
certain differences in qualifiers (this could happen during template argument
483473
deduction or when building a ternary operator). (#GH97005)
484-
- Fixed type alias CTAD issues involving default template arguments. (#GH134471)
485474
- The initialization kind of elements of structured bindings
486475
direct-list-initialized from an array is corrected to direct-initialization.
487476
- Clang no longer crashes when a coroutine is declared ``[[noreturn]]``. (#GH127327)
@@ -497,10 +486,6 @@ Bug Fixes to C++ Support
497486
- Fixes matching of nested template template parameters. (#GH130362)
498487
- Correctly diagnoses template template paramters which have a pack parameter
499488
not in the last position.
500-
- Disallow overloading on struct vs class on dependent types, which is IFNDR, as
501-
this makes the problem diagnosable.
502-
- Improved preservation of the presence or abscence of typename specifier when
503-
printing types in diagnostics.
504489
- Clang now correctly parses ``if constexpr`` expressions in immediate function context. (#GH123524)
505490
- Fixed an assertion failure affecting code that uses C++23 "deducing this". (#GH130272)
506491
- Clang now properly instantiates destructors for initialized members within non-delegating constructors. (#GH93251)
@@ -575,9 +560,6 @@ Arm and AArch64 Support
575560

576561
- Support for __ptrauth type qualifier has been added.
577562

578-
- For AArch64, added support for generating executable-only code sections by using the
579-
``-mexecute-only`` or ``-mpure-code`` compiler flags. (#GH125688)
580-
581563
Android Support
582564
^^^^^^^^^^^^^^^
583565

@@ -667,6 +649,10 @@ Code Completion
667649

668650
Static Analyzer
669651
---------------
652+
- Fixed a crash when C++20 parenthesized initializer lists are used. This issue
653+
was causing a crash in clang-tidy. (#GH136041)
654+
655+
- Fixed a crash when C++20 parenthesized initializer lists are used. (#GH136041)
670656

671657
New features
672658
^^^^^^^^^^^^

clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,9 +379,9 @@ void DynamicTypePropagation::checkPostCall(const CallEvent &Call,
379379
// aggregates, and in such case no top-frame constructor will be called.
380380
// Figure out if we need to do anything in this case.
381381
// FIXME: Instead of relying on the ParentMap, we should have the
382-
// trigger-statement (InitListExpr in this case) available in this
383-
// callback, ideally as part of CallEvent.
384-
if (isa_and_nonnull<InitListExpr>(
382+
// trigger-statement (InitListExpr or CXXParenListInitExpr in this case)
383+
// available in this callback, ideally as part of CallEvent.
384+
if (isa_and_nonnull<InitListExpr, CXXParenListInitExpr>(
385385
LCtx->getParentMap().getParent(Ctor->getOriginExpr())))
386386
return;
387387

clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -644,9 +644,10 @@ void ExprEngine::handleConstructor(const Expr *E,
644644
// FIXME: For now this code essentially bails out. We need to find the
645645
// correct target region and set it.
646646
// FIXME: Instead of relying on the ParentMap, we should have the
647-
// trigger-statement (InitListExpr in this case) passed down from CFG or
648-
// otherwise always available during construction.
649-
if (isa_and_nonnull<InitListExpr>(LCtx->getParentMap().getParent(E))) {
647+
// trigger-statement (InitListExpr or CXXParenListInitExpr in this case)
648+
// passed down from CFG or otherwise always available during construction.
649+
if (isa_and_nonnull<InitListExpr, CXXParenListInitExpr>(
650+
LCtx->getParentMap().getParent(E))) {
650651
MemRegionManager &MRMgr = getSValBuilder().getRegionManager();
651652
Target = loc::MemRegionVal(MRMgr.getCXXTempObjectRegion(E, LCtx));
652653
CallOpts.IsCtorOrDtorWithImproperlyModeledTargetRegion = true;
@@ -1017,7 +1018,8 @@ void ExprEngine::VisitCXXNewExpr(const CXXNewExpr *CNE, ExplodedNode *Pred,
10171018
// values are properly placed inside the required region, however if an
10181019
// initializer list is used, this doesn't happen automatically.
10191020
auto *Init = CNE->getInitializer();
1020-
bool isInitList = isa_and_nonnull<InitListExpr>(Init);
1021+
bool isInitList =
1022+
isa_and_nonnull<InitListExpr, CXXParenListInitExpr>(Init);
10211023

10221024
QualType ObjTy =
10231025
isInitList ? Init->getType() : CNE->getType()->getPointeeType();

clang/test/Analysis/PR135665.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %clang_analyze_cc1 -std=c++20 -analyzer-checker=core -verify %s
2+
3+
// expected-no-diagnostics
4+
5+
template<typename... F>
6+
struct overload : public F...
7+
{
8+
using F::operator()...;
9+
};
10+
11+
template<typename... F>
12+
overload(F&&...) -> overload<F...>;
13+
14+
int main()
15+
{
16+
const auto l = overload([](const int* i) {});
17+
18+
return 0;
19+
}

0 commit comments

Comments
 (0)