Skip to content

Commit

Permalink
Don't diagnose non-modular includes when we are not compiling a module.
Browse files Browse the repository at this point in the history
This is triggered when we are compiling an implementation of a module,
it has relative includes to a VFS-mapped module with umbrella headers.
Currently we will find the real path to headers under the umbrella directory,
but the umbrella directories are using virtual path.

rdar://27951255

Thanks Ben and Richard for reviewing the patch!
Differential Revision: http://reviews.llvm.org/D23858


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@279838 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
manman-ren committed Aug 26, 2016
1 parent 216f664 commit 5423d8c
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/Lex/ModuleMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,9 @@ void ModuleMap::diagnoseHeaderInclusion(Module *RequestingModule,
if (LangOpts.ModulesStrictDeclUse) {
Diags.Report(FilenameLoc, diag::err_undeclared_use_of_module)
<< RequestingModule->getFullModuleName() << Filename;
} else if (RequestingModule && RequestingModuleIsModuleInterface) {
} else if (RequestingModule && RequestingModuleIsModuleInterface &&
LangOpts.isCompilingModule()) {
// Do not diagnose when we are not compiling a module.
diag::kind DiagID = RequestingModule->getTopLevelModule()->IsFramework ?
diag::warn_non_modular_include_in_framework_module :
diag::warn_non_modular_include_in_module;
Expand Down
1 change: 1 addition & 0 deletions test/VFS/Inputs/Nonmodular/A.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// A.h
5 changes: 5 additions & 0 deletions test/VFS/Inputs/Nonmodular/Nonmodular.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
framework module Nonmodular [extern_c] {
umbrella header "umbrella.h"
export *
module * { export * }
}
34 changes: 34 additions & 0 deletions test/VFS/Inputs/Nonmodular/nonmodular-headers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
'version': 0,
'case-sensitive': 'false',
'ignore-non-existent-contents': 'true',
'roots': [
{
'type': 'directory',
'name': "VDIR/Nonmodular.framework/Headers",
'contents': [
{
'type': 'file',
'name': "umbrella.h",
'external-contents': "IN_DIR/Inputs/Nonmodular/umbrella.h"
},
{
'type': 'file',
'name': "A.h",
'external-contents': "IN_DIR/Inputs/Nonmodular/A.h"
}
]
},
{
'type': 'directory',
'name': "VDIR/Nonmodular.framework/Modules",
'contents': [
{
'type': 'file',
'name': "module.modulemap",
'external-contents': "OUT_DIR/module.modulemap"
}
]
}
]
}
3 changes: 3 additions & 0 deletions test/VFS/Inputs/Nonmodular/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// expected-no-diagnostics

#include "umbrella.h"
5 changes: 5 additions & 0 deletions test/VFS/Inputs/Nonmodular/umbrella.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#ifndef __umbrella_h__
#define __umbrella_h__

#include <Nonmodular/A.h>
#endif
11 changes: 11 additions & 0 deletions test/VFS/test_nonmodular.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// REQUIRES: shell

// RUN: rm -rf %t
// RUN: mkdir -p %t/vdir %t/cache %t/outdir
// We can't have module.map inside Inputs/Nonmodular.
// RUN: cp %S/Inputs/Nonmodular/Nonmodular.modulemap %t/outdir/module.modulemap
//
// RUN: sed -e "s:VDIR:%t/vdir:g" -e "s:IN_DIR:%S:g" -e "s:OUT_DIR:%t/outdir:g" %S/Inputs/Nonmodular/nonmodular-headers.yaml > %t/vdir/nonmodular-headers.yaml
// RUN: %clang_cc1 -fmodule-name=Nonmodular -fmodules -Wnon-modular-include-in-framework-module -verify -fimplicit-module-maps -fmodules-cache-path=%t/cache -ivfsoverlay %t/vdir/nonmodular-headers.yaml -I %S/Inputs -F %t/vdir -fsyntax-only %S/Inputs/Nonmodular/test.c

// expected-no-diagnostics

0 comments on commit 5423d8c

Please sign in to comment.