This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Don't infinite loop in SemaSourceWithPriorities::CompleteType when trying to complete a forward decl
ClosedPublic

Authored by teemperor on Sep 8 2020, 8:19 AM.

Details

Summary

SemaSourceWithPriorities is a special SemaSource that wraps our normal LLDB ExternalASTSource and
the ASTReader (which is used for the C++ module loading). It's only active when the import-std-module
setting is turned on.

The CompleteType function there in SemaSourceWithPriorities is looping over all ExternalASTSources and
asks each to complete the type. However, that loop is in another loop that keeps doing that until the type is
complete. If that function is ever called on a type that is a forward decl then that causes LLDB to go into an
infinite loop.

I remember I added that second loop and the comment because I thought I saw a similar pattern in some other Clang
code, but after some grepping I can't find that code anywhere and it seems the rest of the code base only calls
CompleteType once (It would also be kinda silly to have calling it multiple times). So it seems that's just a silly mistake.

The is implicitly tested by importing std::pair, but I also added a simpler dedicated test that creates a dummy
libc++ module with some forward declarations and then imports them into the scratch AST context. At some point
the ASTImporter will check if one of the forward decls could be completed by the ExternalASTSource, which will cause the
SemaSourceWithPriorities to go into an infinite loop once it receives the CompleteType call.

Diff Detail

Event Timeline

teemperor requested review of this revision.Sep 8 2020, 8:19 AM
teemperor updated this revision to Diff 290492.
teemperor created this revision.
  • Upload correct diff.
shafik accepted this revision.Sep 8 2020, 1:46 PM

LGTM

This revision is now accepted and ready to land.Sep 8 2020, 1:46 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 9 2020, 1:06 AM