[Modules] [Sema] Don't try to getAcceptableDecls during the iteration of noload_lookups
authorChuanqi Xu <yedeng.yd@linux.alibaba.com>
Fri, 9 Jun 2023 03:21:29 +0000 (11:21 +0800)
committerChuanqi Xu <yedeng.yd@linux.alibaba.com>
Fri, 9 Jun 2023 03:32:06 +0000 (11:32 +0800)
commit60eb1da315559a9e20f9bf502fd10ba68f6d4085
tree751ddbf983073ae9d9512636e820ce0de2681cc4
parent20d21017b21713e554fc7d97638449f0fc90f256
[Modules] [Sema] Don't try to getAcceptableDecls during the iteration of noload_lookups

I found this during the support of modules for clangd. The reason for
the issue is that the iterator returned by noload_lookups is fast-fail
after the lookup table changes by the design of llvm::DenseMap. And
originally the lookup will try to use getAcceptableDecl to filter the
invisible decls. The key point here is that the function
"getAcceptableDecl" wouldn't stop after it find the specific decl is
invisble. It will continue to visit its redecls to find a visible one.
However, such process involves loading decls from external sources,
which results the invalidation.

Note that the use of "noload_lookups" is rare. It is only used in tools
like FixTypos and CodeCompletions. So it is completely fine for the
tranditional compiler. This is the reason why I can't reproduce it by a
lit test.
clang/lib/Sema/SemaLookup.cpp
clang/unittests/Sema/CMakeLists.txt
clang/unittests/Sema/SemaNoloadLookupTest.cpp [new file with mode: 0644]