From: Bruno Cardoso Lopes Date: Mon, 16 Sep 2019 22:00:29 +0000 (+0000) Subject: [Modules][Objective-C] Use complete decl from module when diagnosing missing import X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5f5c648f246380ad993069c4993fdae73a3002e8;p=clang [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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@372039 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index 8382527578..e960057725 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -5273,8 +5273,11 @@ static NamedDecl *getDefinitionToImport(NamedDecl *D) { return FD->getDefinition(); if (TagDecl *TD = dyn_cast(D)) return TD->getDefinition(); + // The first definition for this ObjCInterfaceDecl might be in the TU + // and not associated with any module. Use the one we know to be complete + // and have just seen in a module. if (ObjCInterfaceDecl *ID = dyn_cast(D)) - return ID->getDefinition(); + return ID; if (ObjCProtocolDecl *PD = dyn_cast(D)) return PD->getDefinition(); if (TemplateDecl *TD = dyn_cast(D)) diff --git a/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/Bar.h b/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/Bar.h new file mode 100644 index 0000000000..3ce482e6f2 --- /dev/null +++ b/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/Bar.h @@ -0,0 +1 @@ +// interface-diagnose-missing-import/Foo.framework/Headers/Bar.h diff --git a/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/Foo.h b/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/Foo.h new file mode 100644 index 0000000000..c9c40986d9 --- /dev/null +++ b/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/Foo.h @@ -0,0 +1,2 @@ +#import +#import diff --git a/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Modules/module.modulemap b/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Modules/module.modulemap new file mode 100644 index 0000000000..ebb4fa6e90 --- /dev/null +++ b/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Modules/module.modulemap @@ -0,0 +1,6 @@ +// interface-diagnose-missing-import/Foo.framework/Modules/module.modulemap +framework module Foo { + umbrella header "Foo.h" + export * + module * { export * } +} diff --git a/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/PrivateHeaders/RandoPriv.h b/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/PrivateHeaders/RandoPriv.h new file mode 100644 index 0000000000..3e195fd85b --- /dev/null +++ b/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/PrivateHeaders/RandoPriv.h @@ -0,0 +1,4 @@ +@interface NSObject +@end +@interface Buggy : NSObject +@end diff --git a/test/Modules/interface-diagnose-missing-import.m b/test/Modules/interface-diagnose-missing-import.m new file mode 100644 index 0000000000..5bbac36423 --- /dev/null +++ b/test/Modules/interface-diagnose-missing-import.m @@ -0,0 +1,11 @@ +// RUN: rm -rf %t +// RUN: %clang_cc1 %s -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -F%S/Inputs/interface-diagnose-missing-import -verify +@interface Buggy +@end + +@import Foo.Bar; + +@interface Buggy (MyExt) // expected-error {{definition of 'Buggy' must be imported from module 'Foo' before it is required}} +@end + +// expected-note@Foo/RandoPriv.h:3{{previous definition is here}}