https://github.com/philnik777 created 
https://github.com/llvm/llvm-project/pull/155218

When initializing an anonymous struct via an `IndirectFieldDecl`, we
create an `APValue` for the struct, but we leave the fields
uninitialized. This would later cause the `CXXConstructExpr` that
initializes the anonymous struct member to not do anything since its
`APValue` already had a value (but the member didn't). Just remove the
check for an `APValue` that already has a value from
`RecordExprEvaluator::VisitCXXConstructExpr()`.

Fixes #154567


>From 02008620c2972d348324fd0b908b36e525bf39d2 Mon Sep 17 00:00:00 2001
From: Timm Baeder <tbae...@redhat.com>
Date: Sat, 23 Aug 2025 08:01:48 +0200
Subject: [PATCH] [clang] Remove hasValue() check in
 `RecordExprEvaluator::VisitCXXConstructExpr()` (#154610)

When initializing an anonymous struct via an `IndirectFieldDecl`, we
create an `APValue` for the struct, but we leave the fields
uninitialized. This would later cause the `CXXConstructExpr` that
initializes the anonymous struct member to not do anything since its
`APValue` already had a value (but the member didn't). Just remove the
check for an `APValue` that already has a value from
`RecordExprEvaluator::VisitCXXConstructExpr()`.

Fixes #154567
---
 clang/lib/AST/ExprConstant.cpp                   |  4 ----
 clang/test/SemaCXX/constant-expression-cxx11.cpp | 16 ++++++++++++++++
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 0733f8e8a33b0..170da16a0cdf8 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -10932,10 +10932,6 @@ bool RecordExprEvaluator::VisitCXXConstructExpr(const 
CXXConstructExpr *E,
 
   bool ZeroInit = E->requiresZeroInitialization();
   if (CheckTrivialDefaultConstructor(Info, E->getExprLoc(), FD, ZeroInit)) {
-    // If we've already performed zero-initialization, we're already done.
-    if (Result.hasValue())
-      return true;
-
     if (ZeroInit)
       return ZeroInitialization(E, T);
 
diff --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp 
b/clang/test/SemaCXX/constant-expression-cxx11.cpp
index c390fee1c38d9..935409131e18f 100644
--- a/clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -2615,3 +2615,19 @@ namespace DoubleCapture {
     };
   }
 }
+
+namespace GH154567 {
+  struct T {
+    int i;
+  };
+
+  struct S {
+    struct { // expected-warning {{GNU extension}}
+      T val;
+    };
+    constexpr S() : val() {}
+  };
+
+  constexpr S s{};
+  static_assert(s.val.i == 0, "");
+}

_______________________________________________
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to