[cfe-dev] clang::Modules and duplicate definitions of base CXXRecordDecls

Axel Naumann Axel.Naumann at cern.ch
Tue Oct 2 08:38:34 PDT 2012


Hi,

clang::Modules attach definitions of CXXRecordDecls to the redecl chain,
updating the Definition* of the CXXRecordDecl::DefinitionData. If I read
a derived class's decl, its CXXMethodDecls will read the overridden
methods - those of the base CXXRecordDecl that existed at the time of
reading the derived class. If the ASTReader then reads a new instance of
the base class, the check:

AST/VTableBuilder.cpp:1419 FindNearestOverriddenMethod():
      // We found our overridden method.
      if (OverriddenMD->getParent() == PrimaryBase)
        return OverriddenMD;

fails, because the OverriddenMD is from the old base, but PrimaryBase is
the one read later. Thus the vtable index gets miscalculated. Changing
this to
      // We found our overridden method.
      if (OverriddenMD->getParent()->getCanonicalDecl()
          == PrimaryBase->getCanonicalDecl())
        return OverriddenMD;
works around it.

I'd of course like to fix this in ASTReader, but I'd have to fix the
*derived* classes' overridden methods when reading the *base*. I have a
similar issue with the derived class's
ASTRecordLayout::getBaseClassOffset() not finding the base because the
map uses the old base decl as the key.

Alternatively we could refuse to add dupe definitions to the AST in the
ASTReader, but that's a revolution that I'm afraid of :-)

What are your recommendations? How could we fix that?

Cheers, Axel.



More information about the cfe-dev mailing list