Skip to content

Commit 919fc50

Browse files
committed
[Modules][Objective-C] Use complete decl from module when diagnosing missing import
Summary: Otherwise the definition (first found) for ObjCInterfaceDecl's might precede the module one, which will eventually lead to crash, since diagnoseMissingImport needs one coming from a module. This behavior changed after Richard's r342018, which started to look into the definition of ObjCInterfaceDecls. rdar://problem/49237144 Reviewers: rsmith, arphaman Subscribers: jkorous, dexonsmith, ributzka, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66982 llvm-svn: 372039
1 parent 155a43e commit 919fc50

File tree

6 files changed

+28
-1
lines changed

6 files changed

+28
-1
lines changed

clang/lib/Sema/SemaLookup.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5273,8 +5273,11 @@ static NamedDecl *getDefinitionToImport(NamedDecl *D) {
52735273
return FD->getDefinition();
52745274
if (TagDecl *TD = dyn_cast<TagDecl>(D))
52755275
return TD->getDefinition();
5276+
// The first definition for this ObjCInterfaceDecl might be in the TU
5277+
// and not associated with any module. Use the one we know to be complete
5278+
// and have just seen in a module.
52765279
if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D))
5277-
return ID->getDefinition();
5280+
return ID;
52785281
if (ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(D))
52795282
return PD->getDefinition();
52805283
if (TemplateDecl *TD = dyn_cast<TemplateDecl>(D))
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// interface-diagnose-missing-import/Foo.framework/Headers/Bar.h
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#import <Foo/RandoPriv.h>
2+
#import <Foo/Bar.h>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// interface-diagnose-missing-import/Foo.framework/Modules/module.modulemap
2+
framework module Foo {
3+
umbrella header "Foo.h"
4+
export *
5+
module * { export * }
6+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@interface NSObject
2+
@end
3+
@interface Buggy : NSObject
4+
@end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: rm -rf %t
2+
// RUN: %clang_cc1 %s -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -F%S/Inputs/interface-diagnose-missing-import -verify
3+
@interface Buggy
4+
@end
5+
6+
@import Foo.Bar;
7+
8+
@interface Buggy (MyExt) // expected-error {{definition of 'Buggy' must be imported from module 'Foo' before it is required}}
9+
@end
10+
11+
// expected-note@Foo/RandoPriv.h:3{{previous definition is here}}

0 commit comments

Comments
 (0)