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

 1) When creating the global variables for them,  always use the first decl
 2) When converting null pointers to `APValue`, don't cast the nullptr base to 
`Expr` or `ValueDecl`. Use `LValueBase()` instead, so the internal 
`PointerUnion` has an all-zeros value as `getOpaqueValue()`. If we don't do 
this, we run into problems with merging of `TemplateParamObjectDecls` because 
they don't compare equal via `::Profile()`.

>From 522713f0fcd6a6a75df17ce72a581339fd6a709e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]>
Date: Fri, 10 Jul 2026 16:10:54 +0200
Subject: [PATCH] [clang][bytecode]

---
 clang/lib/AST/ByteCode/Compiler.cpp    | 7 +++++--
 clang/lib/AST/ByteCode/Pointer.cpp     | 2 +-
 clang/test/PCH/cxx20-template-args.cpp | 1 +
 3 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 46762ed8291f9..c581e9e4a188f 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -8064,11 +8064,14 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl 
*D, const Expr *E) {
     return F && this->emitGetFnPtr(F, E);
   }
   if (const auto *TPOD = dyn_cast<TemplateParamObjectDecl>(D)) {
+    TPOD = TPOD->getFirstDecl();
     if (DiscardResult)
       return true;
+    if (UnsignedOrNone GlobalIndex = P.getGlobal(TPOD))
+      return this->emitGetPtrGlobal(*GlobalIndex, E);
 
-    if (UnsignedOrNone Index = P.getOrCreateGlobal(D)) {
-      if (OptPrimType T = classify(D->getType())) {
+    if (UnsignedOrNone Index = P.getOrCreateGlobal(TPOD)) {
+      if (OptPrimType T = classify(TPOD->getType())) {
         if (!this->visitAPValue(TPOD->getValue(), *T, E))
           return false;
         return this->emitInitGlobal(*T, *Index, E);
diff --git a/clang/lib/AST/ByteCode/Pointer.cpp 
b/clang/lib/AST/ByteCode/Pointer.cpp
index 6d19379d6ecd7..43af58d7bcb83 100644
--- a/clang/lib/AST/ByteCode/Pointer.cpp
+++ b/clang/lib/AST/ByteCode/Pointer.cpp
@@ -174,7 +174,7 @@ APValue Pointer::toAPValue(const ASTContext &ASTCtx) const {
   llvm::SmallVector<APValue::LValuePathEntry, 5> Path;
 
   if (isZero())
-    return APValue(static_cast<const Expr *>(nullptr), CharUnits::Zero(), Path,
+    return APValue(APValue::LValueBase(), CharUnits::Zero(), Path,
                    /*IsOnePastEnd=*/false, /*IsNullPtr=*/true);
   if (isIntegralPointer())
     return APValue(static_cast<const Expr *>(nullptr),
diff --git a/clang/test/PCH/cxx20-template-args.cpp 
b/clang/test/PCH/cxx20-template-args.cpp
index f9ac35ba53a45..5bb816fcbaf09 100644
--- a/clang/test/PCH/cxx20-template-args.cpp
+++ b/clang/test/PCH/cxx20-template-args.cpp
@@ -2,6 +2,7 @@
 
 // RUN: %clang_cc1 -std=c++20 -emit-pch %s -o %t
 // RUN: %clang_cc1 -std=c++20 -include-pch %t -verify %s
+// RUN: %clang_cc1 -std=c++20 -include-pch %t -verify %s 
-fexperimental-new-constant-interpreter
 
 // expected-no-diagnostics
 

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

Reply via email to