[cfe-commits] r54038 - in /cfe/trunk: include/clang/Basic/DiagnosticKinds.def lib/Sema/SemaDecl.cpp test/Sema/typedef-redef.c

Chris Lattner sabre at nondot.org
Fri Jul 25 11:44:27 PDT 2008


Author: lattner
Date: Fri Jul 25 13:44:27 2008
New Revision: 54038

URL: http://llvm.org/viewvc/llvm-project?rev=54038&view=rev
Log:
Reject typedef redefinitions when the underlying types are not identical,
even if in a system header etc.  rdar://6079937


Modified:
    cfe/trunk/include/clang/Basic/DiagnosticKinds.def
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/Sema/typedef-redef.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=54038&r1=54037&r2=54038&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Fri Jul 25 13:44:27 2008
@@ -739,6 +739,8 @@
      "non-static declaration of '%0' follows static declaration")
 DIAG(err_redefinition_different_kind, ERROR,
      "redefinition of '%0' as different kind of symbol")
+DIAG(err_redefinition_different_typedef, ERROR,
+     "typedef redefinition with different types ('%0' vs '%1')")
 DIAG(err_conflicting_types, ERROR,
      "conflicting types for '%0'")
 DIAG(err_nested_redefinition, ERROR,

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=54038&r1=54037&r2=54038&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Jul 25 13:44:27 2008
@@ -248,6 +248,18 @@
     return New;
   }
   
+  // If the typedef types are not identical, reject them in all languages and
+  // with any extensions enabled.
+  if (Old->getUnderlyingType() != New->getUnderlyingType() && 
+      Context.getCanonicalType(Old->getUnderlyingType()) != 
+      Context.getCanonicalType(New->getUnderlyingType())) {
+    Diag(New->getLocation(), diag::err_redefinition_different_typedef,
+         New->getUnderlyingType().getAsString(),
+         Old->getUnderlyingType().getAsString());
+    Diag(Old->getLocation(), diag::err_previous_definition);
+    return Old;
+  }
+  
   // Allow multiple definitions for ObjC built-in typedefs.
   // FIXME: Verify the underlying types are equivalent!
   if (getLangOptions().ObjC1 && isBuiltinObjCType(New))

Modified: cfe/trunk/test/Sema/typedef-redef.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/typedef-redef.c?rev=54038&r1=54037&r2=54038&view=diff

==============================================================================
--- cfe/trunk/test/Sema/typedef-redef.c (original)
+++ cfe/trunk/test/Sema/typedef-redef.c Fri Jul 25 13:44:27 2008
@@ -1,4 +1,13 @@
 // RUN: clang < %s -fsyntax-only -verify
 
+// size_t coming from a system header.
 #include <stddef.h>
-typedef unsigned long size_t;
+typedef __SIZE_TYPE__ size_t;
+
+
+
+typedef const int x; // expected-error {{previous definition is here}}
+extern x a;
+typedef int x;  // expected-error {{typedef redefinition with different types}}
+extern x a;
+





More information about the cfe-commits mailing list