Author: Timm Baeder
Date: 2026-07-12T10:31:02+02:00
New Revision: e62c0cb076fbcb70752530571726944648a48829

URL: 
https://github.com/llvm/llvm-project/commit/e62c0cb076fbcb70752530571726944648a48829
DIFF: 
https://github.com/llvm/llvm-project/commit/e62c0cb076fbcb70752530571726944648a48829.diff

LOG: [clang][bytecode] Fix comparing `TemplateParamObjectDecl`s (#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()`.

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/Compiler.cpp
    clang/lib/AST/ByteCode/Pointer.cpp
    clang/test/PCH/cxx20-template-args.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 869d3a8767617..a50980d23d3b2 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -8106,11 +8106,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