r179430 - Don't replace an existing decl in the scope chains with its

John McCall rjmccall at apple.com
Fri Apr 12 17:20:22 PDT 2013


Author: rjmccall
Date: Fri Apr 12 19:20:21 2013
New Revision: 179430

URL: http://llvm.org/viewvc/llvm-project?rev=179430&view=rev
Log:
Don't replace an existing decl in the scope chains with its
local-extern redeclaration;  type refinements, default arguments,
etc. must all be locally scoped.

rdar://13535367

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/Sema/extern-redecl.c
    cfe/trunk/test/Sema/function-redecl.c
    cfe/trunk/test/Sema/var-redecl.c

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=179430&r1=179429&r2=179430&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Apr 12 19:20:21 2013
@@ -4328,34 +4328,6 @@ Sema::RegisterLocallyScopedExternCDecl(N
          "Decl is not a locally-scoped decl!");
   // Note that we have a locally-scoped external with this name.
   LocallyScopedExternCDecls[ND->getDeclName()] = ND;
-
-  if (!Previous.isSingleResult())
-    return;
-
-  NamedDecl *PrevDecl = Previous.getFoundDecl();
-
-  // If there was a previous declaration of this entity, it may be in
-  // our identifier chain. Update the identifier chain with the new
-  // declaration.
-  if (S && IdResolver.ReplaceDecl(PrevDecl, ND)) {
-    // The previous declaration was found on the identifer resolver
-    // chain, so remove it from its scope.
-
-    if (S->isDeclScope(PrevDecl)) {
-      // Special case for redeclarations in the SAME scope.
-      // Because this declaration is going to be added to the identifier chain
-      // later, we should temporarily take it OFF the chain.
-      IdResolver.RemoveDecl(ND);
-
-    } else {
-      // Find the scope for the original declaration.
-      while (S && !S->isDeclScope(PrevDecl))
-        S = S->getParent();
-    }
-
-    if (S)
-      S->RemoveDecl(PrevDecl);
-  }
 }
 
 llvm::DenseMap<DeclarationName, NamedDecl *>::iterator

Modified: cfe/trunk/test/Sema/extern-redecl.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/extern-redecl.c?rev=179430&r1=179429&r2=179430&view=diff
==============================================================================
--- cfe/trunk/test/Sema/extern-redecl.c (original)
+++ cfe/trunk/test/Sema/extern-redecl.c Fri Apr 12 19:20:21 2013
@@ -33,3 +33,12 @@ void test3declarer() {
   extern int test3_array[];
   int x = sizeof(test3_array); // expected-error {{invalid application of 'sizeof' to an incomplete type 'int []'}}
 }
+
+void test4() {
+  extern int test4_array[];
+  {
+    extern int test4_array[100];
+    int x = sizeof(test4_array); // fine
+  }
+  int x = sizeof(test4_array); // expected-error {{invalid application of 'sizeof' to an incomplete type 'int []'}}
+}

Modified: cfe/trunk/test/Sema/function-redecl.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/function-redecl.c?rev=179430&r1=179429&r2=179430&view=diff
==============================================================================
--- cfe/trunk/test/Sema/function-redecl.c (original)
+++ cfe/trunk/test/Sema/function-redecl.c Fri Apr 12 19:20:21 2013
@@ -62,7 +62,7 @@ void test2() {
 // <rdar://problem/6127293>
 int outer1(int); // expected-note{{previous declaration is here}}
 struct outer3 { };
-int outer4(int);
+int outer4(int); // expected-note{{previous declaration is here}}
 int outer5; // expected-note{{previous definition is here}}
 int *outer7(int);
 
@@ -70,7 +70,7 @@ void outer_test() {
   int outer1(float); // expected-error{{conflicting types for 'outer1'}}
   int outer2(int); // expected-note{{previous declaration is here}}
   int outer3(int); // expected-note{{previous declaration is here}}
-  int outer4(int); // expected-note{{previous declaration is here}}
+  int outer4(int);
   int outer5(int); // expected-error{{redefinition of 'outer5' as different kind of symbol}}
   int* outer6(int); // expected-note{{previous declaration is here}}
   int *outer7(int);

Modified: cfe/trunk/test/Sema/var-redecl.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/var-redecl.c?rev=179430&r1=179429&r2=179430&view=diff
==============================================================================
--- cfe/trunk/test/Sema/var-redecl.c (original)
+++ cfe/trunk/test/Sema/var-redecl.c Fri Apr 12 19:20:21 2013
@@ -4,7 +4,7 @@ int outer1; // expected-note{{previous d
 extern int outer2; // expected-note{{previous definition is here}}
 int outer4;
 int outer4; // expected-note{{previous definition is here}}
-int outer5;
+int outer5; // expected-note{{previous definition is here}}
 int outer6(float); // expected-note{{previous definition is here}}
 int outer7(float);
 
@@ -13,7 +13,7 @@ void outer_test() {
   extern float outer2; // expected-error{{redefinition of 'outer2' with a different type}}
   extern float outer3; // expected-note{{previous definition is here}}
   double outer4;
-  extern int outer5; // expected-note{{previous definition is here}}
+  extern int outer5;
   extern int outer6; // expected-error{{redefinition of 'outer6' as different kind of symbol}}
   int outer7;
   extern int outer8; // expected-note{{previous definition is here}}





More information about the cfe-commits mailing list