diff --git a/clang/include/clang/Basic/Module.h b/clang/include/clang/Basic/Module.h --- a/clang/include/clang/Basic/Module.h +++ b/clang/include/clang/Basic/Module.h @@ -522,6 +522,15 @@ return Name.find(':') != std::string::npos; } + /// Get the primary module interface name from a partition. + + std::string getPrimaryModuleInterfaceName() const { + std::string::size_type pos = Name.find(':'); + if (pos == std::string::npos) + return Name; + return Name.substr(0, pos); + } + /// Retrieve the full name of this module, including the path from /// its top-level module. /// \param AllowStringLiterals If \c true, components that might not be diff --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp --- a/clang/lib/Sema/SemaModule.cpp +++ b/clang/lib/Sema/SemaModule.cpp @@ -373,17 +373,10 @@ // We already checked that we are in a module purview in the parser. assert (!ModuleScopes.empty() && "in a module purview, but no module?"); Module *NamedMod = ModuleScopes.back().Module; - if (ModuleScopes.back().IsPartition) { - // We're importing a partition into a partition, find the name of the - // owning named module. - size_t P = NamedMod->Name.find_first_of(":"); - ModuleName = NamedMod->Name.substr(0, P+1); - } else { - // We're importing a partition into the named module itself (either the - // interface or an implementation TU). - ModuleName = NamedMod->Name; - ModuleName += ":"; - } + // If we are importing into a partition, find the owning named module, + // otherwise, the name of the importing named module. + ModuleName = NamedMod->getPrimaryModuleInterfaceName(); + ModuleName += ":"; ModuleName += stringFromPath(Partition); ModuleNameLoc = {PP.getIdentifierInfo(ModuleName), Partition[0].second}; Partition = ModuleIdPath(ModuleNameLoc);