[clang] [clang][bytecode] Fix comparing `TemplateParamObjectDecl`s (PR #208734)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 10 07:41:05 PDT 2026
https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/208734
>From 522713f0fcd6a6a75df17ce72a581339fd6a709e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
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
More information about the cfe-commits
mailing list