[cfe-commits] r128208 - in /cfe/trunk: lib/Sema/IdentifierResolver.cpp test/SemaCXX/goto.cpp test/SemaCXX/goto2.cpp

Douglas Gregor dgregor at apple.com
Thu Mar 24 03:35:39 PDT 2011


Author: dgregor
Date: Thu Mar 24 05:35:39 2011
New Revision: 128208

URL: http://llvm.org/viewvc/llvm-project?rev=128208&view=rev
Log:
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.

Added:
    cfe/trunk/test/SemaCXX/goto2.cpp   (with props)
Modified:
    cfe/trunk/lib/Sema/IdentifierResolver.cpp
    cfe/trunk/test/SemaCXX/goto.cpp

Modified: cfe/trunk/lib/Sema/IdentifierResolver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/IdentifierResolver.cpp?rev=128208&r1=128207&r2=128208&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/IdentifierResolver.cpp (original)
+++ cfe/trunk/lib/Sema/IdentifierResolver.cpp Thu Mar 24 05:35:39 2011
@@ -172,13 +172,28 @@
   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);
   

Modified: cfe/trunk/test/SemaCXX/goto.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/goto.cpp?rev=128208&r1=128207&r2=128208&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/goto.cpp (original)
+++ cfe/trunk/test/SemaCXX/goto.cpp Thu Mar 24 05:35:39 2011
@@ -19,6 +19,26 @@
   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'}}
 }

Added: cfe/trunk/test/SemaCXX/goto2.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/goto2.cpp?rev=128208&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/goto2.cpp (added)
+++ cfe/trunk/test/SemaCXX/goto2.cpp Thu Mar 24 05:35:39 2011
@@ -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;
+}

Propchange: cfe/trunk/test/SemaCXX/goto2.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cfe/trunk/test/SemaCXX/goto2.cpp
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cfe/trunk/test/SemaCXX/goto2.cpp
------------------------------------------------------------------------------
    svn:mime-type = text/plain





More information about the cfe-commits mailing list