#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>
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
/// 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);
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);
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);
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());
}
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));
}
}
--- /dev/null
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// radar 7638810
+
+@protocol NSObject @end
+
+@interface NSObject <NSObject> @end
+
+@interface UIResponder : NSObject
+@end
+
+@implementation UIResponder
+@end
+
+@interface UIView : UIResponder
+@end
+
+@implementation UIView
+@end
+
+@interface UIWebTiledView : UIView
+@end
+
+@implementation UIWebTiledView
+@end
+
+@interface UIWebDocumentView : UIWebTiledView
+@end
+
+@implementation UIWebDocumentView
+@end
+
+@interface UIWebBrowserView : UIWebDocumentView
+@end
+
+@implementation UIWebBrowserView
+@end
+
+@interface UIPDFView : UIView
+@end
+
+@implementation UIPDFView
+@end
+
+@interface UIWebPDFView : UIPDFView
+@end
+
+@implementation UIWebPDFView
+@end
+
+UIWebPDFView *getView()
+{
+ UIWebBrowserView *browserView;
+ UIWebPDFView *pdfView;
+ return pdfView ? pdfView : browserView; // expected-warning {{incompatible pointer types returning 'UIView<NSObject> *', expected 'UIWebPDFView *'}}
+}