[clang] [clang][bytecode] Fix comparing member pointers for redeclared `FieldDecl`s (PR #208660)

Timm Baeder via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 10 02:18:35 PDT 2026


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

>From be10669f3a7482967e76a20e51c02474ec0487b6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Fri, 10 Jul 2026 10:35:14 +0200
Subject: [PATCH] asdf

---
 clang/lib/AST/ByteCode/MemberPointer.cpp | 14 +++++++++++++-
 clang/test/Modules/templates.mm          |  3 +++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/clang/lib/AST/ByteCode/MemberPointer.cpp b/clang/lib/AST/ByteCode/MemberPointer.cpp
index f0c1fe5930261..bccadc4d4fc8f 100644
--- a/clang/lib/AST/ByteCode/MemberPointer.cpp
+++ b/clang/lib/AST/ByteCode/MemberPointer.cpp
@@ -89,8 +89,20 @@ APValue MemberPointer::toAPValue(const ASTContext &ASTCtx) const {
 
 ComparisonCategoryResult
 MemberPointer::compare(const MemberPointer &RHS) const {
-  if (this->getDecl() == RHS.getDecl()) {
+  assert(!isZero());
+  assert(!RHS.isZero());
 
+  const auto getCmpDecl = [](const MemberPointer &P) -> const Decl * {
+    const Decl *D = P.getDecl()->getMostRecentDecl();
+    if (const auto *FD = dyn_cast<FieldDecl>(D))
+      D = FD->getFirstDecl();
+    return D;
+  };
+
+  const Decl *LHSCmpDecl = getCmpDecl(*this);
+  const Decl *RHSCmpDecl = getCmpDecl(RHS);
+
+  if (LHSCmpDecl == RHSCmpDecl) {
     if (this->PathLength != RHS.PathLength)
       return ComparisonCategoryResult::Unordered;
 
diff --git a/clang/test/Modules/templates.mm b/clang/test/Modules/templates.mm
index 610de099d398d..567717491eb87 100644
--- a/clang/test/Modules/templates.mm
+++ b/clang/test/Modules/templates.mm
@@ -1,6 +1,9 @@
 // RUN: rm -rf %t
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++11 -x objective-c++ -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs -verify %s -Wno-objc-root-class
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++11 -x objective-c++ -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs -emit-llvm %s -o - -Wno-objc-root-class | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++11 -x objective-c++ -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs -verify %s -Wno-objc-root-class -fexperimental-new-constant-interpreter
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++11 -x objective-c++ -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs -emit-llvm %s -o - -Wno-objc-root-class -fexperimental-new-constant-interpreter | FileCheck %s
+
 // expected-no-diagnostics
 // REQUIRES: x86-registered-target
 @import templates_left;



More information about the cfe-commits mailing list