This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Fix crash-bug in preamble indexing when using modules.
ClosedPublic

Authored by adamcz on Aug 13 2020, 12:11 PM.

Details

Summary

When preamble contains #undef, indexing code finds the matching #define
and uses that during indexing. However, it would only look for local
definitions. If the macro was defined in a module, MacroInfo
would be nullptr and clangd would crash.

This change makes clangd ignore any #undef without a matching #define
inside the same TU.

The indexing of macros happens for preamble only, so then #undef must be
in the preamble, which is why we need two .h files in a test.

Note that clangd is currently not ready for module support, but this
brings us one step closer.

This was previously attempted in
4061d9e42cff621462931ac7df9666806c77a237, but had to be reverted due to
broken test. This version fixes that test-only bug by setting a custom module
cache path to avoid re-use of modules across test invocations.

Diff Detail

Event Timeline

adamcz created this revision.Aug 13 2020, 12:11 PM
adamcz requested review of this revision.Aug 13 2020, 12:11 PM
This revision was not accepted when it landed; it landed in state Needs Review.Aug 20 2020, 5:33 AM
This revision was automatically updated to reflect the committed changes.
sammccall added inline comments.Aug 20 2020, 5:48 AM
clang-tools-extra/clangd/unittests/TestTU.cpp
77

errs should probably go away

96

or just [&]{ deleteModuleCache(...); } - bind isn't unreadable here, but we use it so rarely that it almost feels obscure :-)