From 4abceaa6304777435caf488959f6d8a1f8d9270a Mon Sep 17 00:00:00 2001 From: Manman Ren Date: Mon, 3 Oct 2016 21:26:46 +0000 Subject: [PATCH] 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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@283145 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/DeclObjC.cpp | 10 +++++++--- test/Modules/Inputs/objc-method-redecl.h | 4 ++++ test/Modules/objc-method-redecl.m | 8 ++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 test/Modules/Inputs/objc-method-redecl.h create mode 100644 test/Modules/objc-method-redecl.m diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp index 47e032a2e5..fdbac00fc9 100644 --- a/lib/AST/DeclObjC.cpp +++ b/lib/AST/DeclObjC.cpp @@ -897,9 +897,13 @@ ObjCMethodDecl *ObjCMethodDecl::getCanonicalDecl() { return MD; } - if (isRedeclaration()) - return cast(CtxD)->getMethod(getSelector(), - isInstanceMethod()); + if (isRedeclaration()) { + // It is possible that we have not done deserializing the ObjCMethod yet. + ObjCMethodDecl *MD = + cast(CtxD)->getMethod(getSelector(), + isInstanceMethod()); + return MD ? MD : this; + } return this; } diff --git a/test/Modules/Inputs/objc-method-redecl.h b/test/Modules/Inputs/objc-method-redecl.h new file mode 100644 index 0000000000..95c6533fad --- /dev/null +++ b/test/Modules/Inputs/objc-method-redecl.h @@ -0,0 +1,4 @@ +@interface T +- (void)test; +- (void)test; +@end diff --git a/test/Modules/objc-method-redecl.m b/test/Modules/objc-method-redecl.m new file mode 100644 index 0000000000..f7acda5450 --- /dev/null +++ b/test/Modules/objc-method-redecl.m @@ -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 -- 2.40.0