This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Make TypeSystemClang work with redeclarations
AcceptedPublic

Authored by teemperor on Nov 9 2021, 3:52 PM.

Details

Reviewers
aprantl
Summary

This patch is a part of D101950 which makes LLDB use redeclarations in its internal clang ASTs.

This patch does the following:

  1. Add an API that allows redeclaring a declaration inside a TypeSystemClang.
  2. Make the TypeSystemClang APIs work with redeclarations. Mainly making sure we look at redeclarations of DeclContext (see the added calls to getPrimaryContext which for example finds the definition of a class. See also the test for nested types)
  3. Removes code that assumes a 1-1 mapping between Type and Decl (which is no longer true for redeclarations). The biggest offender here are the APIs for creating classes/templates/etc. as they return all CompilerType (which doesn't identify a unique Decl, but only a redeclaration chain).
  4. Removed code that tries to eagerly create types for declarations. Types should be created via GetTypeForDecl so that existing types from forward declarations are reused. Otherwise we end up with

The patch also makes that we store the TemplateParameterInfos for template specializations
in the TypeSystemClang. The only reason for this is that Clang is using a different data
structure for storing this info internally so we can't just reuse the information from the
forward declaration when creating the redeclaration (see CreateRedeclaration). This
can be removed once we updated the DWARF parser and the TypeSystemClang APIs
to accept the information as we can find it in the Clang AST.

This shouldn't affect LLDB's functionality on its own as the DWARF parser currently doesn't
create redeclarations. That's why all the tests are unit tests.

The added logic for looking for the right redeclaration should work as before in ASTs that only
have single-decl redeclaration chains (which is what we currently do).

Diff Detail

Event Timeline

teemperor created this revision.Nov 9 2021, 3:52 PM
teemperor requested review of this revision.Nov 9 2021, 3:52 PM

Note that the changed Dump method and the dump method that takes an ExecutionContext are not tested as we can't test those things via unit tests. They can only be tested with an updated DWARF parser on a real executable/process.

teemperor updated this revision to Diff 386109.Nov 10 2021, 3:25 AM
  • Clang-format some last minute renames
aprantl accepted this revision.Nov 10 2021, 11:12 AM
This revision is now accepted and ready to land.Nov 10 2021, 11:12 AM