From: Steve Naroff Date: Tue, 18 Nov 2008 19:15:30 +0000 (+0000) Subject: Fix [sema] crash on duplication definition of interface... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cfe8bf31ad61a16458d5970734d4a300a7bd9b0a;p=clang Fix [sema] crash on duplication definition of interface with protocols. As soon as we detect duplicate interfaces, discontinue further semantic checks (returning the original interface). This is now consistent with how we handle protocols (and less error prone in general). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59541 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index 8eeb2d367d..49b990906a 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -75,9 +75,12 @@ ActOnStartClassInterface(SourceLocation AtInterfaceLoc, ObjCInterfaceDecl* IDecl = dyn_cast_or_null(PrevDecl); if (IDecl) { // Class already seen. Is it a forward declaration? - if (!IDecl->isForwardDecl()) + if (!IDecl->isForwardDecl()) { Diag(AtInterfaceLoc, diag::err_duplicate_class_def, IDecl->getName()); - else { + // Return the previous class interface. + // FIXME: don't leak the objects passed in! + return IDecl; + } else { IDecl->setLocation(AtInterfaceLoc); IDecl->setForwardDecl(false); } @@ -119,7 +122,7 @@ ActOnStartClassInterface(SourceLocation AtInterfaceLoc, IDecl->setLocEnd(ClassLoc); } - /// Check then save referenced protocols + /// Check then save referenced protocols. if (NumProtoRefs) { IDecl->addReferencedProtocols((ObjCProtocolDecl**)ProtoRefs, NumProtoRefs); IDecl->setLocEnd(EndProtoLoc); diff --git a/test/SemaObjC/alias-test-2.m b/test/SemaObjC/alias-test-2.m index 0a17846685..5f3bfcbba7 100644 --- a/test/SemaObjC/alias-test-2.m +++ b/test/SemaObjC/alias-test-2.m @@ -1,6 +1,7 @@ // RUN: clang -fsyntax-only -verify %s -@interface Super @end +// Note: GCC doesn't produce any of the following errors. +@interface Super @end // expected-error {{previous definition is here}} @interface MyWpModule @end @@ -11,6 +12,6 @@ @interface MyAlias : AliasForSuper // expected-error {{duplicate interface declaration for class 'MyWpModule'}} @end -@implementation MyAlias : AliasForSuper +@implementation MyAlias : AliasForSuper // expected-error {{conflicting super class name 'Super'}} @end diff --git a/test/SemaObjC/check-dup-objc-decls-1.m b/test/SemaObjC/check-dup-objc-decls-1.m index e3902bdcca..8536a201de 100644 --- a/test/SemaObjC/check-dup-objc-decls-1.m +++ b/test/SemaObjC/check-dup-objc-decls-1.m @@ -26,3 +26,14 @@ void Gorf() // expected-error {{redefinition of 'Gorf' as different kind of symb { int Bar, Foo, FooBar; } + +@protocol P -im1; @end +@protocol Q -im2; @end +@interface A

@end +@interface A @end // expected-error {{duplicate interface declaration for class 'A'}} + +@protocol PP

@end +@protocol PP @end // expected-error {{duplicate protocol declaration of 'PP'}} + +@interface A(Cat)

@end +@interface A(Cat) @end // expected-warning {{duplicate interface declaration for category 'A(Cat)'}}