summaryrefslogtreecommitdiffstats
path: root/lib/Sema/IdentifierResolver.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-03-16 16:39:03 +0000
committerDouglas Gregor <dgregor@apple.com>2011-03-16 16:39:03 +0000
commit250e7a74d5a23db5bd7202ecb0bb4a8fef6016b4 (patch)
tree57f0f694b1dcf003464535b63c53a1846707770a /lib/Sema/IdentifierResolver.cpp
parent4d000b322fb1e7ed7fa2de5ab4bfb473bad2edae (diff)
When we're inserting a synthesized label declaration for a
forward-looking "goto" statement, make sure to insert it *after* the last declaration in the identifier resolver's declaration chain that is either outside of the function/block/method's scope or that is declared in that function/block/method's specific scope. Previously, we could end up inserting the label ahead of declarations in inner scopes, confusing C++ name lookup. Fixes PR9491/<rdar://problem/9140426> and <rdar://problem/9135994>. Note that the crash-on-invalid PR9495 is *not* fixed. That's a separate issue. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@127737 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/IdentifierResolver.cpp')
-rw-r--r--lib/Sema/IdentifierResolver.cpp32
1 files changed, 11 insertions, 21 deletions
diff --git a/lib/Sema/IdentifierResolver.cpp b/lib/Sema/IdentifierResolver.cpp
index fcfc05380b..d520a6edab 100644
--- a/lib/Sema/IdentifierResolver.cpp
+++ b/lib/Sema/IdentifierResolver.cpp
@@ -168,36 +168,26 @@ void IdentifierResolver::AddDecl(NamedDecl *D) {
IDI->AddDecl(D);
}
-void IdentifierResolver::InsertDecl(iterator Pos, NamedDecl *D) {
- if (Pos == iterator()) {
- // Simple case: insert at the beginning of the list (which is the
- // end of the stored vector).
- AddDecl(D);
- return;
- }
-
+void IdentifierResolver::InsertDeclAfter(iterator Pos, NamedDecl *D) {
DeclarationName Name = D->getDeclName();
void *Ptr = Name.getFETokenInfo<void>();
- if (isDeclPtr(Ptr)) {
- // There's only one element, and we want to insert before it in the list.
- // Just create the storage for these identifiers and insert them in the
- // opposite order we normally would.
- assert(isDeclPtr(Ptr) && "Not a single declaration!");
- Name.setFETokenInfo(NULL);
- IdDeclInfo *IDI = &(*IdDeclInfos)[Name];
- NamedDecl *PrevD = static_cast<NamedDecl*>(Ptr);
- IDI->AddDecl(D);
- IDI->AddDecl(PrevD);
+ if (Pos == iterator() || isDeclPtr(Ptr)) {
+ // Simple case: insert at the end of the list (which is the
+ // end of the stored vector).
+ AddDecl(D);
return;
}
+ if (IdentifierInfo *II = Name.getAsIdentifierInfo())
+ II->setIsFromAST(false);
+
// General case: insert the declaration at the appropriate point in the
// list, which already has at least two elements.
IdDeclInfo *IDI = toIdDeclInfo(Ptr);
- if (Pos.isIterator())
- IDI->InsertDecl(Pos.getIterator(), D);
- else
+ if (Pos.isIterator()) {
+ IDI->InsertDecl(Pos.getIterator() + 1, D);
+ } else
IDI->InsertDecl(IDI->decls_begin(), D);
}