https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/201000
I think this should work. >From 0f7f733e99bc102cb3bf19da074cfae3ef0959d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]> Date: Tue, 2 Jun 2026 06:09:28 +0200 Subject: [PATCH] [clang][ExprConst] Support DesignatedInitUpdateExpr of array type I think this should work. --- clang/lib/AST/ByteCode/Compiler.cpp | 1 - clang/lib/AST/ExprConstant.cpp | 8 ++++++++ clang/test/Sema/constexpr.c | 8 ++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index 732a9e227430c..7b5b6ce368dca 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -7834,7 +7834,6 @@ bool Compiler<Emitter>::VisitDeclRefExpr(const DeclRefExpr *E) { template <class Emitter> bool Compiler<Emitter>::VisitDesignatedInitUpdateExpr( const DesignatedInitUpdateExpr *E) { - assert(E->getType()->isRecordType()); if (!this->visitInitializer(E->getBase())) return false; return this->visitInitializer(E->getUpdater()); diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 7601d68b13939..f78854d15a9f2 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -15024,6 +15024,7 @@ namespace { ArrayRef<Expr *> Args, const Expr *ArrayFiller, QualType AllocType = QualType()); + bool VisitDesignatedInitUpdateExpr(const DesignatedInitUpdateExpr *E); }; } // end anonymous namespace @@ -15411,6 +15412,13 @@ bool ArrayExprEvaluator::VisitCXXParenListInitExpr( E->getArrayFiller()); } +bool ArrayExprEvaluator::VisitDesignatedInitUpdateExpr( + const DesignatedInitUpdateExpr *E) { + if (!Visit(E->getBase())) + return false; + return Visit(E->getUpdater()); +} + //===----------------------------------------------------------------------===// // Integer Evaluation // diff --git a/clang/test/Sema/constexpr.c b/clang/test/Sema/constexpr.c index cf029446bd362..51ee62d2495f3 100644 --- a/clang/test/Sema/constexpr.c +++ b/clang/test/Sema/constexpr.c @@ -446,3 +446,11 @@ static_assert(designated_init_b.a.d == 12.0); // expected-warning {{folding it t static_assert(designated_init_b.a.e[0] == 5); // expected-warning {{folding it to a constant is a GNU extension}} static_assert(designated_init_b.a.e[1] == 13); // expected-warning {{folding it to a constant is a GNU extension}} static_assert(designated_init_b.y == 14); + +struct S2 { + char L[4]; + int M; +}; +const struct S2 s2[2] = {{{"foo"}, 1}, [0].L[2] = 'x'}; // expected-warning {{initializer partially overrides prior initialization of this subobject}} \ + // expected-note {{previous initialization is here}} +static_assert(s2[0].L[2] == 'x');// expected-warning {{folding it to a constant is a GNU extension}} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
