From 997a91fdf0d9fcd0cba0d27af8a21d3086a2c900 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Tue, 11 Mar 2014 18:56:18 +0000 Subject: [PATCH] Objective-C. Prevent an assertion crash due to buggy code as it can commonly happen. // rdar://16261494 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203598 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/DeclObjC.cpp | 16 ++++++++++++---- test/SemaObjC/attr-designated-init.m | 10 ++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp index b76fc5cf38..094110fecf 100644 --- a/lib/AST/DeclObjC.cpp +++ b/lib/AST/DeclObjC.cpp @@ -415,7 +415,9 @@ bool ObjCInterfaceDecl::inheritsDesignatedInitializers() const { void ObjCInterfaceDecl::getDesignatedInitializers( llvm::SmallVectorImpl &Methods) const { - assert(hasDefinition()); + // Check for a complete definition and recover if not so. + if (!isThisDeclarationADefinition()) + return; if (data().ExternallyCompleted) LoadExternalDefinition(); @@ -433,7 +435,9 @@ void ObjCInterfaceDecl::getDesignatedInitializers( bool ObjCInterfaceDecl::isDesignatedInitializer(Selector Sel, const ObjCMethodDecl **InitMethod) const { - assert(hasDefinition()); + // Check for a complete definition and recover if not so. + if (!isThisDeclarationADefinition()) + return false; if (data().ExternallyCompleted) LoadExternalDefinition(); @@ -1197,12 +1201,16 @@ void ObjCInterfaceDecl::setExternallyCompleted() { } void ObjCInterfaceDecl::setHasDesignatedInitializers() { - assert(hasDefinition() && "Forward declarations can't contain methods"); + // Check for a complete definition and recover if not so. + if (!isThisDeclarationADefinition()) + return; data().HasDesignatedInitializers = true; } bool ObjCInterfaceDecl::hasDesignatedInitializers() const { - assert(hasDefinition() && "Forward declarations can't contain methods"); + // Check for a complete definition and recover if not so. + if (!isThisDeclarationADefinition()) + return false; if (data().ExternallyCompleted) LoadExternalDefinition(); diff --git a/test/SemaObjC/attr-designated-init.m b/test/SemaObjC/attr-designated-init.m index 0432a1859b..d24c9c65cb 100644 --- a/test/SemaObjC/attr-designated-init.m +++ b/test/SemaObjC/attr-designated-init.m @@ -238,3 +238,13 @@ __attribute__((objc_root_class)) return 0; } @end + +// rdar://16261494 +@class GEOPDAnalyticMetadata; // expected-note {{forward declaration of class here}} + +@implementation GEOPDAnalyticMetadata (PlaceCardExtras) // expected-error {{cannot find interface declaration for 'GEOPDAnalyticMetadata'}} +- (instancetype)initInProcess +{ + return ((void*)0); +} +@end -- 2.40.0