Skip to content

Commit 22c8171

Browse files
authored
Merge pull request #1929 from bnbarham/benb/cherry-pick-fbb499e
[AST] Fix crashes caused by redeclarations in hidden prototypes
2 parents c17f50a + faaf4b9 commit 22c8171

File tree

5 files changed

+37
-4
lines changed

5 files changed

+37
-4
lines changed

clang/lib/AST/DeclObjC.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,8 @@ ObjCMethodDecl *ObjCMethodDecl::getNextRedeclarationImpl() {
949949
if (!Redecl && isRedeclaration()) {
950950
// This is the last redeclaration, go back to the first method.
951951
return cast<ObjCContainerDecl>(CtxD)->getMethod(getSelector(),
952-
isInstanceMethod());
952+
isInstanceMethod(),
953+
/*AllowHidden=*/true);
953954
}
954955

955956
return Redecl ? Redecl : this;
@@ -982,7 +983,8 @@ ObjCMethodDecl *ObjCMethodDecl::getCanonicalDecl() {
982983
if (isRedeclaration()) {
983984
// It is possible that we have not done deserializing the ObjCMethod yet.
984985
ObjCMethodDecl *MD =
985-
cast<ObjCContainerDecl>(CtxD)->getMethod(Sel, isInstanceMethod());
986+
cast<ObjCContainerDecl>(CtxD)->getMethod(Sel, isInstanceMethod(),
987+
/*AllowHidden=*/true);
986988
return MD ? MD : this;
987989
}
988990

@@ -1299,8 +1301,9 @@ void ObjCMethodDecl::getOverriddenMethods(
12991301
const ObjCMethodDecl *Method = this;
13001302

13011303
if (Method->isRedeclaration()) {
1302-
Method = cast<ObjCContainerDecl>(Method->getDeclContext())->
1303-
getMethod(Method->getSelector(), Method->isInstanceMethod());
1304+
Method = cast<ObjCContainerDecl>(Method->getDeclContext())
1305+
->getMethod(Method->getSelector(), Method->isInstanceMethod(),
1306+
/*AllowHidden=*/true);
13041307
}
13051308

13061309
if (Method->isOverriding()) {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@protocol P1
2+
- (void)p1_method;
3+
- (void)p1_method;
4+
@end
5+
6+
@interface Foo (SubP1) <P1>
7+
@end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@interface Foo
2+
- (void)parent_method;
3+
@end

clang/test/Index/Inputs/module.map

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,11 @@ module PreambleWithImplicitImport {
2020
export *
2121
}
2222
}
23+
24+
module hidden_redecls {
25+
header "hidden-redecls.h"
26+
27+
explicit module sub {
28+
header "hidden-redecls-sub.h"
29+
}
30+
}

clang/test/Index/hidden-redecls.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@import hidden_redecls;
2+
3+
@interface Foo (Top)
4+
- (void)top_method;
5+
@end
6+
7+
// p1_method in protocol P1 is hidden since module_redecls.sub hasn't been
8+
// imported yet. Check it is still indexed.
9+
10+
// RUN: c-index-test -index-file-full %s -isystem %S/Inputs -fmodules -target x86_64-apple-macosx10.7 | FileCheck %s
11+
// CHECK: [indexDeclaration]: kind: objc-instance-method | name: p1_method | {{.*}} | loc: {{.*}}hidden-redecls-sub.h:2:9 | {{.*}} | isRedecl: 0
12+
// CHECK: [indexDeclaration]: kind: objc-instance-method | name: p1_method | {{.*}} | loc: {{.*}}hidden-redecls-sub.h:3:9 | {{.*}} | isRedecl: 1

0 commit comments

Comments
 (0)