This is an archive of the discontinued LLVM Phabricator instance.

[lldb][NFC] Desugar certain expression result types to strip references to C++ module declarations
AbandonedPublic

Authored by teemperor on Aug 10 2020, 12:18 PM.

Details

Reviewers
shafik
aprantl
Summary

With the activated C++ module prototype LLDB currently runs into the issue that certain expressions
return declarations that are requiring a lot of importing and merging work from ClangASTImporter/ASTImporter.
For example unordered_map_var.size() has a return type of std::unordered_map<Key, Val>::size_type which
would require importing std::unordered_map<Key, Val> and all the declarations that it references.

Importing all these AST nodes is causing frequent crashes in LLDB when we end up failing to import/merge
some of the declarations or the generated AST isn't fully correct. So far we worked around this in the tests by
casting all expressions to some underlying type, but until we fix all the underlying we probably have to do
this automatically for the user to make this less frustrating to use (and the tests less tedious to write).

This patch automatically desugars the return types of expressions step-by-step until we reach a type that
no longer requires us to import any template. The current criteria is that we keep desugaring until we reach
a typedef'd type where the typedef is no longer inside a C++ module template/class. This means that things
like container.size() now return size_t instead of the std::container<T>::size_t types we get so far.
Also the patch removes all the now obsolete casts from the tests which are now done automatically.

The real solution to the problem is obviously to actually fix all the underlying bugs that cause us to assert/crash
when we import those declarations. This will be done on the side and this function is will whitelist more and
more declarations over time while I try to get the different STL declarations working (see for example D85141)

Diff Detail

Event Timeline

teemperor created this revision.Aug 10 2020, 12:18 PM
aprantl accepted this revision.Aug 12 2020, 4:49 PM
aprantl added inline comments.
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
224

Maybe for (;!decl_context->isTranslationUnit()); decl_context = decl_context->getParent()) {

225

and then

Decl *d = dyn_cast<Decl>(decl_context);
if (!d) 
  continue;
This revision is now accepted and ready to land.Aug 12 2020, 4:49 PM
teemperor abandoned this revision.Feb 25 2021, 1:36 AM

The ASTImporter is fixed enough by now that this isn't necessary anymore. Closing