summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaLookup.cpp
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2017-10-13 22:14:34 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2017-10-13 22:14:34 +0000
commit17ba669ad96b6bb303324dda9a4f8d4d7d92fda8 (patch)
treee795274f98706739630e247bf2b2eaf772fd164b /clang/lib/Sema/SemaLookup.cpp
parenta3cd5247b3a15038e1bde0a867b69432531f98de (diff)
downloadbcm5719-llvm-17ba669ad96b6bb303324dda9a4f8d4d7d92fda8.tar.gz
bcm5719-llvm-17ba669ad96b6bb303324dda9a4f8d4d7d92fda8.zip
[Sema] Avoid iterator invalidation when code completing.
It's possible for the code completion consumer to add new decls to the current scope while lookup happens on it. Avoid this by making a copy first. Sadly I wasn't able to get a self-contained test case for this as it requires code completion + precompiled preamble + the stars aligning to deserialize at exactly the right time. llvm-svn: 315772
Diffstat (limited to 'clang/lib/Sema/SemaLookup.cpp')
-rw-r--r--clang/lib/Sema/SemaLookup.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index 8f3e93845bb..827c7012bc3 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -3677,8 +3677,10 @@ static void LookupVisibleDecls(Scope *S, LookupResult &Result,
!Visited.alreadyVisitedContext(S->getEntity())) ||
(S->getEntity())->isFunctionOrMethod()) {
FindLocalExternScope FindLocals(Result);
- // Walk through the declarations in this Scope.
- for (auto *D : S->decls()) {
+ // Walk through the declarations in this Scope. The consumer might add new
+ // decls to the scope as part of deserialization, so make a copy first.
+ SmallVector<Decl *, 8> ScopeDecls(S->decls().begin(), S->decls().end());
+ for (Decl *D : ScopeDecls) {
if (NamedDecl *ND = dyn_cast<NamedDecl>(D))
if ((ND = Result.getAcceptableDecl(ND))) {
Consumer.FoundDecl(ND, Visited.checkHidden(ND), nullptr, false);
OpenPOWER on IntegriCloud