r261372 - [modules] Flatten -fmodule-name= and -fmodule-implementation-of= into a single

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 3 05:28:48 PST 2016


On 3 Mar 2016 3:18 a.m., "Argyrios Kyrtzidis via cfe-commits" <
cfe-commits at lists.llvm.org> wrote:
>
> Mind if we keep -fmodule-implementation-of as an alias so that we can
gradually transition to -fmodule-name ?

Sure, no problem.

> > On Feb 19, 2016, at 2:25 PM, Richard Smith via cfe-commits <
cfe-commits at lists.llvm.org> wrote:
> >
> > Author: rsmith
> > Date: Fri Feb 19 16:25:36 2016
> > New Revision: 261372
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=261372&view=rev
> > Log:
> > [modules] Flatten -fmodule-name= and -fmodule-implementation-of= into a
single
> > option. Previously these options could both be used to specify that you
were
> > compiling the implementation file of a module, with a different set of
minor
> > bugs in each case.
> >
> > This change removes -fmodule-implementation-of, and instead tracks a
flag to
> > determine whether we're currently building a module. -fmodule-name now
behaves
> > the same way that -fmodule-implementation-of previously did.
> >
> > Modified:
> >    cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
> >    cfe/trunk/include/clang/Basic/LangOptions.def
> >    cfe/trunk/include/clang/Basic/LangOptions.h
> >    cfe/trunk/include/clang/Driver/CC1Options.td
> >    cfe/trunk/include/clang/Driver/Options.td
> >    cfe/trunk/include/clang/Lex/ModuleMap.h
> >    cfe/trunk/lib/Basic/LangOptions.cpp
> >    cfe/trunk/lib/Driver/Tools.cpp
> >    cfe/trunk/lib/Frontend/ASTUnit.cpp
> >    cfe/trunk/lib/Frontend/CompilerInstance.cpp
> >    cfe/trunk/lib/Frontend/CompilerInvocation.cpp
> >    cfe/trunk/lib/Frontend/FrontendActions.cpp
> >    cfe/trunk/lib/Lex/ModuleMap.cpp
> >    cfe/trunk/lib/Lex/PPDirectives.cpp
> >    cfe/trunk/lib/Lex/PPMacroExpansion.cpp
> >    cfe/trunk/lib/Lex/Preprocessor.cpp
> >    cfe/trunk/lib/Sema/SemaDecl.cpp
> >    cfe/trunk/lib/Sema/SemaDeclObjC.cpp
> >    cfe/trunk/test/Modules/Inputs/explicit-build/a.h
> >    cfe/trunk/test/Modules/explicit-build.cpp
> >    cfe/trunk/test/Modules/implementation-of-module.m
> >    cfe/trunk/test/Modules/import-self.m
> >
> > Modified: cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
> > URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td?rev=261372&r1=261371&r2=261372&view=diff
> >
==============================================================================
> > --- cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td (original)
> > +++ cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td Fri Feb 19
16:25:36 2016
> > @@ -210,10 +210,6 @@ def err_test_module_file_extension_versi
> >   "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<
> >
> > Modified: cfe/trunk/include/clang/Basic/LangOptions.def
> > URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.def?rev=261372&r1=261371&r2=261372&view=diff
> >
==============================================================================
> > --- cfe/trunk/include/clang/Basic/LangOptions.def (original)
> > +++ cfe/trunk/include/clang/Basic/LangOptions.def Fri Feb 19 16:25:36
2016
> > @@ -127,6 +127,7 @@ BENIGN_LANGOPT(EmitAllDecls      , 1, 0,
> > 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")
> >
> > Modified: cfe/trunk/include/clang/Basic/LangOptions.h
> > URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.h?rev=261372&r1=261371&r2=261372&view=diff
> >
==============================================================================
> > --- cfe/trunk/include/clang/Basic/LangOptions.h (original)
> > +++ cfe/trunk/include/clang/Basic/LangOptions.h Fri Feb 19 16:25:36 2016
> > @@ -92,14 +92,12 @@ public:
> >   /// 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.
> >   ///
> >
> > Modified: cfe/trunk/include/clang/Driver/CC1Options.td
> > URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=261372&r1=261371&r2=261372&view=diff
> >
==============================================================================
> > --- cfe/trunk/include/clang/Driver/CC1Options.td (original)
> > +++ cfe/trunk/include/clang/Driver/CC1Options.td Fri Feb 19 16:25:36
2016
> > @@ -382,9 +382,6 @@ def fno_modules_global_index : Flag<["-"
> >   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>">;
> >
> > Modified: cfe/trunk/include/clang/Driver/Options.td
> > URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=261372&r1=261371&r2=261372&view=diff
> >
==============================================================================
> > --- cfe/trunk/include/clang/Driver/Options.td (original)
> > +++ cfe/trunk/include/clang/Driver/Options.td Fri Feb 19 16:25:36 2016
> > @@ -786,9 +786,10 @@ def fimplicit_module_maps : Flag <["-"],
> >   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">;
> >
> > Modified: cfe/trunk/include/clang/Lex/ModuleMap.h
> > URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/ModuleMap.h?rev=261372&r1=261371&r2=261372&view=diff
> >
==============================================================================
> > --- cfe/trunk/include/clang/Lex/ModuleMap.h (original)
> > +++ cfe/trunk/include/clang/Lex/ModuleMap.h Fri Feb 19 16:25:36 2016
> > @@ -70,15 +70,10 @@ class ModuleMap {
> >   /// 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;
> >
> >
> > Modified: cfe/trunk/lib/Basic/LangOptions.cpp
> > URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/LangOptions.cpp?rev=261372&r1=261371&r2=261372&view=diff
> >
==============================================================================
> > --- cfe/trunk/lib/Basic/LangOptions.cpp (original)
> > +++ cfe/trunk/lib/Basic/LangOptions.cpp Fri Feb 19 16:25:36 2016
> > @@ -34,7 +34,6 @@ void LangOptions::resetNonModularOptions
> >   SanitizerBlacklistFiles.clear();
> >
> >   CurrentModule.clear();
> > -  ImplementationOfModule.clear();
> > }
> >
> > bool LangOptions::isNoBuiltinFunc(const char *Name) const {
> >
> > Modified: cfe/trunk/lib/Driver/Tools.cpp
> > URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=261372&r1=261371&r2=261372&view=diff
> >
==============================================================================
> > --- cfe/trunk/lib/Driver/Tools.cpp (original)
> > +++ cfe/trunk/lib/Driver/Tools.cpp Fri Feb 19 16:25:36 2016
> > @@ -4909,7 +4909,7 @@ void Clang::ConstructJob(Compilation &C,
> >
> >   // -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.
> >
> > Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
> > URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=261372&r1=261371&r2=261372&view=diff
> >
==============================================================================
> > --- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
> > +++ cfe/trunk/lib/Frontend/ASTUnit.cpp Fri Feb 19 16:25:36 2016
> > @@ -2814,7 +2814,7 @@ const FileEntry *ASTUnit::getPCHFile() {
> > }
> >
> > bool ASTUnit::isModuleFile() {
> > -  return isMainFileAST() && !ASTFileLangOpts.CurrentModule.empty();
> > +  return isMainFileAST() && ASTFileLangOpts.CompilingModule;
> > }
> >
> > void ASTUnit::PreambleData::countLines() const {
> >
> > Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
> > URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=261372&r1=261371&r2=261372&view=diff
> >
==============================================================================
> > --- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
> > +++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Fri Feb 19 16:25:36 2016
> > @@ -1386,8 +1386,7 @@ CompilerInstance::loadModule(SourceLocat
> >   // 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;
> > @@ -1401,8 +1400,7 @@ CompilerInstance::loadModule(SourceLocat
> >   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;
> > @@ -1580,10 +1578,6 @@ CompilerInstance::loadModule(SourceLocat
> >     }
> >   }
> >
> > -  // 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) {
> >
> > Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
> > URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=261372&r1=261371&r2=261372&view=diff
> >
==============================================================================
> > --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
> > +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Fri Feb 19 16:25:36
2016
> > @@ -1763,10 +1763,8 @@ static void ParseLangArgs(LangOptions &O
> >   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);
> > @@ -1784,12 +1782,6 @@ static void ParseLangArgs(LangOptions &O
> >       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)
> >
> > Modified: cfe/trunk/lib/Frontend/FrontendActions.cpp
> > URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendActions.cpp?rev=261372&r1=261371&r2=261372&view=diff
> >
==============================================================================
> > --- cfe/trunk/lib/Frontend/FrontendActions.cpp (original)
> > +++ cfe/trunk/lib/Frontend/FrontendActions.cpp Fri Feb 19 16:25:36 2016
> > @@ -270,6 +270,8 @@ collectModuleHeaderIncludes(const LangOp
> >
> > 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);
> >
> > Modified: cfe/trunk/lib/Lex/ModuleMap.cpp
> > URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/ModuleMap.cpp?rev=261372&r1=261371&r2=261372&view=diff
> >
==============================================================================
> > --- cfe/trunk/lib/Lex/ModuleMap.cpp (original)
> > +++ cfe/trunk/lib/Lex/ModuleMap.cpp Fri Feb 19 16:25:36 2016
> > @@ -89,7 +89,7 @@ ModuleMap::ModuleMap(SourceManager &Sour
> >                      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;
> > }
> >
> > @@ -343,8 +343,8 @@ ModuleMap::KnownHeader ModuleMap::findMo
> >     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;
> > @@ -556,16 +556,10 @@ ModuleMap::findOrCreateModule(StringRef
> >   // 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);
> > }
> > @@ -693,9 +687,10 @@ Module *ModuleMap::inferFrameworkModule(
> >                               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;
> > @@ -703,9 +698,6 @@ Module *ModuleMap::inferFrameworkModule(
> >   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
> > @@ -812,7 +804,8 @@ void ModuleMap::addHeader(Module *Mod, M
> >   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.
> >
> > Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
> > URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=261372&r1=261371&r2=261372&view=diff
> >
==============================================================================
> > --- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
> > +++ cfe/trunk/lib/Lex/PPDirectives.cpp Fri Feb 19 16:25:36 2016
> > @@ -573,23 +573,23 @@ void Preprocessor::PTHSkipExcludedCondit
> > }
> >
> > 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) {
> > @@ -1668,10 +1668,7 @@ void Preprocessor::HandleIncludeDirectiv
> >   // 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()) {
> >
> > Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
> > URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=261372&r1=261371&r2=261372&view=diff
> >
==============================================================================
> > --- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)
> > +++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Fri Feb 19 16:25:36 2016
> > @@ -1438,8 +1438,9 @@ static bool EvaluateBuildingModule(Token
> >     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);
> >
> > Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
> > URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=261372&r1=261371&r2=261372&view=diff
> >
==============================================================================
> > --- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
> > +++ cfe/trunk/lib/Lex/Preprocessor.cpp Fri Feb 19 16:25:36 2016
> > @@ -477,7 +477,7 @@ void Preprocessor::CreateString(StringRe
> > }
> >
> > Module *Preprocessor::getCurrentModule() {
> > -  if (getLangOpts().CurrentModule.empty())
> > +  if (!getLangOpts().CompilingModule)
> >     return nullptr;
> >
> >   return
getHeaderSearchInfo().lookupModule(getLangOpts().CurrentModule);
> >
> > Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
> > URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=261372&r1=261371&r2=261372&view=diff
> >
==============================================================================
> > --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
> > +++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Feb 19 16:25:36 2016
> > @@ -14752,11 +14752,10 @@ DeclResult Sema::ActOnModuleImport(Sourc
> >   // 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;
> > @@ -14790,11 +14789,13 @@ void Sema::ActOnModuleInclude(SourceLoca
> >       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.
> >
> > Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
> > URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=261372&r1=261371&r2=261372&view=diff
> >
==============================================================================
> > --- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
> > +++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Fri Feb 19 16:25:36 2016
> > @@ -3171,7 +3171,7 @@ void Sema::addMethodToGlobalList(ObjCMet
> >   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())) {
> >
> > Modified: cfe/trunk/test/Modules/Inputs/explicit-build/a.h
> > URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/explicit-build/a.h?rev=261372&r1=261371&r2=261372&view=diff
> >
==============================================================================
> > --- cfe/trunk/test/Modules/Inputs/explicit-build/a.h (original)
> > +++ cfe/trunk/test/Modules/Inputs/explicit-build/a.h Fri Feb 19
16:25:36 2016
> > @@ -1,4 +1,4 @@
> > -#if !__building_module(a)
> > +#if !__building_module(a) && !BUILDING_A_PCH
> > #error "should only get here when building module a"
> > #endif
> >
> >
> > Modified: cfe/trunk/test/Modules/explicit-build.cpp
> > URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/explicit-build.cpp?rev=261372&r1=261371&r2=261372&view=diff
> >
==============================================================================
> > --- cfe/trunk/test/Modules/explicit-build.cpp (original)
> > +++ cfe/trunk/test/Modules/explicit-build.cpp Fri Feb 19 16:25:36 2016
> > @@ -143,7 +143,7 @@
> > // -------------------------------
> > // 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 \
> >
> > Modified: cfe/trunk/test/Modules/implementation-of-module.m
> > URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/implementation-of-module.m?rev=261372&r1=261371&r2=261372&view=diff
> >
==============================================================================
> > --- cfe/trunk/test/Modules/implementation-of-module.m (original)
> > +++ cfe/trunk/test/Modules/implementation-of-module.m Fri Feb 19
16:25:36 2016
> > @@ -1,22 +1,18 @@
> > -// 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
> >
> >
> > Modified: cfe/trunk/test/Modules/import-self.m
> > URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/import-self.m?rev=261372&r1=261371&r2=261372&view=diff
> >
==============================================================================
> > --- cfe/trunk/test/Modules/import-self.m (original)
> > +++ cfe/trunk/test/Modules/import-self.m Fri Feb 19 16:25:36 2016
> > @@ -6,6 +6,6 @@
> > // 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;
> >
> >
> > _______________________________________________
> > cfe-commits mailing list
> > cfe-commits at lists.llvm.org
> > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160303/c2badb3b/attachment-0001.html>


More information about the cfe-commits mailing list