Author: mren Date: Mon Oct 3 16:26:46 2016 New Revision: 283145 URL: http://llvm.org/viewvc/llvm-project?rev=283145&view=rev Log: ObjectiveC: fix a seg fault when deserialing redeclaration of ObjCMethodDecl.
The deserialization of redeclartion can cause seg fault since getCanonicalDecl of the redeclaration returns the lookup result on the ObjCContainerDecl, which can be null if FindExternalVisibleDeclsByName is not done updating the lookup results. The fix is to return the redeclaration itself as the canonical decl. Note that the handling for redeclaration of ObjCMethodDecl is not in line with other redeclarables. rdar://28488466 Added: cfe/trunk/test/Modules/Inputs/objc-method-redecl.h cfe/trunk/test/Modules/objc-method-redecl.m Modified: cfe/trunk/lib/AST/DeclObjC.cpp Modified: cfe/trunk/lib/AST/DeclObjC.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=283145&r1=283144&r2=283145&view=diff ============================================================================== --- cfe/trunk/lib/AST/DeclObjC.cpp (original) +++ cfe/trunk/lib/AST/DeclObjC.cpp Mon Oct 3 16:26:46 2016 @@ -897,9 +897,13 @@ ObjCMethodDecl *ObjCMethodDecl::getCanon return MD; } - if (isRedeclaration()) - return cast<ObjCContainerDecl>(CtxD)->getMethod(getSelector(), - isInstanceMethod()); + if (isRedeclaration()) { + // It is possible that we have not done deserializing the ObjCMethod yet. + ObjCMethodDecl *MD = + cast<ObjCContainerDecl>(CtxD)->getMethod(getSelector(), + isInstanceMethod()); + return MD ? MD : this; + } return this; } Added: cfe/trunk/test/Modules/Inputs/objc-method-redecl.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/objc-method-redecl.h?rev=283145&view=auto ============================================================================== --- cfe/trunk/test/Modules/Inputs/objc-method-redecl.h (added) +++ cfe/trunk/test/Modules/Inputs/objc-method-redecl.h Mon Oct 3 16:26:46 2016 @@ -0,0 +1,4 @@ +@interface T +- (void)test; +- (void)test; +@end Added: cfe/trunk/test/Modules/objc-method-redecl.m URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/objc-method-redecl.m?rev=283145&view=auto ============================================================================== --- cfe/trunk/test/Modules/objc-method-redecl.m (added) +++ cfe/trunk/test/Modules/objc-method-redecl.m Mon Oct 3 16:26:46 2016 @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -x objective-c-header -emit-pch %S/Inputs/objc-method-redecl.h -o %t.pch -Wno-objc-root-class +// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -x objective-c -include-pch %t.pch %s -verify -Wno-objc-root-class +// expected-no-diagnostics + +@implementation T +- (void)test { +} +@end _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits