summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-07-26 00:46:50 +0000
committerChris Lattner <sabre@nondot.org>2008-07-26 00:46:50 +0000
commita075e63bbca031f3d5794e888252cab265cc058c (patch)
treec61e53907ccc3f6106183a494a0d484cf0ad0f38 /clang
parent0974b2380f555333aa34125e870e0620af8d11fe (diff)
downloadbcm5719-llvm-a075e63bbca031f3d5794e888252cab265cc058c.tar.gz
bcm5719-llvm-a075e63bbca031f3d5794e888252cab265cc058c.zip
fix several problems with the protocol qualified id handling where id was implicit.
First, fix canonical type handling of these, since protocol qualified id's are always canonical. Next, enhance SemaType to actually make these when used (instead of int) allowing them to actually be used when appropriate. Finally remove a bunch of logic relating to the mishandling of canonical types with protocol-qual id's. This fixes rdar://5986251 llvm-svn: 54083
Diffstat (limited to 'clang')
-rw-r--r--clang/include/clang/AST/ASTContext.h3
-rw-r--r--clang/include/clang/AST/Type.h6
-rw-r--r--clang/lib/AST/ASTContext.cpp17
-rw-r--r--clang/lib/AST/Type.cpp4
-rw-r--r--clang/lib/Sema/SemaType.cpp13
-rw-r--r--clang/test/Sema/objc-protocol-1.m4
6 files changed, 23 insertions, 24 deletions
diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h
index c981aa4116b..0def9881402 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -217,8 +217,7 @@ public:
/// getObjCQualifiedIdType - Return an ObjCQualifiedIdType for a
/// given 'id' and conforming protocol list.
- QualType getObjCQualifiedIdType(QualType idType,
- ObjCProtocolDecl **ProtocolList,
+ QualType getObjCQualifiedIdType(ObjCProtocolDecl **ProtocolList,
unsigned NumProtocols);
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 22f7abaf49b..28f6e8cf932 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -1227,8 +1227,8 @@ class ObjCQualifiedIdType : public Type,
// List is sorted on protocol name. No protocol is enterred more than once.
llvm::SmallVector<ObjCProtocolDecl*, 8> Protocols;
- ObjCQualifiedIdType(QualType can, ObjCProtocolDecl **Protos, unsigned NumP)
- : Type(ObjCQualifiedId, can),
+ ObjCQualifiedIdType(ObjCProtocolDecl **Protos, unsigned NumP)
+ : Type(ObjCQualifiedId, QualType()/*these are always canonical*/),
Protocols(Protos, Protos+NumP) { }
friend class ASTContext; // ASTContext creates these.
public:
@@ -1250,7 +1250,7 @@ public:
virtual void getAsStringInternal(std::string &InnerString) const;
void Profile(llvm::FoldingSetNodeID &ID);
- static void Profile(llvm::FoldingSetNodeID &ID,
+ static void Profile(llvm::FoldingSetNodeID &ID,
ObjCProtocolDecl **protocols, unsigned NumProtocols);
static bool classof(const Type *T) {
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 54cc8e00683..dedc9b8376a 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -929,8 +929,7 @@ QualType ASTContext::getObjCQualifiedInterfaceType(ObjCInterfaceDecl *Decl,
/// getObjCQualifiedIdType - Return an ObjCQualifiedIdType for the 'id' decl
/// and the conforming protocol list.
-QualType ASTContext::getObjCQualifiedIdType(QualType idType,
- ObjCProtocolDecl **Protocols,
+QualType ASTContext::getObjCQualifiedIdType(ObjCProtocolDecl **Protocols,
unsigned NumProtocols) {
// Sort the protocol list alphabetically to canonicalize it.
SortAndUniqueProtocols(Protocols, NumProtocols);
@@ -940,21 +939,11 @@ QualType ASTContext::getObjCQualifiedIdType(QualType idType,
void *InsertPos = 0;
if (ObjCQualifiedIdType *QT =
- ObjCQualifiedIdTypes.FindNodeOrInsertPos(ID, InsertPos))
+ ObjCQualifiedIdTypes.FindNodeOrInsertPos(ID, InsertPos))
return QualType(QT, 0);
// No Match;
- QualType Canonical;
- if (!idType->isCanonical()) {
- Canonical = getObjCQualifiedIdType(getCanonicalType(idType),
- Protocols, NumProtocols);
- ObjCQualifiedIdType *NewQT =
- ObjCQualifiedIdTypes.FindNodeOrInsertPos(ID, InsertPos);
- assert(NewQT == 0 && "Shouldn't be in the map!");
- }
-
- ObjCQualifiedIdType *QType =
- new ObjCQualifiedIdType(Canonical, Protocols, NumProtocols);
+ ObjCQualifiedIdType *QType = new ObjCQualifiedIdType(Protocols, NumProtocols);
Types.push_back(QType);
ObjCQualifiedIdTypes.InsertNode(QType, InsertPos);
return QualType(QType, 0);
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 275406eabac..08f889a4bf8 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -743,8 +743,8 @@ void ObjCQualifiedInterfaceType::Profile(llvm::FoldingSetNodeID &ID) {
}
void ObjCQualifiedIdType::Profile(llvm::FoldingSetNodeID &ID,
- ObjCProtocolDecl **protocols,
- unsigned NumProtocols) {
+ ObjCProtocolDecl **protocols,
+ unsigned NumProtocols) {
for (unsigned i = 0; i != NumProtocols; i++)
ID.AddPointer(protocols[i]);
}
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 4bee2de9948..85a457bd562 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -43,6 +43,14 @@ QualType Sema::ConvertDeclSpecToType(const DeclSpec &DS) {
}
break;
case DeclSpec::TST_unspecified:
+ // "<proto1,proto2>" is an objc qualified ID with a missing id.
+ if (llvm::SmallVector<Action::DeclTy *, 8> *PQ=DS.getProtocolQualifiers()) {
+ Action::DeclTy **PPDecl = &(*PQ)[0];
+ Result = Context.getObjCQualifiedIdType((ObjCProtocolDecl**)(PPDecl),
+ DS.getNumProtocolQualifiers());
+ break;
+ }
+
// Unspecified typespec defaults to int in C90. However, the C90 grammar
// [C90 6.5] only allows a decl-spec if there was *some* type-specifier,
// type-qualifier, or storage-class-specifier. If not, emit an extwarn.
@@ -128,13 +136,12 @@ QualType Sema::ConvertDeclSpecToType(const DeclSpec &DS) {
reinterpret_cast<ObjCProtocolDecl**>(PPDecl),
DS.getNumProtocolQualifiers());
break;
- }
- else if (TypedefDecl *typeDecl = dyn_cast<TypedefDecl>(D)) {
+ } else if (TypedefDecl *typeDecl = dyn_cast<TypedefDecl>(D)) {
if (Context.getObjCIdType() == Context.getTypedefType(typeDecl)
&& DS.getProtocolQualifiers()) {
// id<protocol-list>
Action::DeclTy **PPDecl = &(*DS.getProtocolQualifiers())[0];
- Result = Context.getObjCQualifiedIdType(typeDecl->getUnderlyingType(),
+ Result = Context.getObjCQualifiedIdType(
reinterpret_cast<ObjCProtocolDecl**>(PPDecl),
DS.getNumProtocolQualifiers());
break;
diff --git a/clang/test/Sema/objc-protocol-1.m b/clang/test/Sema/objc-protocol-1.m
index f0615a32bea..3ace0ac3de0 100644
--- a/clang/test/Sema/objc-protocol-1.m
+++ b/clang/test/Sema/objc-protocol-1.m
@@ -1,10 +1,14 @@
// RUN: clang -fsyntax-only -verify %s
+// rdar://5986251
@protocol SomeProtocol
+- (void) bar;
@end
void foo(id x) {
bar((short<SomeProtocol>)x); // expected-error {{expected ')'}} expected-error {{to match this '('}}
bar((<SomeProtocol>)x); // expected-warning {{protocol qualifiers without 'id' is archaic}}
+
+ [(<SomeProtocol>)x bar]; // expected-warning {{protocol qualifiers without 'id' is archaic}}
}
OpenPOWER on IntegriCloud