[cfe-commits] r134097 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/Sema/extern-redecl.c
Douglas Gregor
dgregor at apple.com
Wed Jun 29 14:22:02 PDT 2011
Author: dgregor
Date: Wed Jun 29 16:22:02 2011
New Revision: 134097
URL: http://llvm.org/viewvc/llvm-project?rev=134097&view=rev
Log:
When redeclaring a local extern in the same scope, make sure that we
replace the existing declaration appropriately. Patch by Jordy Rose,
fixes PR10013 / <rdar://problem/9584157>.
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/Sema/extern-redecl.c
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=134097&r1=134096&r2=134097&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Jun 29 16:22:02 2011
@@ -3299,8 +3299,18 @@
if (S && IdResolver.ReplaceDecl(PrevDecl, ND)) {
// The previous declaration was found on the identifer resolver
// chain, so remove it from its scope.
- while (S && !S->isDeclScope(PrevDecl))
- S = S->getParent();
+
+ 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);
Modified: cfe/trunk/test/Sema/extern-redecl.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/extern-redecl.c?rev=134097&r1=134096&r2=134097&view=diff
==============================================================================
--- cfe/trunk/test/Sema/extern-redecl.c (original)
+++ cfe/trunk/test/Sema/extern-redecl.c Wed Jun 29 16:22:02 2011
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only %s
+// RUN: %clang_cc1 -fsyntax-only -verify %s
// rdar: // 8125274
static int a16[]; // expected-warning {{tentative array definition assumed to have one element}}
@@ -7,3 +7,16 @@
extern int a16[];
}
+
+// PR10013: Scope of extern declarations extend past enclosing block
+extern int PR10013_x;
+int PR10013(void) {
+ int *PR10013_x = 0;
+ {
+ extern int PR10013_x;
+ extern int PR10013_x;
+ }
+
+ return PR10013_x; // expected-warning{{incompatible pointer to integer conversion}}
+}
+
More information about the cfe-commits
mailing list