From a0042c4922681d5a8c667b4607cb0b41478f5389 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 llvm-svn: 283145 --- clang/lib/AST/DeclObjC.cpp | 10 +++++++--- clang/test/Modules/Inputs/objc-method-redecl.h | 4 ++++ clang/test/Modules/objc-method-redecl.m | 8 ++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 clang/test/Modules/Inputs/objc-method-redecl.h create mode 100644 clang/test/Modules/objc-method-redecl.m diff --git a/clang/lib/AST/DeclObjC.cpp b/clang/lib/AST/DeclObjC.cpp index 47e032a..fdbac00 100644 --- a/clang/lib/AST/DeclObjC.cpp +++ b/clang/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/clang/test/Modules/Inputs/objc-method-redecl.h b/clang/test/Modules/Inputs/objc-method-redecl.h new file mode 100644 index 0000000..95c6533 --- /dev/null +++ b/clang/test/Modules/Inputs/objc-method-redecl.h @@ -0,0 +1,4 @@ +@interface T +- (void)test; +- (void)test; +@end diff --git a/clang/test/Modules/objc-method-redecl.m b/clang/test/Modules/objc-method-redecl.m new file mode 100644 index 0000000..f7acda5 --- /dev/null +++ b/clang/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.7.4