diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-03-24 10:35:39 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-03-24 10:35:39 +0000 |
commit | fa7b8ced6f3318879b39f44b5ace8346e979826e (patch) | |
tree | 3c5cc15f150f3a2f667e3c2a55c64dd23657e09f | |
parent | c285372e69f42d95ca638d74abd1f46bd7b77a96 (diff) |
Fix the insertion of label declarations into the identifier chain in
the case where we only have a single identifier with that name in the
chain. Fixes PR9463 for real this time.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@128208 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/IdentifierResolver.cpp | 21 | ||||
-rw-r--r-- | test/SemaCXX/goto.cpp | 20 | ||||
-rw-r--r-- | test/SemaCXX/goto2.cpp | 47 |
3 files changed, 85 insertions, 3 deletions
diff --git a/lib/Sema/IdentifierResolver.cpp b/lib/Sema/IdentifierResolver.cpp index d520a6edab..95420a316a 100644 --- a/lib/Sema/IdentifierResolver.cpp +++ b/lib/Sema/IdentifierResolver.cpp @@ -172,13 +172,28 @@ void IdentifierResolver::InsertDeclAfter(iterator Pos, NamedDecl *D) { DeclarationName Name = D->getDeclName(); void *Ptr = Name.getFETokenInfo<void>(); - if (Pos == iterator() || isDeclPtr(Ptr)) { - // Simple case: insert at the end of the list (which is the - // end of the stored vector). + if (!Ptr) { AddDecl(D); return; } + if (isDeclPtr(Ptr)) { + // We only have a single declaration: insert before or after it, + // as appropriate. + if (Pos == iterator()) { + // Add the new declaration before the existing declaration. + NamedDecl *PrevD = static_cast<NamedDecl*>(Ptr); + RemoveDecl(PrevD); + AddDecl(D); + AddDecl(PrevD); + } else { + // Add new declaration after the existing declaration. + AddDecl(D); + } + + return; + } + if (IdentifierInfo *II = Name.getAsIdentifierInfo()) II->setIsFromAST(false); diff --git a/test/SemaCXX/goto.cpp b/test/SemaCXX/goto.cpp index dd2e03d471..b2b1e6f391 100644 --- a/test/SemaCXX/goto.cpp +++ b/test/SemaCXX/goto.cpp @@ -19,6 +19,26 @@ void f(bool b1, bool b2) { return; } +namespace N { + float* end; + void f(bool b1, bool b2) { + { + do { + int end = 0; + if (b2) { + do { + goto end; + } while (b2); + } + end = 1; + } while (b1); + } + + end: + return; + } +} + void g() { end = 1; // expected-error{{assigning to 'double *' from incompatible type 'int'}} } diff --git a/test/SemaCXX/goto2.cpp b/test/SemaCXX/goto2.cpp new file mode 100644 index 0000000000..01ea031ac2 --- /dev/null +++ b/test/SemaCXX/goto2.cpp @@ -0,0 +1,47 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +//PR9463 +int subfun(const char *text) { + const char *tmp = text; + return 0; +} + +void fun(const char* text) { + int count = 0; + bool check = true; + + if (check) + { + const char *end = text; + + if (check) + { + do + { + if (check) + { + count = subfun(end); + goto end; + } + + check = !check; + } + while (check); + } + // also works, after commenting following line of source code + int e = subfun(end); + } + end: + if (check) + ++count; +} + +const char *text = "some text"; + +int main() { + const char *ptr = text; + + fun(ptr); + + return 0; +} |