[cfe-commits] r96003 - in /cfe/trunk: include/clang/AST/ASTContext.h lib/AST/ASTContext.cpp test/SemaObjC/protocol-warn.m

Fariborz Jahanian fjahanian at apple.com
Fri Feb 12 11:27:33 PST 2010


Author: fjahanian
Date: Fri Feb 12 13:27:33 2010
New Revision: 96003

URL: http://llvm.org/viewvc/llvm-project?rev=96003&view=rev
Log:
Patch to fix a warning which exposed a bug in building
a qualified objective-c pointer type. Fixes radar 7638810.
(Also removes a FIXME).

Added:
    cfe/trunk/test/SemaObjC/protocol-warn.m
Modified:
    cfe/trunk/include/clang/AST/ASTContext.h
    cfe/trunk/lib/AST/ASTContext.cpp

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=96003&r1=96002&r2=96003&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Fri Feb 12 13:27:33 2010
@@ -27,6 +27,7 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/FoldingSet.h"
 #include "llvm/ADT/OwningPtr.h"
+#include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/Support/Allocator.h"
 #include <vector>
 
@@ -890,7 +891,7 @@
   unsigned CountSynthesizedIvars(const ObjCInterfaceDecl *OI);
   unsigned CountProtocolSynthesizedIvars(const ObjCProtocolDecl *PD);
   void CollectInheritedProtocols(const Decl *CDecl,
-                          llvm::SmallVectorImpl<ObjCProtocolDecl*> &Protocols);
+                          llvm::SmallPtrSet<ObjCProtocolDecl*, 8> &Protocols);
 
   //===--------------------------------------------------------------------===//
   //                            Type Operators

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=96003&r1=96002&r2=96003&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Fri Feb 12 13:27:33 2010
@@ -917,12 +917,12 @@
 /// CollectInheritedProtocols - Collect all protocols in current class and
 /// those inherited by it.
 void ASTContext::CollectInheritedProtocols(const Decl *CDecl,
-                          llvm::SmallVectorImpl<ObjCProtocolDecl*> &Protocols) {
+                          llvm::SmallPtrSet<ObjCProtocolDecl*, 8> &Protocols) {
   if (const ObjCInterfaceDecl *OI = dyn_cast<ObjCInterfaceDecl>(CDecl)) {
     for (ObjCInterfaceDecl::protocol_iterator P = OI->protocol_begin(),
          PE = OI->protocol_end(); P != PE; ++P) {
       ObjCProtocolDecl *Proto = (*P);
-      Protocols.push_back(Proto);
+      Protocols.insert(Proto);
       for (ObjCProtocolDecl::protocol_iterator P = Proto->protocol_begin(),
            PE = Proto->protocol_end(); P != PE; ++P)
         CollectInheritedProtocols(*P, Protocols);
@@ -943,7 +943,7 @@
     for (ObjCInterfaceDecl::protocol_iterator P = OC->protocol_begin(),
          PE = OC->protocol_end(); P != PE; ++P) {
       ObjCProtocolDecl *Proto = (*P);
-      Protocols.push_back(Proto);
+      Protocols.insert(Proto);
       for (ObjCProtocolDecl::protocol_iterator P = Proto->protocol_begin(),
            PE = Proto->protocol_end(); P != PE; ++P)
         CollectInheritedProtocols(*P, Protocols);
@@ -954,7 +954,7 @@
     for (ObjCProtocolDecl::protocol_iterator P = OP->protocol_begin(),
          PE = OP->protocol_end(); P != PE; ++P) {
       ObjCProtocolDecl *Proto = (*P);
-      Protocols.push_back(Proto);
+      Protocols.insert(Proto);
       for (ObjCProtocolDecl::protocol_iterator P = Proto->protocol_begin(),
            PE = Proto->protocol_end(); P != PE; ++P)
         CollectInheritedProtocols(*P, Protocols);
@@ -4188,8 +4188,8 @@
   if (LHSNumProtocols > 0)
     InheritedProtocolSet.insert(LHS->qual_begin(), LHS->qual_end());
   else {
-    llvm::SmallVector<ObjCProtocolDecl *, 8> LHSInheritedProtocols;
-     Context.CollectInheritedProtocols(LHS->getDecl(), LHSInheritedProtocols);
+    llvm::SmallPtrSet<ObjCProtocolDecl *, 8> LHSInheritedProtocols;
+    Context.CollectInheritedProtocols(LHS->getDecl(), LHSInheritedProtocols);
     InheritedProtocolSet.insert(LHSInheritedProtocols.begin(), 
                                 LHSInheritedProtocols.end());
   }
@@ -4202,13 +4202,13 @@
         IntersectionOfProtocols.push_back(RHSProtocols[i]);
   }
   else {
-    llvm::SmallVector<ObjCProtocolDecl *, 8> RHSInheritedProtocols;
+    llvm::SmallPtrSet<ObjCProtocolDecl *, 8> RHSInheritedProtocols;
     Context.CollectInheritedProtocols(RHS->getDecl(), RHSInheritedProtocols);
-    // FIXME. This may cause duplication of protocols in the list, but should
-    // be harmless.
-    for (unsigned i = 0, len = RHSInheritedProtocols.size(); i < len; ++i)
-      if (InheritedProtocolSet.count(RHSInheritedProtocols[i]))
-        IntersectionOfProtocols.push_back(RHSInheritedProtocols[i]);
+    for (llvm::SmallPtrSet<ObjCProtocolDecl*,8>::iterator I = 
+         RHSInheritedProtocols.begin(),
+         E = RHSInheritedProtocols.end(); I != E; ++I) 
+      if (InheritedProtocolSet.count((*I)))
+        IntersectionOfProtocols.push_back((*I));
   }
 }
 

Added: cfe/trunk/test/SemaObjC/protocol-warn.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/protocol-warn.m?rev=96003&view=auto

==============================================================================
--- cfe/trunk/test/SemaObjC/protocol-warn.m (added)
+++ cfe/trunk/test/SemaObjC/protocol-warn.m Fri Feb 12 13:27:33 2010
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// radar 7638810
+
+ at protocol NSObject @end
+
+ at interface NSObject <NSObject> @end
+
+ at interface UIResponder : NSObject
+ at end
+
+ at implementation UIResponder
+ at end
+
+ at interface UIView : UIResponder
+ at end
+
+ at implementation UIView
+ at end
+
+ at interface UIWebTiledView : UIView
+ at end
+
+ at implementation UIWebTiledView
+ at end
+
+ at interface UIWebDocumentView : UIWebTiledView
+ at end
+
+ at implementation UIWebDocumentView
+ at end
+
+ at interface UIWebBrowserView : UIWebDocumentView
+ at end
+
+ at implementation UIWebBrowserView
+ at end
+
+ at interface UIPDFView : UIView
+ at end
+
+ at implementation UIPDFView
+ at end
+
+ at interface UIWebPDFView : UIPDFView
+ at end
+
+ at implementation UIWebPDFView
+ at end
+
+UIWebPDFView *getView()
+{
+    UIWebBrowserView *browserView;
+    UIWebPDFView *pdfView;
+    return pdfView ? pdfView : browserView; // expected-warning {{incompatible pointer types returning 'UIView<NSObject> *', expected 'UIWebPDFView *'}}
+}





More information about the cfe-commits mailing list