[cfe-commits] r110651 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/Sema/typedef-variable-type.c

Eli Friedman eli.friedman at gmail.com
Mon Aug 9 20:13:15 PDT 2010


Author: efriedma
Date: Mon Aug  9 22:13:15 2010
New Revision: 110651

URL: http://llvm.org/viewvc/llvm-project?rev=110651&view=rev
Log:
Fix redefinition of typedefs of fixable variably-modified array types; should
fix an issue compiling <windows.h>.


Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/Sema/typedef-variable-type.c

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=110651&r1=110650&r2=110651&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Aug  9 22:13:15 2010
@@ -2332,16 +2332,10 @@
   // Handle attributes prior to checking for duplicates in MergeVarDecl
   ProcessDeclAttributes(S, NewTD, D);
 
-  // Merge the decl with the existing one if appropriate. If the decl is
-  // in an outer scope, it isn't the same thing.
-  FilterLookupForScope(*this, Previous, DC, S, /*ConsiderLinkage*/ false);
-  if (!Previous.empty()) {
-    Redeclaration = true;
-    MergeTypeDefDecl(NewTD, Previous);
-  }
-
   // C99 6.7.7p2: If a typedef name specifies a variably modified type
   // then it shall have block scope.
+  // Note that variably modified types must be fixed before merging the decl so
+  // that redeclarations will match.
   QualType T = NewTD->getUnderlyingType();
   if (T->isVariablyModifiedType()) {
     setFunctionHasBranchProtectedScope();
@@ -2365,6 +2359,14 @@
     }
   }
 
+  // Merge the decl with the existing one if appropriate. If the decl is
+  // in an outer scope, it isn't the same thing.
+  FilterLookupForScope(*this, Previous, DC, S, /*ConsiderLinkage*/ false);
+  if (!Previous.empty()) {
+    Redeclaration = true;
+    MergeTypeDefDecl(NewTD, Previous);
+  }
+
   // If this is the C FILE type, notify the AST context.
   if (IdentifierInfo *II = NewTD->getIdentifier())
     if (!NewTD->isInvalidDecl() &&

Modified: cfe/trunk/test/Sema/typedef-variable-type.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/typedef-variable-type.c?rev=110651&r1=110650&r2=110651&view=diff
==============================================================================
--- cfe/trunk/test/Sema/typedef-variable-type.c (original)
+++ cfe/trunk/test/Sema/typedef-variable-type.c Mon Aug  9 22:13:15 2010
@@ -1,3 +1,8 @@
-// RUN: %clang_cc1 %s -verify -fsyntax-only -pedantic
+// RUN: %clang_cc1 %s -verify -fsyntax-only -pedantic -Wno-typedef-redefinition
 
+// Make sure we accept a single typedef
+typedef int (*a)[!.0]; // expected-warning{{size of static array must be an integer constant expression}}
+
+// And make sure we accept identical redefinitions in system headers
+// (The test uses -Wno-typedef-redefinition to simulate this.)
 typedef int (*a)[!.0]; // expected-warning{{size of static array must be an integer constant expression}}





More information about the cfe-commits mailing list