r372039 - [Modules][Objective-C] Use complete decl from module when diagnosing missing import
Bruno Cardoso Lopes via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 16 15:00:29 PDT 2019
Author: bruno
Date: Mon Sep 16 15:00:29 2019
New Revision: 372039
URL: http://llvm.org/viewvc/llvm-project?rev=372039&view=rev
Log:
[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
Added:
cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/
cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/
cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/
cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/Bar.h
cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/Foo.h
cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Modules/
cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Modules/module.modulemap
cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/PrivateHeaders/
cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/PrivateHeaders/RandoPriv.h
cfe/trunk/test/Modules/interface-diagnose-missing-import.m
Modified:
cfe/trunk/lib/Sema/SemaLookup.cpp
Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=372039&r1=372038&r2=372039&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Mon Sep 16 15:00:29 2019
@@ -5273,8 +5273,11 @@ static NamedDecl *getDefinitionToImport(
return FD->getDefinition();
if (TagDecl *TD = dyn_cast<TagDecl>(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<ObjCInterfaceDecl>(D))
- return ID->getDefinition();
+ return ID;
if (ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(D))
return PD->getDefinition();
if (TemplateDecl *TD = dyn_cast<TemplateDecl>(D))
Added: cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/Bar.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/Bar.h?rev=372039&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/Bar.h (added)
+++ cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/Bar.h Mon Sep 16 15:00:29 2019
@@ -0,0 +1 @@
+// interface-diagnose-missing-import/Foo.framework/Headers/Bar.h
Added: cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/Foo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/Foo.h?rev=372039&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/Foo.h (added)
+++ cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/Foo.h Mon Sep 16 15:00:29 2019
@@ -0,0 +1,2 @@
+#import <Foo/RandoPriv.h>
+#import <Foo/Bar.h>
Added: cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Modules/module.modulemap
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Modules/module.modulemap?rev=372039&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Modules/module.modulemap (added)
+++ cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Modules/module.modulemap Mon Sep 16 15:00:29 2019
@@ -0,0 +1,6 @@
+// interface-diagnose-missing-import/Foo.framework/Modules/module.modulemap
+framework module Foo {
+ umbrella header "Foo.h"
+ export *
+ module * { export * }
+}
Added: cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/PrivateHeaders/RandoPriv.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/PrivateHeaders/RandoPriv.h?rev=372039&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/PrivateHeaders/RandoPriv.h (added)
+++ cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/PrivateHeaders/RandoPriv.h Mon Sep 16 15:00:29 2019
@@ -0,0 +1,4 @@
+ at interface NSObject
+ at end
+ at interface Buggy : NSObject
+ at end
Added: cfe/trunk/test/Modules/interface-diagnose-missing-import.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/interface-diagnose-missing-import.m?rev=372039&view=auto
==============================================================================
--- cfe/trunk/test/Modules/interface-diagnose-missing-import.m (added)
+++ cfe/trunk/test/Modules/interface-diagnose-missing-import.m Mon Sep 16 15:00:29 2019
@@ -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
+ at interface Buggy
+ at end
+
+ at import Foo.Bar;
+
+ at interface Buggy (MyExt) // expected-error {{definition of 'Buggy' must be imported from module 'Foo' before it is required}}
+ at end
+
+// expected-note at Foo/RandoPriv.h:3{{previous definition is here}}
More information about the cfe-commits
mailing list