https://github.com/efriedma-quic updated https://github.com/llvm/llvm-project/pull/148030
>From 5c279209bff277e008866e5d5e5192cf99cdcf8d Mon Sep 17 00:00:00 2001 From: Eli Friedman <efrie...@quicinc.com> Date: Thu, 10 Jul 2025 11:37:50 -0700 Subject: [PATCH 1/2] [clang] Fix isConstantInitializer handling of transparent init lists. Transparent InitListExprs have different semantics, so special-case them in Expr::isConstantInitializer. We probably should move away from isConstantInitializer, in favor of relying more directly on constant evaluation, but this is an easy fix. Fixes #147949 --- clang/lib/AST/Expr.cpp | 4 ++++ clang/test/CodeGenCXX/const-init-cxx11.cpp | 9 +++++++++ clang/test/SemaCXX/compound-literal.cpp | 8 ++++++++ 3 files changed, 21 insertions(+) diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index 36fd5ee271e03..2e1a9a3d9ad63 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -3393,6 +3393,10 @@ bool Expr::isConstantInitializer(ASTContext &Ctx, bool IsForRef, // an anonymous union, in declaration order. const InitListExpr *ILE = cast<InitListExpr>(this); assert(ILE->isSemanticForm() && "InitListExpr must be in semantic form"); + + if (ILE->isTransparent()) + return ILE->getInit(0)->isConstantInitializer(Ctx, false, Culprit); + if (ILE->getType()->isArrayType()) { unsigned numInits = ILE->getNumInits(); for (unsigned i = 0; i < numInits; i++) { diff --git a/clang/test/CodeGenCXX/const-init-cxx11.cpp b/clang/test/CodeGenCXX/const-init-cxx11.cpp index 7c92af0def527..0795fb534af4b 100644 --- a/clang/test/CodeGenCXX/const-init-cxx11.cpp +++ b/clang/test/CodeGenCXX/const-init-cxx11.cpp @@ -638,6 +638,15 @@ struct PR69979 { const char (&d)[9]; } e {"12345678"}; +namespace GH147949 { + struct Coordinate {}; + Coordinate Make(); + void TestBody() { + // CHECK: call {{.*}} @_ZN8GH1479494MakeEv + const Coordinate x{Make()}; + } +} + // VirtualMembers::TemplateClass::templateMethod() must be defined in this TU, // not just declared. // CHECK: define linkonce_odr void @_ZN14VirtualMembers13TemplateClassIiE14templateMethodEv(ptr {{[^,]*}} %this) diff --git a/clang/test/SemaCXX/compound-literal.cpp b/clang/test/SemaCXX/compound-literal.cpp index a62e4f79b5a07..9c7c606838de9 100644 --- a/clang/test/SemaCXX/compound-literal.cpp +++ b/clang/test/SemaCXX/compound-literal.cpp @@ -129,3 +129,11 @@ int f(); #endif Foo o = (Foo){ {}, 1, f() }; } + +#if __cplusplus >= 201103L +namespace GH147949 { + // Make sure we handle transparent InitListExprs correctly. + struct S { int x : 3; }; + const S* x = (const S[]){S{S{3}}}; +} +#endif >From dc1805eb7118f6b6994cb0239519266193c13cf0 Mon Sep 17 00:00:00 2001 From: Eli Friedman <efrie...@quicinc.com> Date: Fri, 11 Jul 2025 15:28:48 -0700 Subject: [PATCH 2/2] Add relnote. --- clang/docs/ReleaseNotes.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 8b4f9229c4463..8e1200bd5b7b5 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -923,6 +923,8 @@ Bug Fixes to C++ Support - Improved handling of variables with ``consteval`` constructors, to consistently treat the initializer as manifestly constant-evaluated. (#GH135281) +- Fixed a crash involving list-initialization of an empty class with a + non-empty initializer list. (#GH147949) Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits