This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Add a test for how we lazily create Clang AST nodes
ClosedPublic

Authored by teemperor on Dec 5 2019, 4:59 AM.

Details

Summary

One of the ways we try to make LLDB faster is by only creating the Clang declarations (and loading the associated types)
when we actually need them for something. For example an evaluated expression might need to load types to
type check and codegen the expression.

Currently this mechanism isn't really tested, so we currently have no way to know how many Clang nodes we load and
when we load them. In general there seems to be some confusion when and why certain Clang nodes are created.
As we are about to make some changes to the code which is creating Clang AST nodes we probably should have
a test that at least checks that the current behaviour doesn't change. It also serves as some kind of documentation
on the current behaviour.

The test in this patch is just evaluating some expressions and checks which Clang nodes are created due to this in the
module AST. The check happens by looking at the AST dump of the current module and then scanning it for the
declarations we are looking for.

I'm aware that there are things missing in this test (inheritance, template parameters, non-expression evaluation commands)
but I'll expand it in follow up patches.

Also this test found two potential bugs in LLDB which are documented near the respective asserts in the test:

  1. LLDB seems to always load all types of local variables even when we don't reference them in the expression. We had patches

that tried to prevent this but it seems that didn't work as well as it should have (even though we don't complete these
types).

  1. We always seem to complete the first field of any record we run into. This has the funny side effect that LLDB is faster when

all classes in a project have an arbitrary char unused; as their first member. We probably want to fix this.

Diff Detail

Event Timeline

teemperor created this revision.Dec 5 2019, 4:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 5 2019, 4:59 AM
teemperor updated this revision to Diff 232768.Dec 9 2019, 12:58 AM
  • Add this to DWARF testing category. The types we load depends partly on the debug information so this set of tests is only testing the way we build the AST with DWARF.
This revision was not accepted when it landed; it landed in state Needs Review.Dec 9 2019, 1:01 AM
This revision was automatically updated to reflect the committed changes.