diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2017-10-13 22:14:34 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2017-10-13 22:14:34 +0000 |
commit | 912dc999b86bb9fd2e7fa5f275bd373d19237787 (patch) | |
tree | c4a245420751681985b2973db801bfe952b49e7c /lib/Sema/SemaLookup.cpp | |
parent | f9470527074c034b3f6da4b894416baf1c3998a7 (diff) | |
download | clang-912dc999b86bb9fd2e7fa5f275bd373d19237787.tar.gz |
[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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@315772 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaLookup.cpp')
-rw-r--r-- | lib/Sema/SemaLookup.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index 8f3e93845b..827c7012bc 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/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); |