[cfe-commits] r66161 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.def lib/Sema/Sema.h lib/Sema/SemaDeclObjC.cpp test/SemaObjC/protocol-forward-circular.m
Steve Naroff
snaroff at apple.com
Thu Mar 5 07:22:16 PST 2009
Author: snaroff
Date: Thu Mar 5 09:22:01 2009
New Revision: 66161
URL: http://llvm.org/viewvc/llvm-project?rev=66161&view=rev
Log:
Fix <rdar://problem/6144382> [sema] gcc inconsistency w.r.t. forward protocol declarations.
Added:
cfe/trunk/test/SemaObjC/protocol-forward-circular.m
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def?rev=66161&r1=66160&r2=66161&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def Thu Mar 5 09:22:01 2009
@@ -135,6 +135,8 @@
"cannot find interface declaration for %0")
DIAG(err_duplicate_protocol_def, ERROR,
"duplicate protocol definition of %0")
+DIAG(err_protocol_has_circular_dependency, ERROR,
+ "protocol has circular dependency")
DIAG(err_undeclared_protocol, ERROR,
"cannot find protocol declaration for %0")
DIAG(warn_undef_protocolref, WARNING,
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=66161&r1=66160&r2=66161&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Thu Mar 5 09:22:01 2009
@@ -25,6 +25,7 @@
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/OwningPtr.h"
+#include "clang/AST/DeclObjC.h"
#include <string>
#include <vector>
@@ -1678,6 +1679,11 @@
SourceLocation AtCompatibilityAliasLoc,
IdentifierInfo *AliasName, SourceLocation AliasLocation,
IdentifierInfo *ClassName, SourceLocation ClassLocation);
+
+ void CheckForwardProtocolDeclarationForCircularDependency(
+ IdentifierInfo *PName,
+ SourceLocation &PLoc, SourceLocation PrevLoc,
+ const ObjCList<ObjCProtocolDecl> &PList);
virtual DeclTy *ActOnStartProtocolInterface(
SourceLocation AtProtoInterfaceLoc,
Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=66161&r1=66160&r2=66161&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Thu Mar 5 09:22:01 2009
@@ -215,6 +215,25 @@
return AliasDecl;
}
+void Sema::CheckForwardProtocolDeclarationForCircularDependency(
+ IdentifierInfo *PName,
+ SourceLocation &Ploc, SourceLocation PrevLoc,
+ const ObjCList<ObjCProtocolDecl> &PList)
+{
+ for (ObjCList<ObjCProtocolDecl>::iterator I = PList.begin(),
+ E = PList.end(); I != E; ++I) {
+
+ if (ObjCProtocolDecl *PDecl = ObjCProtocols[(*I)->getIdentifier()]) {
+ if (PDecl->getIdentifier() == PName) {
+ Diag(Ploc, diag::err_protocol_has_circular_dependency);
+ Diag(PrevLoc, diag::note_previous_definition);
+ }
+ CheckForwardProtocolDeclarationForCircularDependency(PName, Ploc,
+ PDecl->getLocation(), PDecl->getReferencedProtocols());
+ }
+ }
+}
+
Sema::DeclTy *
Sema::ActOnStartProtocolInterface(SourceLocation AtProtoInterfaceLoc,
IdentifierInfo *ProtocolName,
@@ -236,6 +255,12 @@
// FIXME: don't leak the objects passed in!
return PDecl;
}
+ ObjCList<ObjCProtocolDecl> PList;
+ PList.set((ObjCProtocolDecl *const*)ProtoRefs, NumProtoRefs, Context);
+ CheckForwardProtocolDeclarationForCircularDependency(
+ ProtocolName, ProtocolLoc, PDecl->getLocation(), PList);
+ PList.Destroy(Context);
+
// Make sure the cached decl gets a valid start location.
PDecl->setLocation(AtProtoInterfaceLoc);
PDecl->setForwardDecl(false);
Added: cfe/trunk/test/SemaObjC/protocol-forward-circular.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/protocol-forward-circular.m?rev=66161&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/protocol-forward-circular.m (added)
+++ cfe/trunk/test/SemaObjC/protocol-forward-circular.m Thu Mar 5 09:22:01 2009
@@ -0,0 +1,10 @@
+// RUN: clang -fsyntax-only -verify %s
+
+ at protocol B;
+ at protocol C < B > // expected-warning{{cannot find protocol definition for 'B'}} // expected-note{{previous definition is here}}
+ at end
+ at protocol A < C >
+ at end
+ at protocol B < A > // expected-error{{protocol has circular dependency}}
+ at end
+
More information about the cfe-commits
mailing list