"test module file extension '%0' has different version (%1.%2) than expected "
"(%3.%4)">;
-def err_conflicting_module_names : Error<
- "conflicting module names specified: '-fmodule-name=%0' and "
- "'-fmodule-implementation-of %1'">;
-
def err_missing_vfs_overlay_file : Error<
"virtual filesystem overlay file '%0' not found">, DefaultFatal;
def err_invalid_vfs_overlay : Error<
LANGOPT(MathErrno , 1, 1, "errno support for math functions")
BENIGN_LANGOPT(HeinousExtensions , 1, 0, "Extensions that we really don't like and may be ripped out at any time")
LANGOPT(Modules , 1, 0, "modules extension to C")
+BENIGN_LANGOPT(CompilingModule, 1, 0, "compiling a module interface")
COMPATIBLE_LANGOPT(ModulesDeclUse , 1, 0, "require declaration of module uses")
LANGOPT(ModulesSearchAll , 1, 1, "search even non-imported modules to find unresolved references")
COMPATIBLE_LANGOPT(ModulesStrictDeclUse, 1, 0, "require declaration of module uses and all headers to be in modules")
/// If none is specified, abort (GCC-compatible behaviour).
std::string OverflowHandler;
- /// \brief The name of the current module.
+ /// \brief The name of the current module, of which the main source file
+ /// is a part. If CompilingModule is set, we are compiling the interface
+ /// of this module, otherwise we are compiling an implementation file of
+ /// it.
std::string CurrentModule;
- /// \brief The name of the module that the translation unit is an
- /// implementation of. Prevents semantic imports, but does not otherwise
- /// treat this as the CurrentModule.
- std::string ImplementationOfModule;
-
/// \brief The names of any features to enable in module 'requires' decls
/// in addition to the hard-coded list in Module.cpp and the target features.
///
HelpText<"Do not automatically generate or update the global module index">;
def fno_modules_error_recovery : Flag<["-"], "fno-modules-error-recovery">,
HelpText<"Do not automatically import modules for error recovery">;
-def fmodule_implementation_of : Separate<["-"], "fmodule-implementation-of">,
- MetaVarName<"<name>">,
- HelpText<"Specify the name of the module whose implementation file this is">;
def fmodule_map_file_home_is_cwd : Flag<["-"], "fmodule-map-file-home-is-cwd">,
HelpText<"Use the current working directory as the home directory of "
"module maps specified by -fmodule-map-file=<FILE>">;
Flags<[DriverOption, CC1Option]>,
HelpText<"Implicitly search the file system for module map files.">;
def fmodule_maps : Flag <["-"], "fmodule-maps">, Alias<fimplicit_module_maps>;
-def fmodule_name : JoinedOrSeparate<["-"], "fmodule-name=">, Group<f_Group>,
+def fmodule_name_EQ : Joined<["-"], "fmodule-name=">, Group<f_Group>,
Flags<[DriverOption,CC1Option]>, MetaVarName<"<name>">,
HelpText<"Specify the name of the module to build">;
+def fmodule_name : Separate<["-"], "fmodule-name">, Alias<fmodule_name_EQ>;
def fmodule_map_file : Joined<["-"], "fmodule-map-file=">,
Group<f_Group>, Flags<[DriverOption,CC1Option]>, MetaVarName<"<file>">,
HelpText<"Load this module map file">;
/// These are always simple C language options.
LangOptions MMapLangOpts;
- // The module that we are building; related to \c LangOptions::CurrentModule.
- Module *CompilingModule;
-
-public:
- // The module that the .cc source file is associated with.
+ // The module that the main source file is associated with (the module
+ // named LangOpts::CurrentModule, if we've loaded it).
Module *SourceModule;
- std::string SourceModuleName;
-private:
/// \brief The top-level modules that are known.
llvm::StringMap<Module *> Modules;
SanitizerBlacklistFiles.clear();
CurrentModule.clear();
- ImplementationOfModule.clear();
}
bool LangOptions::isNoBuiltinFunc(const char *Name) const {
// -fmodule-name specifies the module that is currently being built (or
// used for header checking by -fmodule-maps).
- Args.AddLastArg(CmdArgs, options::OPT_fmodule_name);
+ Args.AddLastArg(CmdArgs, options::OPT_fmodule_name_EQ);
// -fmodule-map-file can be used to specify files containing module
// definitions.
}
bool ASTUnit::isModuleFile() {
- return isMainFileAST() && !ASTFileLangOpts.CurrentModule.empty();
+ return isMainFileAST() && ASTFileLangOpts.CompilingModule;
}
void ASTUnit::PreambleData::countLines() const {
// when both the preprocessor and parser see the same import declaration.
if (ImportLoc.isValid() && LastModuleImportLoc == ImportLoc) {
// Make the named module visible.
- if (LastModuleImportResult && ModuleName != getLangOpts().CurrentModule &&
- ModuleName != getLangOpts().ImplementationOfModule)
+ if (LastModuleImportResult && ModuleName != getLangOpts().CurrentModule)
ModuleManager->makeModuleVisible(LastModuleImportResult, Visibility,
ImportLoc);
return LastModuleImportResult;
if (Known != KnownModules.end()) {
// Retrieve the cached top-level module.
Module = Known->second;
- } else if (ModuleName == getLangOpts().CurrentModule ||
- ModuleName == getLangOpts().ImplementationOfModule) {
+ } else if (ModuleName == getLangOpts().CurrentModule) {
// This is the module we're building.
Module = PP->getHeaderSearchInfo().lookupModule(ModuleName);
Known = KnownModules.insert(std::make_pair(Path[0].first, Module)).first;
}
}
- // Don't make the module visible if we are in the implementation.
- if (ModuleName == getLangOpts().ImplementationOfModule)
- return ModuleLoadResult(Module, false);
-
// Make the named module visible, if it's not already part of the module
// we are parsing.
if (ModuleName != getLangOpts().CurrentModule) {
Opts.DebuggerCastResultToId = Args.hasArg(OPT_fdebugger_cast_result_to_id);
Opts.DebuggerObjCLiteral = Args.hasArg(OPT_fdebugger_objc_literal);
Opts.ApplePragmaPack = Args.hasArg(OPT_fapple_pragma_pack);
- Opts.CurrentModule = Args.getLastArgValue(OPT_fmodule_name);
+ Opts.CurrentModule = Args.getLastArgValue(OPT_fmodule_name_EQ);
Opts.AppExt = Args.hasArg(OPT_fapplication_extension);
- Opts.ImplementationOfModule =
- Args.getLastArgValue(OPT_fmodule_implementation_of);
Opts.ModuleFeatures = Args.getAllArgValues(OPT_fmodule_feature);
std::sort(Opts.ModuleFeatures.begin(), Opts.ModuleFeatures.end());
Opts.NativeHalfType |= Args.hasArg(OPT_fnative_half_type);
Args.hasFlag(OPT_fdeclspec, OPT_fno_declspec,
(Opts.MicrosoftExt || Opts.Borland || Opts.CUDA));
- if (!Opts.CurrentModule.empty() && !Opts.ImplementationOfModule.empty() &&
- Opts.CurrentModule != Opts.ImplementationOfModule) {
- Diags.Report(diag::err_conflicting_module_names)
- << Opts.CurrentModule << Opts.ImplementationOfModule;
- }
-
// For now, we only support local submodule visibility in C++ (because we
// heavily depend on the ODR for merging redefinitions).
if (Opts.ModulesLocalVisibility && !Opts.CPlusPlus)
bool GenerateModuleAction::BeginSourceFileAction(CompilerInstance &CI,
StringRef Filename) {
+ CI.getLangOpts().CompilingModule = true;
+
// Find the module map file.
const FileEntry *ModuleMap =
CI.getFileManager().getFile(Filename, /*openFile*/true);
HeaderSearch &HeaderInfo)
: SourceMgr(SourceMgr), Diags(Diags), LangOpts(LangOpts), Target(Target),
HeaderInfo(HeaderInfo), BuiltinIncludeDir(nullptr),
- CompilingModule(nullptr), SourceModule(nullptr), NumCreatedModules(0) {
+ SourceModule(nullptr), NumCreatedModules(0) {
MMapLangOpts.LineComment = true;
}
ModuleMap::KnownHeader Result;
// Iterate over all modules that 'File' is part of to find the best fit.
for (KnownHeader &H : Known->second) {
- // Prefer a header from the current module over all others.
- if (H.getModule()->getTopLevelModule() == CompilingModule)
+ // Prefer a header from the source module over all others.
+ if (H.getModule()->getTopLevelModule() == SourceModule)
return MakeResult(H);
if (!Result || isBetterKnownHeader(H, Result))
Result = H;
// Create a new module with this name.
Module *Result = new Module(Name, SourceLocation(), Parent,
IsFramework, IsExplicit, NumCreatedModules++);
- if (LangOpts.CurrentModule == Name) {
- SourceModule = Result;
- SourceModuleName = Name;
- }
if (!Parent) {
+ if (LangOpts.CurrentModule == Name)
+ SourceModule = Result;
Modules[Name] = Result;
- if (!LangOpts.CurrentModule.empty() && !CompilingModule &&
- Name == LangOpts.CurrentModule) {
- CompilingModule = Result;
- }
}
return std::make_pair(Result, true);
}
NumCreatedModules++);
InferredModuleAllowedBy[Result] = ModuleMapFile;
Result->IsInferred = true;
- if (LangOpts.CurrentModule == ModuleName) {
- SourceModule = Result;
- SourceModuleName = ModuleName;
+ if (!Parent) {
+ if (LangOpts.CurrentModule == ModuleName)
+ SourceModule = Result;
+ Modules[ModuleName] = Result;
}
Result->IsSystem |= Attrs.IsSystem;
Result->ConfigMacrosExhaustive |= Attrs.IsExhaustive;
Result->Directory = FrameworkDir;
- if (!Parent)
- Modules[ModuleName] = Result;
-
// umbrella header "umbrella-header-name"
//
// The "Headers/" component of the name is implied because this is
HeaderList.push_back(KH);
Mod->Headers[headerRoleToKind(Role)].push_back(std::move(Header));
- bool isCompilingModuleHeader = Mod->getTopLevelModule() == CompilingModule;
+ bool isCompilingModuleHeader =
+ LangOpts.CompilingModule && Mod->getTopLevelModule() == SourceModule;
if (!Imported || isCompilingModuleHeader) {
// When we import HeaderFileInfo, the external source is expected to
// set the isModuleHeader flag itself.
}
Module *Preprocessor::getModuleForLocation(SourceLocation Loc) {
- ModuleMap &ModMap = HeaderInfo.getModuleMap();
- if (SourceMgr.isInMainFile(Loc)) {
- if (Module *CurMod = getCurrentModule())
- return CurMod; // Compiling a module.
- return HeaderInfo.getModuleMap().SourceModule; // Compiling a source.
- }
- // Try to determine the module of the include directive.
- // FIXME: Look into directly passing the FileEntry from LookupFile instead.
- FileID IDOfIncl = SourceMgr.getFileID(SourceMgr.getExpansionLoc(Loc));
- if (const FileEntry *EntryOfIncl = SourceMgr.getFileEntryForID(IDOfIncl)) {
- // The include comes from a file.
- return ModMap.findModuleForHeader(EntryOfIncl).getModule();
- } else {
- // The include does not come from a file,
- // so it is probably a module compilation.
- return getCurrentModule();
+ if (!SourceMgr.isInMainFile(Loc)) {
+ // Try to determine the module of the include directive.
+ // FIXME: Look into directly passing the FileEntry from LookupFile instead.
+ FileID IDOfIncl = SourceMgr.getFileID(SourceMgr.getExpansionLoc(Loc));
+ if (const FileEntry *EntryOfIncl = SourceMgr.getFileEntryForID(IDOfIncl)) {
+ // The include comes from an included file.
+ return HeaderInfo.getModuleMap()
+ .findModuleForHeader(EntryOfIncl)
+ .getModule();
+ }
}
+
+ // This is either in the main file or not in a file at all. It belongs
+ // to the current module, if there is one.
+ return getLangOpts().CurrentModule.empty()
+ ? nullptr
+ : HeaderInfo.lookupModule(getLangOpts().CurrentModule);
}
Module *Preprocessor::getModuleContainingLocation(SourceLocation Loc) {
// are processing this module textually (because we're building the module).
if (File && SuggestedModule && getLangOpts().Modules &&
SuggestedModule.getModule()->getTopLevelModuleName() !=
- getLangOpts().CurrentModule &&
- SuggestedModule.getModule()->getTopLevelModuleName() !=
- getLangOpts().ImplementationOfModule) {
-
+ getLangOpts().CurrentModule) {
// If this include corresponds to a module but that module is
// unavailable, diagnose the situation and bail out.
if (!SuggestedModule.getModule()->isAvailable()) {
return false;
}
- bool Result
- = Tok.getIdentifierInfo()->getName() == PP.getLangOpts().CurrentModule;
+ bool Result =
+ PP.getLangOpts().CompilingModule &&
+ Tok.getIdentifierInfo()->getName() == PP.getLangOpts().CurrentModule;
// Get ')'.
PP.LexNonComment(Tok);
}
Module *Preprocessor::getCurrentModule() {
- if (getLangOpts().CurrentModule.empty())
+ if (!getLangOpts().CompilingModule)
return nullptr;
return getHeaderSearchInfo().lookupModule(getLangOpts().CurrentModule);
// of the same top-level module. Until we do, make it an error rather than
// silently ignoring the import.
if (Mod->getTopLevelModuleName() == getLangOpts().CurrentModule)
- Diag(ImportLoc, diag::err_module_self_import)
+ Diag(ImportLoc, getLangOpts().CompilingModule
+ ? diag::err_module_self_import
+ : diag::err_module_import_in_implementation)
<< Mod->getFullModuleName() << getLangOpts().CurrentModule;
- else if (Mod->getTopLevelModuleName() == getLangOpts().ImplementationOfModule)
- Diag(ImportLoc, diag::err_module_import_in_implementation)
- << Mod->getFullModuleName() << getLangOpts().ImplementationOfModule;
SmallVector<SourceLocation, 2> IdentifierLocs;
Module *ModCheck = Mod;
TUKind == TU_Module &&
getSourceManager().isWrittenInMainFile(DirectiveLoc);
- // Similarly, if this module is specified by -fmodule-implementation-of
- // don't actually synthesize an illegal module import.
- bool ShouldAddImport = !IsInModuleIncludes &&
- (getLangOpts().ImplementationOfModule.empty() ||
- getLangOpts().ImplementationOfModule != Mod->getTopLevelModuleName());
+ // Similarly, if we're in the implementation of a module, don't
+ // synthesize an illegal module import. FIXME: Why not?
+ bool ShouldAddImport =
+ !IsInModuleIncludes &&
+ (getLangOpts().CompilingModule ||
+ getLangOpts().CurrentModule.empty() ||
+ getLangOpts().CurrentModule != Mod->getTopLevelModuleName());
// If this module import was due to an inclusion directive, create an
// implicit import declaration to capture it in the AST.
ObjCMethodList *Previous = List;
for (; List; Previous = List, List = List->getNext()) {
// If we are building a module, keep all of the methods.
- if (getLangOpts().Modules && !getLangOpts().CurrentModule.empty())
+ if (getLangOpts().CompilingModule)
continue;
if (!MatchTwoMethodDeclarations(Method, List->getMethod())) {
-#if !__building_module(a)
+#if !__building_module(a) && !BUILDING_A_PCH
#error "should only get here when building module a"
#endif
// -------------------------------
// Try to import a PCH with -fmodule-file=
// RUN: %clang_cc1 -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \
-// RUN: -fmodule-name=a -emit-pch %S/Inputs/explicit-build/a.h -o %t/a.pch \
+// RUN: -fmodule-name=a -emit-pch %S/Inputs/explicit-build/a.h -o %t/a.pch -DBUILDING_A_PCH \
// RUN: 2>&1 | FileCheck --check-prefix=CHECK-NO-IMPLICIT-BUILD %s --allow-empty
//
// RUN: not %clang_cc1 -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \
-// RUN: not %clang_cc1 -fmodule-implementation-of Foo -fmodule-name=Bar %s 2>&1 \
-// RUN: | FileCheck -check-prefix=CHECK-IMPL-OF-ERR %s
-// CHECK-IMPL-OF-ERR: conflicting module names specified: '-fmodule-name=Bar' and '-fmodule-implementation-of Foo'
-
// RUN: rm -rf %t
// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -w -Werror=auto-import %s -I %S/Inputs \
-// RUN: -fmodule-implementation-of category_right -fsyntax-only
+// RUN: -fmodule-name=category_right -fsyntax-only
// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -w -Werror=auto-import %s -I %S/Inputs \
-// RUN: -fmodule-implementation-of category_right -dM -E -o - 2>&1 | FileCheck %s
+// RUN: -fmodule-name=category_right -dM -E -o - 2>&1 | FileCheck %s
// CHECK-NOT: __building_module
// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -w -Werror=auto-import %s -I %S/Inputs \
-// RUN: -fmodule-implementation-of category_left -verify
+// RUN: -fmodule-name=category_left -verify
// RUN: %clang_cc1 -x objective-c-header -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -w -Werror=auto-import %s -I %S/Inputs \
-// RUN: -fmodule-implementation-of category_right -emit-pch -o %t.pch
+// RUN: -fmodule-name=category_right -emit-pch -o %t.pch
// RUN: %clang_cc1 -x objective-c-header -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -w -Werror=auto-import %s -I %S/Inputs \
-// RUN: -DWITH_PREFIX -fmodules-ignore-macro=WITH_PREFIX -include-pch %t.pch -fmodule-implementation-of category_right
+// RUN: -DWITH_PREFIX -fmodules-ignore-macro=WITH_PREFIX -include-pch %t.pch -fmodule-name=category_right
#ifndef WITH_PREFIX
// RUN: not %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t \
// RUN: -I %S/Inputs/submodules -fmodule-name=import_self %s \
// RUN: 2>&1 | FileCheck -check-prefix=CHECK-fmodule-name %s
-// CHECK-fmodule-name: import of module 'import_self.b' appears within same top-level module 'import_self'
+// CHECK-fmodule-name: @import of module 'import_self.b' in implementation of 'import_self'
@import import_self.b;