r203598 - Objective-C. Prevent an assertion crash due to buggy code
Fariborz Jahanian
fjahanian at apple.com
Tue Mar 11 11:56:18 PDT 2014
Author: fjahanian
Date: Tue Mar 11 13:56:18 2014
New Revision: 203598
URL: http://llvm.org/viewvc/llvm-project?rev=203598&view=rev
Log:
Objective-C. Prevent an assertion crash due to buggy code
as it can commonly happen. // rdar://16261494
Modified:
cfe/trunk/lib/AST/DeclObjC.cpp
cfe/trunk/test/SemaObjC/attr-designated-init.m
Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=203598&r1=203597&r2=203598&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Tue Mar 11 13:56:18 2014
@@ -415,7 +415,9 @@ bool ObjCInterfaceDecl::inheritsDesignat
void ObjCInterfaceDecl::getDesignatedInitializers(
llvm::SmallVectorImpl<const ObjCMethodDecl *> &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::getDesignatedIni
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::setExternallyCom
}
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();
Modified: cfe/trunk/test/SemaObjC/attr-designated-init.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/attr-designated-init.m?rev=203598&r1=203597&r2=203598&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/attr-designated-init.m (original)
+++ cfe/trunk/test/SemaObjC/attr-designated-init.m Tue Mar 11 13:56:18 2014
@@ -238,3 +238,13 @@ __attribute__((objc_root_class))
return 0;
}
@end
+
+// rdar://16261494
+ at class GEOPDAnalyticMetadata; // expected-note {{forward declaration of class here}}
+
+ at implementation GEOPDAnalyticMetadata (PlaceCardExtras) // expected-error {{cannot find interface declaration for 'GEOPDAnalyticMetadata'}}
+- (instancetype)initInProcess
+{
+ return ((void*)0);
+}
+ at end
More information about the cfe-commits
mailing list