Author: Erich Keane
Date: 2026-09-22T07:28:44-07:00
New Revision: 1baa43495862650e0d03780d565b8e09d57b3495

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

LOG: [CIR] Correct how memberPath compares 'current class' (#225237)

I didn't realize in the past that `isSameEntity` didn't actually check
to make sure we were working on canonical/most recent decl, so this
patch adds those to each side of the check. If we don't, we end up
finding them not equal, and crashing later when trying to pick up the
correct index.

Added: 
    

Modified: 
    clang/lib/CIR/CodeGen/CIRGenModule.cpp
    clang/test/CIR/CodeGen/class.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp 
b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
index 16adb742caa8b..785ca633a0aac 100644
--- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
@@ -2486,7 +2486,8 @@ bool CIRGenModule::findFieldMemberPath(const 
CXXRecordDecl *currentClass,
       getTypes().getCIRGenRecordLayout(currentClass);
 
   // The field is declared directly in this class.
-  if (astContext.isSameEntity(field->getParent(), currentClass)) {
+  if (astContext.isSameEntity(field->getParent()->getMostRecentDecl(),
+                              currentClass->getMostRecentDecl())) {
     int32_t fieldIdx;
     if (currentClass->isUnion()) {
       // For unions, getCIRFieldNo always returns 0 for every union member (all

diff  --git a/clang/test/CIR/CodeGen/class.cpp 
b/clang/test/CIR/CodeGen/class.cpp
index 267983a015723..b04899feb29ff 100644
--- a/clang/test/CIR/CodeGen/class.cpp
+++ b/clang/test/CIR/CodeGen/class.cpp
@@ -119,3 +119,20 @@ void use_empty_derived2() {
 // OGCG: define{{.*}} void @_Z18use_empty_derived2v
 // OGCG:   alloca %struct.EmptyDerived2
 // OGCG:   ret void
+
+// Makes sure these are the same 
+template <class T> struct Template {
+  int m;
+};
+extern template struct Template<char>;
+template struct Template<char>;
+void takesTemplate(int Template<char>::*);
+void usesTemplate() { takesTemplate(&Template<char>::m); }
+// CIR: cir.func{{.*}} @_Z12usesTemplatev
+// CIR: cir.call @_Z13takesTemplateM8TemplateIcEi(
+
+// LLVM: define dso_local void @_Z12usesTemplatev
+// LLVM: call void @_Z13takesTemplateM8TemplateIcEi(
+
+// OGCG: define dso_local void @_Z12usesTemplatev
+// OGCG: call void @_Z13takesTemplateM8TemplateIcEi(


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

Reply via email to