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

... if the bytecode interpreter is in use. This is similar to 
https://github.com/llvm/llvm-project/pull/198062.
With `-ast-import`, every `ASTUnit` has its own `ASTContext`. When that context 
is destroyed, so is the `interp::Context`.
Evaluate the initializer in the context we're importing to.

>From 457db862e15904176204bc46220023d56ed289f9 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/ASTImporter.cpp                            | 9 ++++++++-
 clang/test/ASTMerge/class-template-partial-spec/test.cpp | 4 ++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index d1de2dbac2a0e..0ace8e7c6c299 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -4897,8 +4897,15 @@ ExpectedDecl ASTNodeImporter::VisitVarDecl(VarDecl *D) {
   if (Error Err = ImportInitializer(D, ToVar))
     return std::move(Err);
 
-  if (D->isConstexpr())
+  if (D->isConstexpr()) {
     ToVar->setConstexpr(true);
+    // Tell the bytecode interpreter that a new constexpr variable has 
appeared.
+    if (ToVar->getASTContext().getLangOpts().EnableNewConstInterp) {
+      if (const Expr *Init = ToVar->getInit();
+          Init && !Init->isValueDependent())
+        ToVar->evaluateValue();
+    }
+  }
 
   addDeclToContexts(D, ToVar);
 
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