summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/include/clang/Basic/DiagnosticFrontendKinds.td4
-rw-r--r--clang/include/clang/Basic/LangOptions.def1
-rw-r--r--clang/include/clang/Basic/LangOptions.h10
-rw-r--r--clang/include/clang/Driver/CC1Options.td3
-rw-r--r--clang/include/clang/Driver/Options.td3
-rw-r--r--clang/include/clang/Lex/ModuleMap.h9
-rw-r--r--clang/lib/Basic/LangOptions.cpp1
-rw-r--r--clang/lib/Driver/Tools.cpp2
-rw-r--r--clang/lib/Frontend/ASTUnit.cpp2
-rw-r--r--clang/lib/Frontend/CompilerInstance.cpp10
-rw-r--r--clang/lib/Frontend/CompilerInvocation.cpp10
-rw-r--r--clang/lib/Frontend/FrontendActions.cpp2
-rw-r--r--clang/lib/Lex/ModuleMap.cpp29
-rw-r--r--clang/lib/Lex/PPDirectives.cpp37
-rw-r--r--clang/lib/Lex/PPMacroExpansion.cpp5
-rw-r--r--clang/lib/Lex/Preprocessor.cpp2
-rw-r--r--clang/lib/Sema/SemaDecl.cpp19
-rw-r--r--clang/lib/Sema/SemaDeclObjC.cpp2
-rw-r--r--clang/test/Modules/Inputs/explicit-build/a.h2
-rw-r--r--clang/test/Modules/explicit-build.cpp2
-rw-r--r--clang/test/Modules/implementation-of-module.m14
-rw-r--r--clang/test/Modules/import-self.m2
22 files changed, 67 insertions, 104 deletions
diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index 1c759024abb..43a9b186c9e 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -210,10 +210,6 @@ def err_test_module_file_extension_version : Error<
"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<
diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def
index cd1eb9f9d97..a3ee84291fd 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -127,6 +127,7 @@ BENIGN_LANGOPT(EmitAllDecls , 1, 0, "support for emitting all declarations"
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")
diff --git a/clang/include/clang/Basic/LangOptions.h b/clang/include/clang/Basic/LangOptions.h
index 736d4e0930b..a069a8f8b8f 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -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.
///
diff --git a/clang/include/clang/Driver/CC1Options.td b/clang/include/clang/Driver/CC1Options.td
index 00ca505afd2..76563ea6e8e 100644
--- a/clang/include/clang/Driver/CC1Options.td
+++ b/clang/include/clang/Driver/CC1Options.td
@@ -382,9 +382,6 @@ def fno_modules_global_index : Flag<["-"], "fno-modules-global-index">,
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>">;
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 7e5dc098b0f..1a974304e76 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -786,9 +786,10 @@ def fimplicit_module_maps : Flag <["-"], "fimplicit-module-maps">, Group<f_Group
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">;
diff --git a/clang/include/clang/Lex/ModuleMap.h b/clang/include/clang/Lex/ModuleMap.h
index 155943e5453..d9e04f47a61 100644
--- a/clang/include/clang/Lex/ModuleMap.h
+++ b/clang/include/clang/Lex/ModuleMap.h
@@ -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;
diff --git a/clang/lib/Basic/LangOptions.cpp b/clang/lib/Basic/LangOptions.cpp
index 1b08b068604..8c0ecd46ad5 100644
--- a/clang/lib/Basic/LangOptions.cpp
+++ b/clang/lib/Basic/LangOptions.cpp
@@ -34,7 +34,6 @@ void LangOptions::resetNonModularOptions() {
SanitizerBlacklistFiles.clear();
CurrentModule.clear();
- ImplementationOfModule.clear();
}
bool LangOptions::isNoBuiltinFunc(const char *Name) const {
diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp
index 8441a91a637..584dfed5a45 100644
--- a/clang/lib/Driver/Tools.cpp
+++ b/clang/lib/Driver/Tools.cpp
@@ -4909,7 +4909,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
// -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.
diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp
index 54ac6048bc1..0080fab13e2 100644
--- a/clang/lib/Frontend/ASTUnit.cpp
+++ b/clang/lib/Frontend/ASTUnit.cpp
@@ -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 {
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index 2b940ce360c..04a4c7dbe68 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -1386,8 +1386,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
// 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(SourceLocation ImportLoc,
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(SourceLocation ImportLoc,
}
}
- // 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) {
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index c822bccaa3c..2e0822794ee 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1763,10 +1763,8 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
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 &Opts, ArgList &Args, InputKind IK,
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)
diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp
index 060055fe115..6f76aa0992d 100644
--- a/clang/lib/Frontend/FrontendActions.cpp
+++ b/clang/lib/Frontend/FrontendActions.cpp
@@ -270,6 +270,8 @@ collectModuleHeaderIncludes(const LangOptions &LangOpts, FileManager &FileMgr,
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);
diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index f39928a44a8..1c5b4e2f1ad 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -89,7 +89,7 @@ ModuleMap::ModuleMap(SourceManager &SourceMgr, DiagnosticsEngine &Diags,
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::findModuleForHeader(const FileEntry *File) {
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 Name, Module *Parent, bool IsFramework,
// 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(const DirectoryEntry *FrameworkDir,
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(const DirectoryEntry *FrameworkDir,
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, Module::Header Header,
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.
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 645d0903617..320c16dbec2 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -573,23 +573,23 @@ void Preprocessor::PTHSkipExcludedConditionalBlock() {
}
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::HandleIncludeDirective(SourceLocation HashLoc,
// 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()) {
diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp
index 69f5bc8ddcc..a47b356f9c0 100644
--- a/clang/lib/Lex/PPMacroExpansion.cpp
+++ b/clang/lib/Lex/PPMacroExpansion.cpp
@@ -1438,8 +1438,9 @@ static bool EvaluateBuildingModule(Token &Tok,
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);
diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp
index 142d9ce0904..70b992170c9 100644
--- a/clang/lib/Lex/Preprocessor.cpp
+++ b/clang/lib/Lex/Preprocessor.cpp
@@ -477,7 +477,7 @@ void Preprocessor::CreateString(StringRef Str, Token &Tok,
}
Module *Preprocessor::getCurrentModule() {
- if (getLangOpts().CurrentModule.empty())
+ if (!getLangOpts().CompilingModule)
return nullptr;
return getHeaderSearchInfo().lookupModule(getLangOpts().CurrentModule);
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index d79e2e287f2..62cd5c8e3db 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -14752,11 +14752,10 @@ DeclResult Sema::ActOnModuleImport(SourceLocation AtLoc,
// 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(SourceLocation DirectiveLoc, Module *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.
diff --git a/clang/lib/Sema/SemaDeclObjC.cpp b/clang/lib/Sema/SemaDeclObjC.cpp
index 89d99906a07..6121973eb18 100644
--- a/clang/lib/Sema/SemaDeclObjC.cpp
+++ b/clang/lib/Sema/SemaDeclObjC.cpp
@@ -3171,7 +3171,7 @@ void Sema::addMethodToGlobalList(ObjCMethodList *List,
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())) {
diff --git a/clang/test/Modules/Inputs/explicit-build/a.h b/clang/test/Modules/Inputs/explicit-build/a.h
index 5e3602f58ff..a52f7357ff7 100644
--- a/clang/test/Modules/Inputs/explicit-build/a.h
+++ b/clang/test/Modules/Inputs/explicit-build/a.h
@@ -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
diff --git a/clang/test/Modules/explicit-build.cpp b/clang/test/Modules/explicit-build.cpp
index 2a5b70dce6c..a6f6a6268c1 100644
--- a/clang/test/Modules/explicit-build.cpp
+++ b/clang/test/Modules/explicit-build.cpp
@@ -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 \
diff --git a/clang/test/Modules/implementation-of-module.m b/clang/test/Modules/implementation-of-module.m
index 37e2cfbe30f..c07c52c3fc6 100644
--- a/clang/test/Modules/implementation-of-module.m
+++ b/clang/test/Modules/implementation-of-module.m
@@ -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
diff --git a/clang/test/Modules/import-self.m b/clang/test/Modules/import-self.m
index aa743713237..e5980159245 100644
--- a/clang/test/Modules/import-self.m
+++ b/clang/test/Modules/import-self.m
@@ -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;
OpenPOWER on IntegriCloud