[cfe-commits] r75385 - in /cfe/trunk: lib/CodeGen/CodeGenTypes.cpp test/CodeGenObjC/protocols.m

Daniel Dunbar daniel at zuster.org
Sat Jul 11 14:12:15 PDT 2009


Author: ddunbar
Date: Sat Jul 11 16:12:14 2009
New Revision: 75385

URL: http://llvm.org/viewvc/llvm-project?rev=75385&view=rev
Log:
Fix type conversion of ObjCObjectPointerType.
 - Previous code was based on a misunderstanding (on my part) of the type
   representation.

Added:
    cfe/trunk/test/CodeGenObjC/protocols.m
Modified:
    cfe/trunk/lib/CodeGen/CodeGenTypes.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTypes.cpp?rev=75385&r1=75384&r2=75385&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenTypes.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenTypes.cpp Sat Jul 11 16:12:14 2009
@@ -355,13 +355,14 @@
   }
       
   case Type::ObjCObjectPointer: {
-   // Qualified id types don't influence the LLVM type, here we always return
-   // an opaque type for 'id'.
-   const llvm::Type *&T = InterfaceTypes[0];
-   if (!T)
-       T = llvm::OpaqueType::get();
-   return llvm::PointerType::getUnqual(T);
+    // Protocol qualifications do not influence the LLVM type, we just return a
+    // pointer to the underlying interface type. We don't need to worry about
+    // recursive conversion.
+    const llvm::Type *T = 
+      ConvertTypeRecursive(cast<ObjCObjectPointerType>(Ty).getPointeeType());
+    return llvm::PointerType::getUnqual(T);
   }
+
   case Type::Record:
   case Type::Enum: {
     const TagDecl *TD = cast<TagType>(Ty).getDecl();

Added: cfe/trunk/test/CodeGenObjC/protocols.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/protocols.m?rev=75385&view=auto

==============================================================================
--- cfe/trunk/test/CodeGenObjC/protocols.m (added)
+++ cfe/trunk/test/CodeGenObjC/protocols.m Sat Jul 11 16:12:14 2009
@@ -0,0 +1,50 @@
+// RUN: clang-cc -emit-llvm %s -o %t
+
+void p(const char*, ...);
+
+ at interface Root
+-(int) conformsTo: (id) x;
+ at end
+
+ at protocol P0;
+
+ at protocol P1
++(void) classMethodReq0;
+-(void) methodReq0;
+ at optional
++(void) classMethodOpt1;
+-(void) methodOpt1;
+ at required
++(void) classMethodReq2;
+-(void) methodReq2;
+ at end
+
+ at protocol P2
+//@property(readwrite) int x;
+ at end
+
+ at protocol P3<P1, P2>
+-(id <P1>) print0;
+-(void) print1;
+ at end
+
+void foo(const id a) {
+  void *p = @protocol(P3);
+}
+
+int main() {
+  Protocol *P0 = @protocol(P0);
+  Protocol *P1 = @protocol(P1);
+  Protocol *P2 = @protocol(P2);
+  Protocol *P3 = @protocol(P3);
+
+#define Pbool(X) p(#X ": %s\n", X ? "yes" : "no");
+  Pbool([P0 conformsTo: P1]);
+  Pbool([P1 conformsTo: P0]);
+  Pbool([P1 conformsTo: P2]);
+  Pbool([P2 conformsTo: P1]);
+  Pbool([P3 conformsTo: P1]);
+  Pbool([P1 conformsTo: P3]);
+
+  return 0;
+}





More information about the cfe-commits mailing list