[clangd] Fix crash-bug in preamble indexing when using modules.
authorAdam Czachorowski <adamcz@google.com>
Thu, 13 Aug 2020 15:24:22 +0000 (17:24 +0200)
committerAdam Czachorowski <adamcz@google.com>
Thu, 20 Aug 2020 12:19:52 +0000 (14:19 +0200)
commit53b9199a5cdba8a6e294e1fb183f308ec558db22
tree428a61274b78bf18181c6f1d0a5ae1040946d1b9
parent0ee23b286ac48662b5e576fb837efa5564bc0578
[clangd] Fix crash-bug in preamble indexing when using modules.

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.

Differential Revision: https://reviews.llvm.org/D85923
clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
clang-tools-extra/clangd/unittests/TestFS.h
clang-tools-extra/clangd/unittests/TestTU.cpp
clang-tools-extra/clangd/unittests/TestTU.h
clang/lib/Index/IndexingAction.cpp