[clang] 68f116a - PR47864: Fix assertion in pointer-to-member emission if there are

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 15 13:52:03 PDT 2020


Author: Richard Smith
Date: 2020-10-15T13:51:51-07:00
New Revision: 68f116aa23434b577743307c487b2edf037fca4c

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

LOG: PR47864: Fix assertion in pointer-to-member emission if there are
multiple declarations of the same base class.

Added: 
    

Modified: 
    clang/include/clang/AST/RecordLayout.h
    clang/test/CodeGenCXX/pointers-to-data-members.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/AST/RecordLayout.h b/clang/include/clang/AST/RecordLayout.h
index 946fbd8f4ce2..dd18f9c49f84 100644
--- a/clang/include/clang/AST/RecordLayout.h
+++ b/clang/include/clang/AST/RecordLayout.h
@@ -248,6 +248,8 @@ class ASTRecordLayout {
   /// getBaseClassOffset - Get the offset, in chars, for the given base class.
   CharUnits getBaseClassOffset(const CXXRecordDecl *Base) const {
     assert(CXXInfo && "Record layout does not have C++ specific info!");
+
+    Base = Base->getDefinition();
     assert(CXXInfo->BaseOffsets.count(Base) && "Did not find base!");
 
     return CXXInfo->BaseOffsets[Base];
@@ -256,6 +258,8 @@ class ASTRecordLayout {
   /// getVBaseClassOffset - Get the offset, in chars, for the given base class.
   CharUnits getVBaseClassOffset(const CXXRecordDecl *VBase) const {
     assert(CXXInfo && "Record layout does not have C++ specific info!");
+
+    VBase = VBase->getDefinition();
     assert(CXXInfo->VBaseOffsets.count(VBase) && "Did not find base!");
 
     return CXXInfo->VBaseOffsets[VBase].VBaseOffset;

diff  --git a/clang/test/CodeGenCXX/pointers-to-data-members.cpp b/clang/test/CodeGenCXX/pointers-to-data-members.cpp
index f975035d0318..b08cdcc52c5b 100644
--- a/clang/test/CodeGenCXX/pointers-to-data-members.cpp
+++ b/clang/test/CodeGenCXX/pointers-to-data-members.cpp
@@ -258,3 +258,10 @@ union U {
 U u;
 // CHECK-GLOBAL: @_ZN11IndirectPDM1uE = global %"union.IndirectPDM::U" { %union.anon { i64 -1 } }, align 8
 }
+
+namespace PR47864 {
+  struct B;
+  struct B {};
+  struct D : B { int m; };
+  auto x = (int B::*)&D::m;
+}


        


More information about the cfe-commits mailing list