From: Ted Kremenek Date: Thu, 18 Mar 2010 21:23:08 +0000 (+0000) Subject: Make PredefinedExpr::ComputeName() more robust to incorrect X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b03d33edaf24af2893a50caee4d2c99839242c44;p=clang Make PredefinedExpr::ComputeName() more robust to incorrect code when we are printing the name of an Objective-C method whose class has not been declared. Fixes . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@98874 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index a62dbc9012..6a71e925d9 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -227,7 +227,12 @@ std::string PredefinedExpr::ComputeName(IdentType IT, const Decl *CurrentDecl) { llvm::raw_svector_ostream Out(Name); Out << (MD->isInstanceMethod() ? '-' : '+'); Out << '['; - Out << MD->getClassInterface()->getNameAsString(); + + // For incorrect code, there might not be an ObjCInterfaceDecl. Do + // a null check to avoid a crash. + if (const ObjCInterfaceDecl *ID = MD->getClassInterface()) + Out << ID->getNameAsString(); + if (const ObjCCategoryImplDecl *CID = dyn_cast(MD->getDeclContext())) { Out << '('; diff --git a/test/SemaObjC/invalid-code.m b/test/SemaObjC/invalid-code.m index 9913a3a237..2f297cf6e6 100644 --- a/test/SemaObjC/invalid-code.m +++ b/test/SemaObjC/invalid-code.m @@ -5,3 +5,10 @@ void test1() { void *p = @1; // expected-error {{unexpected '@' in program}} } +// +// This previously triggered a crash because the class has not been defined. +@implementation RDar7495713 (rdar_7495713_cat) // expected-error{{cannot find interface declaration for 'RDar7495713'}} +- (id) rdar_7495713 { + __PRETTY_FUNCTION__; // expected-warning{{expression result unused}} +} +@end