[modules] Don't diagnose non-modular includes from modular files that are

implementation units of modules rather than interface units.

llvm-svn: 263449
This commit is contained in:
Richard Smith 2016-03-14 17:52:37 +00:00
parent 5719584129
commit 8d4e90b319
5 changed files with 23 additions and 4 deletions

View File

@ -313,12 +313,18 @@ public:
///
/// \param RequestingModule The module including a file.
///
/// \param RequestingModuleIsModuleInterface \c true if the inclusion is in
/// the interface of RequestingModule, \c false if it's in the
/// implementation of RequestingModule. Value is ignored and
/// meaningless if RequestingModule is nullptr.
///
/// \param FilenameLoc The location of the inclusion's filename.
///
/// \param Filename The included filename as written.
///
/// \param File The included file.
void diagnoseHeaderInclusion(Module *RequestingModule,
bool RequestingModuleIsModuleInterface,
SourceLocation FilenameLoc, StringRef Filename,
const FileEntry *File);

View File

@ -239,6 +239,7 @@ static Module *getTopLevelOrNull(Module *M) {
}
void ModuleMap::diagnoseHeaderInclusion(Module *RequestingModule,
bool RequestingModuleIsModuleInterface,
SourceLocation FilenameLoc,
StringRef Filename,
const FileEntry *File) {
@ -301,7 +302,7 @@ void ModuleMap::diagnoseHeaderInclusion(Module *RequestingModule,
if (LangOpts.ModulesStrictDeclUse) {
Diags.Report(FilenameLoc, diag::err_undeclared_use_of_module)
<< RequestingModule->getFullModuleName() << Filename;
} else if (RequestingModule) {
} else if (RequestingModule && RequestingModuleIsModuleInterface) {
diag::kind DiagID = RequestingModule->getTopLevelModule()->IsFramework ?
diag::warn_non_modular_include_in_framework_module :
diag::warn_non_modular_include_in_module;

View File

@ -609,6 +609,7 @@ const FileEntry *Preprocessor::LookupFile(
ModuleMap::KnownHeader *SuggestedModule,
bool SkipCache) {
Module *RequestingModule = getModuleForLocation(FilenameLoc);
bool RequestingModuleIsModuleInterface = !SourceMgr.isInMainFile(FilenameLoc);
// If the header lookup mechanism may be relative to the current inclusion
// stack, record the parent #includes.
@ -683,7 +684,8 @@ const FileEntry *Preprocessor::LookupFile(
if (FE) {
if (SuggestedModule && !LangOpts.AsmPreprocessor)
HeaderInfo.getModuleMap().diagnoseHeaderInclusion(
RequestingModule, FilenameLoc, Filename, FE);
RequestingModule, RequestingModuleIsModuleInterface, FilenameLoc,
Filename, FE);
return FE;
}
@ -699,7 +701,8 @@ const FileEntry *Preprocessor::LookupFile(
SuggestedModule))) {
if (SuggestedModule && !LangOpts.AsmPreprocessor)
HeaderInfo.getModuleMap().diagnoseHeaderInclusion(
RequestingModule, FilenameLoc, Filename, FE);
RequestingModule, RequestingModuleIsModuleInterface, FilenameLoc,
Filename, FE);
return FE;
}
}
@ -714,7 +717,8 @@ const FileEntry *Preprocessor::LookupFile(
RequestingModule, SuggestedModule))) {
if (SuggestedModule && !LangOpts.AsmPreprocessor)
HeaderInfo.getModuleMap().diagnoseHeaderInclusion(
RequestingModule, FilenameLoc, Filename, FE);
RequestingModule, RequestingModuleIsModuleInterface,
FilenameLoc, Filename, FE);
return FE;
}
}

View File

@ -0,0 +1,4 @@
#ifndef NON_MODULE_H
#define NON_MODULE_H
#endif

View File

@ -0,0 +1,4 @@
// RUN: rm -rf %t
// RUN: %clang_cc1 -fmodules -fmodule-name=Module -fimplicit-module-maps -fmodules-cache-path=%t -Werror=non-modular-include-in-framework-module -F%S/Inputs -I%S -fsyntax-only %s
#include "Module/Module.h"
#include "Inputs/non-module.h"