[cfe-commits] r156788 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/SemaObjC/id.m

Fariborz Jahanian fjahanian at apple.com
Mon May 14 15:48:56 PDT 2012


Author: fjahanian
Date: Mon May 14 17:48:56 2012
New Revision: 156788

URL: http://llvm.org/viewvc/llvm-project?rev=156788&view=rev
Log:
objc: allow typedef'ing an id to a pointer to a c-struct only.
// rdar://11356439

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/SemaObjC/id.m

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=156788&r1=156787&r2=156788&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon May 14 17:48:56 2012
@@ -1518,12 +1518,22 @@
     switch (TypeID->getLength()) {
     default: break;
     case 2:
-      if (!TypeID->isStr("id"))
-        break;
-      Context.setObjCIdRedefinitionType(New->getUnderlyingType());
-      // Install the built-in type for 'id', ignoring the current definition.
-      New->setTypeForDecl(Context.getObjCIdType().getTypePtr());
-      return;
+      {
+        if (!TypeID->isStr("id"))
+          break;
+        QualType T = New->getUnderlyingType();
+        if (!T->isPointerType())
+          break;
+        if (!T->isVoidPointerType()) {
+          QualType PT = T->getAs<PointerType>()->getPointeeType();
+          if (!PT->isStructureType())
+            break;
+        }
+        Context.setObjCIdRedefinitionType(T);
+        // Install the built-in type for 'id', ignoring the current definition.
+        New->setTypeForDecl(Context.getObjCIdType().getTypePtr());
+        return;
+      }
     case 5:
       if (!TypeID->isStr("Class"))
         break;

Modified: cfe/trunk/test/SemaObjC/id.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/id.m?rev=156788&r1=156787&r2=156788&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/id.m (original)
+++ cfe/trunk/test/SemaObjC/id.m Mon May 14 17:48:56 2012
@@ -16,6 +16,16 @@
 }
 
 // Test attempt to redefine 'id' in an incompatible fashion.
-typedef int id;  // FIXME: Decide how we want to deal with this (now that 'id' is more of a built-in type).
+// rdar://11356439
+typedef int id;  // expected-error {{typedef redefinition with different types ('int' vs 'id')}}
 id b;
 
+typedef double id;  // expected-error {{typedef redefinition with different types ('double' vs 'id')}}
+
+typedef char *id; // expected-error {{typedef redefinition with different types ('char *' vs 'id')}}
+
+typedef union U{ int iu; } *id; // expected-error {{typedef redefinition with different types ('union U *' vs 'id')}}
+
+void test11356439(id o) {
+  o->x; // expected-error {{member reference base type 'id' is not a structure or union}}
+}





More information about the cfe-commits mailing list