Author: Timm Baeder
Date: 2026-07-10T13:08:24+02:00
New Revision: 41a35a7d99604174c442c975ef1472498a47e643

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

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

Use the first decl to compare.

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/MemberPointer.cpp
    clang/test/Modules/templates.mm

Removed: 
    


################################################################################
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;


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

Reply via email to