[cfe-dev] Completing CXXRecordDecls when .bases() is called.

Lang Hames via cfe-dev cfe-dev at lists.llvm.org
Fri Jul 28 18:23:46 PDT 2017


Hi Cfe-dev, Richard,

I've run into a test case in LLDB where we crash evaluating an expression
in the following program:

class Foo {};
class Bar : public Foo {};

class Base {
public:
  virtual Foo* baz() { return nullptr; }
};

class Derived : public Base {
public:
  Bar* baz() override { return nullptr; }
};

int main() {
  Derived d;
  Base *b = *d;
  b->baz(); // Break here and eval 'd.baz()' to crash.
  return 0;
}

LLDB is crashing in IRGen when we call the CXXRecordDecl::bases() method
for the Bar class. (I think this is being called to determine whether we
need to fix up the pointer returned from Derived::baz()). Because the
CXXRecordDecl for Bar is generated by DWARFASTParserClang as a minimal,
lazily completed decl (and is then imported into a different context for
good measure), and because no other operations on Bar force it to be
completed, it's still incomplete when we call bases(). In particular, the
DerivedData field is still null: it's the access to this field that causes
the crash.

I don't grok the model for lazy decl completion/import well enough to know
exactly how to proceed (Is there a good source explaining it?). I know that
some operations on a Decl will cause that Decl to be completed
automatically. Should calling 'bases()' also trigger completion? Or should
that be the responsibility of callers of bases()? (I tested forcing
completion in CXXBasePaths::lookupInBases(…) and that fixed my issue, but
it's not clear to me that that's the Right Thing to do here).

Cheers,
Lang.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170728/4948c376/attachment.html>


More information about the cfe-dev mailing list