https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/208794

>From 91a735792ea26dd7b569a07c33e5076d5d6c3170 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]>
Date: Fri, 10 Jul 2026 19:43:39 +0200
Subject: [PATCH] [clang][import] Evaluate constexpr variable initialzers

... if the bytecode interpreter is in use. This is similar to
https://github.com/llvm/llvm-project/pull/198062.
---
 clang/lib/AST/ByteCode/Compiler.cpp                      | 8 ++++++--
 clang/test/ASTMerge/class-template-partial-spec/test.cpp | 4 ++++
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index d7bdb2f217a9a..a2a3516ac3d78 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -2920,8 +2920,12 @@ bool Compiler<Emitter>::VisitMemberExpr(const MemberExpr 
*E) {
     return this->discard(Base);
 
   if (const auto *VD = dyn_cast<VarDecl>(Member)) {
-    // I am almost confident in saying that a var decl must be static
-    // and therefore registered as a global variable.
+    // If the member is a VarDecl, this is a static variable.
+    // We need to try to lazily evaluate its initializer here since the
+    // variable might've been deserialized and not registered
+    // as a global variable yet.
+    if (VD->getInit() && !VD->getInit()->isValueDependent())
+      VD->evaluateValue();
     if (auto GlobalIndex = P.getGlobal(VD)) {
       if (!this->emitGetPtrGlobal(*GlobalIndex, E))
         return false;
diff --git a/clang/test/ASTMerge/class-template-partial-spec/test.cpp 
b/clang/test/ASTMerge/class-template-partial-spec/test.cpp
index 6ab5ed5a7d5fb..6f2191d048455 100644
--- a/clang/test/ASTMerge/class-template-partial-spec/test.cpp
+++ b/clang/test/ASTMerge/class-template-partial-spec/test.cpp
@@ -2,6 +2,10 @@
 // RUN: %clang_cc1 -emit-pch -std=c++1z -o %t.2.ast 
%S/Inputs/class-template-partial-spec2.cpp
 // RUN: %clang_cc1 -std=c++1z -ast-merge %t.1.ast -ast-merge %t.2.ast 
-fsyntax-only %s 2>&1 | FileCheck %s
 
+// RUN: %clang_cc1 -emit-pch -std=c++1z -o %t.1.ast 
%S/Inputs/class-template-partial-spec1.cpp 
-fexperimental-new-constant-interpreter
+// RUN: %clang_cc1 -emit-pch -std=c++1z -o %t.2.ast 
%S/Inputs/class-template-partial-spec2.cpp 
-fexperimental-new-constant-interpreter
+// RUN: %clang_cc1 -std=c++1z -ast-merge %t.1.ast -ast-merge %t.2.ast 
-fsyntax-only %s 2>&1 -fexperimental-new-constant-interpreter | FileCheck %s
+
 static_assert(sizeof(**SingleSource.member) == sizeof(**SingleDest.member));
 static_assert(sizeof(SecondDoubleSource.member) == 
sizeof(SecondDoubleDest.member));
 static_assert(NumberSource.val == 42);

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to