<div dir="ltr">Thanks, looking...</div><div class="gmail_extra"><br><div class="gmail_quote">On 5 September 2017 at 13:31, Evgenii Stepanov via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Richard,<br>
<br>
this change has triggered a bunch of leak reports on the sanitizer bots:<br>
<br>
Direct leak of 1824 byte(s) in 1 object(s) allocated from:<br>
    #0 0xb48430 in operator new(unsigned long)<br>
/mnt/b/sanitizer-buildbot3/<wbr>sanitizer-x86_64-linux-fast/<wbr>build/llvm/projects/compiler-<wbr>rt/lib/asan/asan_new_delete.<wbr>cc:82<br>
    #1 0xadfd119 in<br>
clang::ModuleMap::<wbr>createGlobalModuleForInterface<wbr>Unit(clang::SourceLocation)<br>
/mnt/b/sanitizer-buildbot3/<wbr>sanitizer-x86_64-linux-fast/<wbr>build/llvm/tools/clang/lib/<wbr>Lex/ModuleMap.cpp:750:18<br>
    #2 0x860e9be in clang::Sema::<wbr>ActOnStartOfTranslationUnit()<br>
/mnt/b/sanitizer-buildbot3/<wbr>sanitizer-x86_64-linux-fast/<wbr>build/llvm/tools/clang/lib/<wbr>Sema/Sema.cpp:775:30<br>
    #3 0x7d27209 in<br>
clang::Parser::<wbr>ParseFirstTopLevelDecl(clang::<wbr>OpaquePtr<clang::DeclGroupRef><wbr>&)<br>
/mnt/b/sanitizer-buildbot3/<wbr>sanitizer-x86_64-linux-fast/<wbr>build/llvm/tools/clang/lib/<wbr>Parse/Parser.cpp:529:11<br>
    #4 0x7d158fe in clang::ParseAST(clang::Sema&, bool, bool)<br>
/mnt/b/sanitizer-buildbot3/<wbr>sanitizer-x86_64-linux-fast/<wbr>build/llvm/tools/clang/lib/<wbr>Parse/ParseAST.cpp:146:23<br>
    #5 0x618926e in clang::FrontendAction::<wbr>Execute()<br>
/mnt/b/sanitizer-buildbot3/<wbr>sanitizer-x86_64-linux-fast/<wbr>build/llvm/tools/clang/lib/<wbr>Frontend/FrontendAction.cpp:<wbr>902:8<br>
    #6 0x6090664 in<br>
clang::CompilerInstance::<wbr>ExecuteAction(clang::<wbr>FrontendAction&)<br>
/mnt/b/sanitizer-buildbot3/<wbr>sanitizer-x86_64-linux-fast/<wbr>build/llvm/tools/clang/lib/<wbr>Frontend/CompilerInstance.cpp:<wbr>986:11<br>
    #7 0x637eb45 in<br>
clang::<wbr>ExecuteCompilerInvocation(<wbr>clang::CompilerInstance*)<br>
/mnt/b/sanitizer-buildbot3/<wbr>sanitizer-x86_64-linux-fast/<wbr>build/llvm/tools/clang/lib/<wbr>FrontendTool/<wbr>ExecuteCompilerInvocation.cpp:<wbr>252:25<br>
    #8 0xb5b13f in cc1_main(llvm::ArrayRef<char const*>, char const*,<br>
void*) /mnt/b/sanitizer-buildbot3/<wbr>sanitizer-x86_64-linux-fast/<wbr>build/llvm/tools/clang/tools/<wbr>driver/cc1_main.cpp:221:13<br>
    #9 0xb53d33 in ExecuteCC1Tool<br>
/mnt/b/sanitizer-buildbot3/<wbr>sanitizer-x86_64-linux-fast/<wbr>build/llvm/tools/clang/tools/<wbr>driver/driver.cpp:302:12<br>
    #10 0xb53d33 in main<br>
/mnt/b/sanitizer-buildbot3/<wbr>sanitizer-x86_64-linux-fast/<wbr>build/llvm/tools/clang/tools/<wbr>driver/driver.cpp:381<br>
    #11 0x7fc921b0b82f in __libc_start_main<br>
(/lib/x86_64-linux-gnu/libc.<wbr>so.6+0x2082f)<br>
<br>
Failing Tests (16):<br>
    Clang :: CXX/modules-ts/basic/basic.<wbr>def.odr/p4/module.cpp<br>
    Clang :: CXX/modules-ts/basic/basic.<wbr>def.odr/p4/user.cpp<br>
    Clang :: CXX/modules-ts/basic/basic.<wbr>link/module-declaration.cpp<br>
    Clang :: CXX/modules-ts/basic/basic.<wbr>link/p2/module.cpp<br>
    Clang :: CXX/modules-ts/basic/basic.<wbr>link/p2/other.cpp<br>
    Clang :: CXX/modules-ts/basic/basic.<wbr>search/module-import.cpp<br>
    Clang :: CXX/modules-ts/codegen-basics.<wbr>cppm<br>
    Clang :: CXX/modules-ts/dcl.dcl/dcl.<wbr>module/dcl.module.import/p1.<wbr>cpp<br>
    Clang :: CXX/modules-ts/dcl.dcl/dcl.<wbr>module/dcl.module.interface/<wbr>p1.cpp<br>
    Clang :: CXX/modules-ts/dcl.dcl/dcl.<wbr>module/p5.cpp<br>
    Clang :: Driver/modules-ts.cpp<br>
    Clang :: Lexer/modules-ts.cpp<br>
    Clang :: Modules/diag-flags.cpp<br>
    Clang :: Modules/diag-pragma.cpp<br>
    Clang :: Modules/import-syntax.c<br>
    Clang :: SemaCXX/modules-ts.cppm<br>
<br>
<a href="http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/7630" rel="noreferrer" target="_blank">http://lab.llvm.org:8011/<wbr>builders/sanitizer-x86_64-<wbr>linux-fast/builds/7630</a><br>
<div class="HOEnZb"><div class="h5"><br>
On Sun, Sep 3, 2017 at 10:37 PM, Richard Smith via cfe-commits<br>
<<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br>
> Author: rsmith<br>
> Date: Sun Sep  3 22:37:53 2017<br>
> New Revision: 312467<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=312467&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=312467&view=rev</a><br>
> Log:<br>
> Implement Itanium name mangling support for C++ Modules TS.<br>
><br>
> This follows the scheme agreed with Nathan Sidwell, which can be found here:<br>
><br>
>   <a href="https://gcc.gnu.org/wiki/cxx-modules?action=AttachFile" rel="noreferrer" target="_blank">https://gcc.gnu.org/wiki/cxx-<wbr>modules?action=AttachFile</a><br>
><br>
> This will be proposed to the itanium-cxx-abi list once we have some experience<br>
> with how well it works; the ABI for this TS should be considered unstable until<br>
> it is part of the Itanium C++ ABI.<br>
><br>
> Modified:<br>
>     cfe/trunk/include/clang/AST/<wbr>Decl.h<br>
>     cfe/trunk/include/clang/AST/<wbr>DeclBase.h<br>
>     cfe/trunk/include/clang/Basic/<wbr>Module.h<br>
>     cfe/trunk/include/clang/Lex/<wbr>ModuleMap.h<br>
>     cfe/trunk/lib/AST/Decl.cpp<br>
>     cfe/trunk/lib/AST/<wbr>ItaniumMangle.cpp<br>
>     cfe/trunk/lib/Lex/ModuleMap.<wbr>cpp<br>
>     cfe/trunk/lib/Sema/Sema.cpp<br>
>     cfe/trunk/lib/Sema/SemaDecl.<wbr>cpp<br>
>     cfe/trunk/lib/Serialization/<wbr>ASTReader.cpp<br>
>     cfe/trunk/lib/Serialization/<wbr>ASTWriter.cpp<br>
>     cfe/trunk/test/CXX/modules-ts/<wbr>basic/basic.def.odr/p4/module.<wbr>cpp<br>
>     cfe/trunk/test/CXX/modules-ts/<wbr>basic/basic.def.odr/p4/module.<wbr>cppm<br>
>     cfe/trunk/test/CXX/modules-ts/<wbr>basic/basic.def.odr/p4/user.<wbr>cpp<br>
>     cfe/trunk/test/CXX/modules-ts/<wbr>codegen-basics.cppm<br>
>     cfe/trunk/test/SemaCXX/<wbr>modules-ts.cppm<br>
><br>
> Modified: cfe/trunk/include/clang/AST/<wbr>Decl.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=312467&r1=312466&r2=312467&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/include/<wbr>clang/AST/Decl.h?rev=312467&<wbr>r1=312466&r2=312467&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- cfe/trunk/include/clang/AST/<wbr>Decl.h (original)<br>
> +++ cfe/trunk/include/clang/AST/<wbr>Decl.h Sun Sep  3 22:37:53 2017<br>
> @@ -372,6 +372,10 @@ public:<br>
>      return hasCachedLinkage();<br>
>    }<br>
><br>
> +  /// Get the module that owns this declaration for linkage purposes.<br>
> +  /// There only ever is such a module under the C++ Modules TS.<br>
> +  Module *getOwningModuleForLinkage() const;<br>
> +<br>
>    /// \brief Looks through UsingDecls and ObjCCompatibleAliasDecls for<br>
>    /// the underlying named decl.<br>
>    NamedDecl *getUnderlyingDecl() {<br>
><br>
> Modified: cfe/trunk/include/clang/AST/<wbr>DeclBase.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=312467&r1=312466&r2=312467&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/include/<wbr>clang/AST/DeclBase.h?rev=<wbr>312467&r1=312466&r2=312467&<wbr>view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- cfe/trunk/include/clang/AST/<wbr>DeclBase.h (original)<br>
> +++ cfe/trunk/include/clang/AST/<wbr>DeclBase.h Sun Sep  3 22:37:53 2017<br>
> @@ -733,7 +733,7 @@ public:<br>
>      return getModuleOwnershipKind() != ModuleOwnershipKind::Unowned;<br>
>    }<br>
><br>
> -  /// Get the module that owns this declaration.<br>
> +  /// Get the module that owns this declaration (for visibility purposes).<br>
>    Module *getOwningModule() const {<br>
>      return isFromASTFile() ? getImportedOwningModule() : getLocalOwningModule();<br>
>    }<br>
><br>
> Modified: cfe/trunk/include/clang/Basic/<wbr>Module.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Module.h?rev=312467&r1=312466&r2=312467&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/include/<wbr>clang/Basic/Module.h?rev=<wbr>312467&r1=312466&r2=312467&<wbr>view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- cfe/trunk/include/clang/Basic/<wbr>Module.h (original)<br>
> +++ cfe/trunk/include/clang/Basic/<wbr>Module.h Sun Sep  3 22:37:53 2017<br>
> @@ -68,7 +68,11 @@ public:<br>
>      ModuleMapModule,<br>
><br>
>      /// \brief This is a C++ Modules TS module interface unit.<br>
> -    ModuleInterfaceUnit<br>
> +    ModuleInterfaceUnit,<br>
> +<br>
> +    /// \brief This is a fragment of the global module within some C++ Modules<br>
> +    /// TS module.<br>
> +    GlobalModuleFragment,<br>
>    };<br>
><br>
>    /// \brief The kind of this module.<br>
> @@ -391,6 +395,15 @@ public:<br>
>      return IsFramework && Parent && Parent->isPartOfFramework();<br>
>    }<br>
><br>
> +  /// Set the parent of this module. This should only be used if the parent<br>
> +  /// could not be set during module creation.<br>
> +  void setParent(Module *M) {<br>
> +    assert(!Parent);<br>
> +    Parent = M;<br>
> +    Parent->SubModuleIndex[Name] = Parent->SubModules.size();<br>
> +    Parent->SubModules.push_back(<wbr>this);<br>
> +  }<br>
> +<br>
>    /// \brief Retrieve the full name of this module, including the path from<br>
>    /// its top-level module.<br>
>    /// \param AllowStringLiterals If \c true, components that might not be<br>
><br>
> Modified: cfe/trunk/include/clang/Lex/<wbr>ModuleMap.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/ModuleMap.h?rev=312467&r1=312466&r2=312467&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/include/<wbr>clang/Lex/ModuleMap.h?rev=<wbr>312467&r1=312466&r2=312467&<wbr>view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- cfe/trunk/include/clang/Lex/<wbr>ModuleMap.h (original)<br>
> +++ cfe/trunk/include/clang/Lex/<wbr>ModuleMap.h Sun Sep  3 22:37:53 2017<br>
> @@ -472,6 +472,14 @@ public:<br>
>                                                 bool IsFramework,<br>
>                                                 bool IsExplicit);<br>
><br>
> +  /// \brief Create a 'global module' for a C++ Modules TS module interface<br>
> +  /// unit.<br>
> +  ///<br>
> +  /// We model the global module as a submodule of the module interface unit.<br>
> +  /// Unfortunately, we can't create the module interface unit's Module until<br>
> +  /// later, because we don't know what it will be called.<br>
> +  Module *<wbr>createGlobalModuleForInterface<wbr>Unit(SourceLocation Loc);<br>
> +<br>
>    /// \brief Create a new module for a C++ Modules TS module interface unit.<br>
>    /// The module must not already exist, and will be configured for the current<br>
>    /// compilation.<br>
> @@ -479,7 +487,8 @@ public:<br>
>    /// Note that this also sets the current module to the newly-created module.<br>
>    ///<br>
>    /// \returns The newly-created module.<br>
> -  Module *createModuleForInterfaceUnit(<wbr>SourceLocation Loc, StringRef Name);<br>
> +  Module *createModuleForInterfaceUnit(<wbr>SourceLocation Loc, StringRef Name,<br>
> +                                       Module *GlobalModule);<br>
><br>
>    /// \brief Infer the contents of a framework module map from the given<br>
>    /// framework directory.<br>
><br>
> Modified: cfe/trunk/lib/AST/Decl.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=312467&r1=312466&r2=312467&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/AST/<wbr>Decl.cpp?rev=312467&r1=312466&<wbr>r2=312467&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- cfe/trunk/lib/AST/Decl.cpp (original)<br>
> +++ cfe/trunk/lib/AST/Decl.cpp Sun Sep  3 22:37:53 2017<br>
> @@ -652,7 +652,7 @@ LinkageComputer::<wbr>getLVForNamespaceScopeD<br>
>    //   If the declaration of an identifier for an object has file<br>
>    //   scope and no storage-class specifier, its linkage is<br>
>    //   external.<br>
> -  LinkageInfo LV;<br>
> +  LinkageInfo LV = getExternalLinkageFor(D);<br>
><br>
>    if (!<wbr>hasExplicitVisibilityAlready(<wbr>computation)) {<br>
>      if (Optional<Visibility> Vis = getExplicitVisibility(D, computation)) {<br>
> @@ -1399,6 +1399,30 @@ LinkageInfo LinkageComputer::getDeclLink<br>
>    return getLVForDecl(D, usesTypeVisibility(D) ? LVForType : LVForValue);<br>
>  }<br>
><br>
> +Module *NamedDecl::<wbr>getOwningModuleForLinkage() const {<br>
> +  Module *M = getOwningModule();<br>
> +  if (!M)<br>
> +    return nullptr;<br>
> +<br>
> +  switch (M->Kind) {<br>
> +  case Module::ModuleMapModule:<br>
> +    // Module map modules have no special linkage semantics.<br>
> +    return nullptr;<br>
> +<br>
> +  case Module::ModuleInterfaceUnit:<br>
> +    return M;<br>
> +<br>
> +  case Module::GlobalModuleFragment:<br>
> +    // External linkage declarations in the global module have no owning module<br>
> +    // for linkage purposes. But internal linkage declarations in the global<br>
> +    // module fragment of a particular module are owned by that module for<br>
> +    // linkage purposes.<br>
> +    return hasExternalFormalLinkage() ? nullptr : M->Parent;<br>
> +  }<br>
> +<br>
> +  llvm_unreachable("unknown module kind");<br>
> +}<br>
> +<br>
>  void NamedDecl::printName(raw_<wbr>ostream &os) const {<br>
>    os << Name;<br>
>  }<br>
><br>
> Modified: cfe/trunk/lib/AST/<wbr>ItaniumMangle.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ItaniumMangle.cpp?rev=312467&r1=312466&r2=312467&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/AST/<wbr>ItaniumMangle.cpp?rev=312467&<wbr>r1=312466&r2=312467&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- cfe/trunk/lib/AST/<wbr>ItaniumMangle.cpp (original)<br>
> +++ cfe/trunk/lib/AST/<wbr>ItaniumMangle.cpp Sun Sep  3 22:37:53 2017<br>
> @@ -381,6 +381,7 @@ class CXXNameMangler {<br>
>    AbiTagState AbiTagsRoot;<br>
><br>
>    llvm::DenseMap<uintptr_t, unsigned> Substitutions;<br>
> +  llvm::DenseMap<StringRef, unsigned> ModuleSubstitutions;<br>
><br>
>    ASTContext &getASTContext() const { return Context.getASTContext(); }<br>
><br>
> @@ -475,6 +476,8 @@ private:<br>
><br>
>    void mangleNameWithAbiTags(const NamedDecl *ND,<br>
>                               const AbiTagList *AdditionalAbiTags);<br>
> +  void mangleModuleName(const Module *M);<br>
> +  void mangleModuleNamePrefix(<wbr>StringRef Name);<br>
>    void mangleTemplateName(const TemplateDecl *TD,<br>
>                            const TemplateArgument *TemplateArgs,<br>
>                            unsigned NumTemplateArgs);<br>
> @@ -845,9 +848,9 @@ void CXXNameMangler::mangleName(<wbr>const Na<br>
><br>
>  void CXXNameMangler::<wbr>mangleNameWithAbiTags(const NamedDecl *ND,<br>
>                                             const AbiTagList *AdditionalAbiTags) {<br>
> -  //  <name> ::= <nested-name><br>
> -  //         ::= <unscoped-name><br>
> -  //         ::= <unscoped-template-name> <template-args><br>
> +  //  <name> ::= [<module-name>] <nested-name><br>
> +  //         ::= [<module-name>] <unscoped-name><br>
> +  //         ::= [<module-name>] <unscoped-template-name> <template-args><br>
>    //         ::= <local-name><br>
>    //<br>
>    const DeclContext *DC = getEffectiveDeclContext(ND);<br>
> @@ -866,6 +869,19 @@ void CXXNameMangler::<wbr>mangleNameWithAbiTa<br>
><br>
>    DC = IgnoreLinkageSpecDecls(DC);<br>
><br>
> +  if (isLocalContainerContext(DC)) {<br>
> +    mangleLocalName(ND, AdditionalAbiTags);<br>
> +    return;<br>
> +  }<br>
> +<br>
> +  // Do not mangle the owning module for an external linkage declaration.<br>
> +  // This enables backwards-compatibility with non-modular code, and is<br>
> +  // a valid choice since conflicts are not permitted by C++ Modules TS<br>
> +  // [basic.def.odr]/6.2.<br>
> +  if (!ND-><wbr>hasExternalFormalLinkage())<br>
> +    if (Module *M = ND->getOwningModuleForLinkage(<wbr>))<br>
> +      mangleModuleName(M);<br>
> +<br>
>    if (DC->isTranslationUnit() || isStdNamespace(DC)) {<br>
>      // Check if we have a template.<br>
>      const TemplateArgumentList *TemplateArgs = nullptr;<br>
> @@ -879,12 +895,42 @@ void CXXNameMangler::<wbr>mangleNameWithAbiTa<br>
>      return;<br>
>    }<br>
><br>
> -  if (isLocalContainerContext(DC)) {<br>
> -    mangleLocalName(ND, AdditionalAbiTags);<br>
> +  mangleNestedName(ND, DC, AdditionalAbiTags);<br>
> +}<br>
> +<br>
> +void CXXNameMangler::<wbr>mangleModuleName(const Module *M) {<br>
> +  // Implement the C++ Modules TS name mangling proposal; see<br>
> +  //     <a href="https://gcc.gnu.org/wiki/cxx-modules?action=AttachFile" rel="noreferrer" target="_blank">https://gcc.gnu.org/wiki/cxx-<wbr>modules?action=AttachFile</a><br>
> +  //<br>
> +  //   <module-name> ::= W <unscoped-name>+ E<br>
> +  //                 ::= W <module-subst> <unscoped-name>* E<br>
> +  Out << 'W';<br>
> +  mangleModuleNamePrefix(M-><wbr>Name);<br>
> +  Out << 'E';<br>
> +}<br>
> +<br>
> +void CXXNameMangler::<wbr>mangleModuleNamePrefix(<wbr>StringRef Name) {<br>
> +  //  <module-subst> ::= _ <seq-id>          # 0 < seq-id < 10<br>
> +  //                 ::= W <seq-id - 10> _   # otherwise<br>
> +  auto It = ModuleSubstitutions.find(Name)<wbr>;<br>
> +  if (It != ModuleSubstitutions.end()) {<br>
> +    if (It->second < 10)<br>
> +      Out << '_' << static_cast<char>('0' + It->second);<br>
> +    else<br>
> +      Out << 'W' << (It->second - 10) << '_';<br>
>      return;<br>
>    }<br>
><br>
> -  mangleNestedName(ND, DC, AdditionalAbiTags);<br>
> +  // FIXME: Preserve hierarchy in module names rather than flattening<br>
> +  // them to strings; use Module*s as substitution keys.<br>
> +  auto Parts = Name.rsplit('.');<br>
> +  if (Parts.second.empty())<br>
> +    Parts.second = Parts.first;<br>
> +  else<br>
> +    mangleModuleNamePrefix(Parts.<wbr>first);<br>
> +<br>
> +  Out << Parts.second.size() << Parts.second;<br>
> +  ModuleSubstitutions.insert({<wbr>Name, ModuleSubstitutions.size()});<br>
>  }<br>
><br>
>  void CXXNameMangler::<wbr>mangleTemplateName(const TemplateDecl *TD,<br>
> @@ -1233,13 +1279,16 @@ void CXXNameMangler::<wbr>mangleUnqualifiedNa<br>
>      }<br>
><br>
>      if (II) {<br>
> -      // We must avoid conflicts between internally- and externally-<br>
> -      // linked variable and function declaration names in the same TU:<br>
> +      // Match GCC's naming convention for internal linkage symbols, for<br>
> +      // symbols that are not actually visible outside of this TU. GCC<br>
> +      // distinguishes between internal and external linkage symbols in<br>
> +      // its mangling, to support cases like this that were valid C++ prior<br>
> +      // to DR426:<br>
> +      //<br>
>        //   void test() { extern void foo(); }<br>
>        //   static void foo();<br>
> -      // This naming convention is the same as that followed by GCC,<br>
> -      // though it shouldn't actually matter.<br>
>        if (ND && ND->getFormalLinkage() == InternalLinkage &&<br>
> +          !ND->isExternallyVisible() &&<br>
>            getEffectiveDeclContext(ND)-><wbr>isFileContext())<br>
>          Out << 'L';<br>
><br>
><br>
> Modified: cfe/trunk/lib/Lex/ModuleMap.<wbr>cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/ModuleMap.cpp?rev=312467&r1=312466&r2=312467&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/Lex/<wbr>ModuleMap.cpp?rev=312467&r1=<wbr>312466&r2=312467&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- cfe/trunk/lib/Lex/ModuleMap.<wbr>cpp (original)<br>
> +++ cfe/trunk/lib/Lex/ModuleMap.<wbr>cpp Sun Sep  3 22:37:53 2017<br>
> @@ -746,8 +746,16 @@ std::pair<Module *, bool> ModuleMap::fin<br>
>    return std::make_pair(Result, true);<br>
>  }<br>
><br>
> +Module *ModuleMap::<wbr>createGlobalModuleForInterface<wbr>Unit(SourceLocation Loc) {<br>
> +  auto *Result = new Module("<global>", Loc, nullptr, /*IsFramework*/ false,<br>
> +                            /*IsExplicit*/ true, NumCreatedModules++);<br>
> +  Result->Kind = Module::GlobalModuleFragment;<br>
> +  return Result;<br>
> +}<br>
> +<br>
>  Module *ModuleMap::<wbr>createModuleForInterfaceUnit(<wbr>SourceLocation Loc,<br>
> -                                                StringRef Name) {<br>
> +                                                StringRef Name,<br>
> +                                                Module *GlobalModule) {<br>
>    assert(LangOpts.CurrentModule == Name && "module name mismatch");<br>
>    assert(!Modules[Name] && "redefining existing module");<br>
><br>
> @@ -757,6 +765,9 @@ Module *ModuleMap::<wbr>createModuleForInterf<br>
>    Result->Kind = Module::ModuleInterfaceUnit;<br>
>    Modules[Name] = SourceModule = Result;<br>
><br>
> +  // Reparent the current global module fragment as a submodule of this module.<br>
> +  GlobalModule->setParent(<wbr>Result);<br>
> +<br>
>    // Mark the main source file as being within the newly-created module so that<br>
>    // declarations and macros are properly visibility-restricted to it.<br>
>    auto *MainFile = SourceMgr.getFileEntryForID(<wbr>SourceMgr.getMainFileID());<br>
><br>
> Modified: cfe/trunk/lib/Sema/Sema.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=312467&r1=312466&r2=312467&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/Sema/<wbr>Sema.cpp?rev=312467&r1=312466&<wbr>r2=312467&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- cfe/trunk/lib/Sema/Sema.cpp (original)<br>
> +++ cfe/trunk/lib/Sema/Sema.cpp Sun Sep  3 22:37:53 2017<br>
> @@ -766,10 +766,24 @@ void Sema::<wbr>emitAndClearUnusedLocalTypede<br>
>  /// declarations.<br>
>  void Sema::<wbr>ActOnStartOfTranslationUnit() {<br>
>    if (getLangOpts().ModulesTS) {<br>
> +    SourceLocation StartOfTU =<br>
> +        SourceMgr.<wbr>getLocForStartOfFile(<wbr>SourceMgr.getMainFileID());<br>
> +<br>
>      // We start in the global module; all those declarations are implicitly<br>
>      // module-private (though they do not have module linkage).<br>
> -    Context.<wbr>getTranslationUnitDecl()-><wbr>setModuleOwnershipKind(<br>
> -        Decl::ModuleOwnershipKind::<wbr>ModulePrivate);<br>
> +    auto &Map = PP.getHeaderSearchInfo().<wbr>getModuleMap();<br>
> +    auto *GlobalModule = Map.<wbr>createGlobalModuleForInterface<wbr>Unit(StartOfTU);<br>
> +    assert(GlobalModule && "module creation should not fail");<br>
> +<br>
> +    // Enter the scope of the global module.<br>
> +    ModuleScopes.push_back({});<br>
> +    ModuleScopes.back().Module = GlobalModule;<br>
> +    VisibleModules.setVisible(<wbr>GlobalModule, StartOfTU);<br>
> +<br>
> +    // All declarations created from now on are owned by the global module.<br>
> +    auto *TU = Context.<wbr>getTranslationUnitDecl();<br>
> +    TU->setModuleOwnershipKind(<wbr>Decl::ModuleOwnershipKind::<wbr>Visible);<br>
> +    TU->setLocalOwningModule(<wbr>GlobalModule);<br>
>    }<br>
>  }<br>
><br>
><br>
> Modified: cfe/trunk/lib/Sema/SemaDecl.<wbr>cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=312467&r1=312466&r2=312467&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/Sema/<wbr>SemaDecl.cpp?rev=312467&r1=<wbr>312466&r2=312467&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- cfe/trunk/lib/Sema/SemaDecl.<wbr>cpp (original)<br>
> +++ cfe/trunk/lib/Sema/SemaDecl.<wbr>cpp Sun Sep  3 22:37:53 2017<br>
> @@ -16052,6 +16052,9 @@ Sema::DeclGroupPtrTy Sema::ActOnModuleDe<br>
>                                             SourceLocation ModuleLoc,<br>
>                                             ModuleDeclKind MDK,<br>
>                                             ModuleIdPath Path) {<br>
> +  assert(getLangOpts().ModulesTS &&<br>
> +         "should only have module decl in modules TS");<br>
> +<br>
>    // A module implementation unit requires that we are not compiling a module<br>
>    // of any kind. A module interface unit requires that we are not compiling a<br>
>    // module map.<br>
> @@ -16104,10 +16107,10 @@ Sema::DeclGroupPtrTy Sema::ActOnModuleDe<br>
>    auto &Map = PP.getHeaderSearchInfo().<wbr>getModuleMap();<br>
>    Module *Mod;<br>
><br>
> +  assert(ModuleScopes.size() == 1 && "expected to be at global module scope");<br>
> +<br>
>    switch (MDK) {<br>
>    case ModuleDeclKind::Module: {<br>
> -    // FIXME: Check we're not in a submodule.<br>
> -<br>
>      // We can't have parsed or imported a definition of this module or parsed a<br>
>      // module map defining it already.<br>
>      if (auto *M = Map.findModule(ModuleName)) {<br>
> @@ -16121,7 +16124,8 @@ Sema::DeclGroupPtrTy Sema::ActOnModuleDe<br>
>      }<br>
><br>
>      // Create a Module for the module that we're defining.<br>
> -    Mod = Map.<wbr>createModuleForInterfaceUnit(<wbr>ModuleLoc, ModuleName);<br>
> +    Mod = Map.<wbr>createModuleForInterfaceUnit(<wbr>ModuleLoc, ModuleName,<br>
> +                                           ModuleScopes.front().Module);<br>
>      assert(Mod && "module creation should not fail");<br>
>      break;<br>
>    }<br>
> @@ -16140,16 +16144,16 @@ Sema::DeclGroupPtrTy Sema::ActOnModuleDe<br>
>      break;<br>
>    }<br>
><br>
> -  // Enter the semantic scope of the module.<br>
> -  ModuleScopes.push_back({});<br>
> +  // Switch from the global module to the named module.<br>
>    ModuleScopes.back().Module = Mod;<br>
> -  ModuleScopes.back().<wbr>OuterVisibleModules = std::move(VisibleModules);<br>
>    VisibleModules.setVisible(Mod, ModuleLoc);<br>
><br>
>    // From now on, we have an owning module for all declarations we see.<br>
>    // However, those declarations are module-private unless explicitly<br>
>    // exported.<br>
> -  Context.<wbr>getTranslationUnitDecl()-><wbr>setLocalOwningModule(Mod);<br>
> +  auto *TU = Context.<wbr>getTranslationUnitDecl();<br>
> +  TU->setModuleOwnershipKind(<wbr>Decl::ModuleOwnershipKind::<wbr>ModulePrivate);<br>
> +  TU->setLocalOwningModule(Mod);<br>
><br>
>    // FIXME: Create a ModuleDecl.<br>
>    return nullptr;<br>
> @@ -16327,7 +16331,7 @@ Decl *Sema::ActOnStartExportDecl(<wbr>Scope *<br>
>    // C++ Modules TS draft:<br>
>    //   An export-declaration shall appear in the purview of a module other than<br>
>    //   the global module.<br>
> -  if (ModuleScopes.empty() || !ModuleScopes.back().Module ||<br>
> +  if (ModuleScopes.empty() ||<br>
>        ModuleScopes.back().Module-><wbr>Kind != Module::ModuleInterfaceUnit)<br>
>      Diag(ExportLoc, diag::err_export_not_in_<wbr>module_interface);<br>
><br>
><br>
> Modified: cfe/trunk/lib/Serialization/<wbr>ASTReader.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=312467&r1=312466&r2=312467&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/<wbr>Serialization/ASTReader.cpp?<wbr>rev=312467&r1=312466&r2=<wbr>312467&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- cfe/trunk/lib/Serialization/<wbr>ASTReader.cpp (original)<br>
> +++ cfe/trunk/lib/Serialization/<wbr>ASTReader.cpp Sun Sep  3 22:37:53 2017<br>
> @@ -4871,7 +4871,6 @@ ASTReader::ReadSubmoduleBlock(<wbr>ModuleFile<br>
>    ModuleMap &ModMap = PP.getHeaderSearchInfo().<wbr>getModuleMap();<br>
>    bool First = true;<br>
>    Module *CurrentModule = nullptr;<br>
> -  Module::ModuleKind ModuleKind = Module::ModuleMapModule;<br>
>    RecordData Record;<br>
>    while (true) {<br>
>      llvm::BitstreamEntry Entry = F.Stream.<wbr>advanceSkippingSubblocks();<br>
> @@ -4919,6 +4918,7 @@ ASTReader::ReadSubmoduleBlock(<wbr>ModuleFile<br>
>        unsigned Idx = 0;<br>
>        SubmoduleID GlobalID = getGlobalSubmoduleID(F, Record[Idx++]);<br>
>        SubmoduleID Parent = getGlobalSubmoduleID(F, Record[Idx++]);<br>
> +      Module::ModuleKind Kind = (Module::ModuleKind)Record[<wbr>Idx++];<br>
>        bool IsFramework = Record[Idx++];<br>
>        bool IsExplicit = Record[Idx++];<br>
>        bool IsSystem = Record[Idx++];<br>
> @@ -4965,7 +4965,7 @@ ASTReader::ReadSubmoduleBlock(<wbr>ModuleFile<br>
>          CurrentModule-><wbr>PresumedModuleMapFile = F.ModuleMapPath;<br>
>        }<br>
><br>
> -      CurrentModule->Kind = ModuleKind;<br>
> +      CurrentModule->Kind = Kind;<br>
>        CurrentModule->Signature = F.Signature;<br>
>        CurrentModule-><wbr>IsFromModuleFile = true;<br>
>        CurrentModule->IsSystem = IsSystem || CurrentModule->IsSystem;<br>
> @@ -5064,7 +5064,6 @@ ASTReader::ReadSubmoduleBlock(<wbr>ModuleFile<br>
><br>
>          SubmodulesLoaded.resize(<wbr>SubmodulesLoaded.size() + F.LocalNumSubmodules);<br>
>        }<br>
> -      ModuleKind = (Module::ModuleKind)Record[2];<br>
>        break;<br>
>      }<br>
><br>
><br>
> Modified: cfe/trunk/lib/Serialization/<wbr>ASTWriter.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=312467&r1=312466&r2=312467&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/<wbr>Serialization/ASTWriter.cpp?<wbr>rev=312467&r1=312466&r2=<wbr>312467&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- cfe/trunk/lib/Serialization/<wbr>ASTWriter.cpp (original)<br>
> +++ cfe/trunk/lib/Serialization/<wbr>ASTWriter.cpp Sun Sep  3 22:37:53 2017<br>
> @@ -2716,6 +2716,7 @@ void ASTWriter::WriteSubmodules(<wbr>Module *<br>
>    Abbrev->Add(BitCodeAbbrevOp(<wbr>SUBMODULE_DEFINITION));<br>
>    Abbrev->Add(BitCodeAbbrevOp(<wbr>BitCodeAbbrevOp::VBR, 6)); // ID<br>
>    Abbrev->Add(BitCodeAbbrevOp(<wbr>BitCodeAbbrevOp::VBR, 6)); // Parent<br>
> +  Abbrev->Add(BitCodeAbbrevOp(<wbr>BitCodeAbbrevOp::Fixed, 2)); // Kind<br>
>    Abbrev->Add(BitCodeAbbrevOp(<wbr>BitCodeAbbrevOp::Fixed, 1)); // IsFramework<br>
>    Abbrev->Add(BitCodeAbbrevOp(<wbr>BitCodeAbbrevOp::Fixed, 1)); // IsExplicit<br>
>    Abbrev->Add(BitCodeAbbrevOp(<wbr>BitCodeAbbrevOp::Fixed, 1)); // IsSystem<br>
> @@ -2793,8 +2794,7 @@ void ASTWriter::WriteSubmodules(<wbr>Module *<br>
>    // Write the submodule metadata block.<br>
>    RecordData::value_type Record[] = {<br>
>        getNumberOfModules(<wbr>WritingModule),<br>
> -      FirstSubmoduleID - NUM_PREDEF_SUBMODULE_IDS,<br>
> -      (unsigned)WritingModule->Kind}<wbr>;<br>
> +      FirstSubmoduleID - NUM_PREDEF_SUBMODULE_IDS};<br>
>    Stream.EmitRecord(SUBMODULE_<wbr>METADATA, Record);<br>
><br>
>    // Write all of the submodules.<br>
> @@ -2816,6 +2816,7 @@ void ASTWriter::WriteSubmodules(<wbr>Module *<br>
>        RecordData::value_type Record[] = {SUBMODULE_DEFINITION,<br>
>                                           ID,<br>
>                                           ParentID,<br>
> +                                         Mod->Kind,<br>
>                                           Mod->IsFramework,<br>
>                                           Mod->IsExplicit,<br>
>                                           Mod->IsSystem,<br>
><br>
> Modified: cfe/trunk/test/CXX/modules-ts/<wbr>basic/basic.def.odr/p4/module.<wbr>cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cpp?rev=312467&r1=312466&r2=312467&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/test/CXX/<wbr>modules-ts/basic/basic.def.<wbr>odr/p4/module.cpp?rev=312467&<wbr>r1=312466&r2=312467&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- cfe/trunk/test/CXX/modules-ts/<wbr>basic/basic.def.odr/p4/module.<wbr>cpp (original)<br>
> +++ cfe/trunk/test/CXX/modules-ts/<wbr>basic/basic.def.odr/p4/module.<wbr>cpp Sun Sep  3 22:37:53 2017<br>
> @@ -4,15 +4,15 @@<br>
>  // CHECK-DAG: @extern_var_exported = external global<br>
>  // FIXME: Should this be 'external global'?<br>
>  // CHECK-DAG: @inline_var_exported = linkonce_odr global<br>
> -// CHECK-DAG: @_ZL19static_var_exported = external global<br>
> +// CHECK-DAG: @_ZW6ModuleE19static_var_<wbr>exported = external global<br>
>  // CHECK-DAG: @const_var_exported = external constant<br>
>  //<br>
>  // FIXME: The module name should be mangled into all of these.<br>
>  // CHECK-DAG: @extern_var_module_linkage = external global<br>
>  // FIXME: Should this be 'external global'?<br>
>  // CHECK-DAG: @inline_var_module_linkage = linkonce_odr global<br>
> -// CHECK-DAG: @_ZL25static_var_module_<wbr>linkage = external global<br>
> -// CHECK-DAG: @_ZL24const_var_module_linkage = external constant<br>
> +// CHECK-DAG: @_ZW6ModuleE25static_var_<wbr>module_linkage = external global<br>
> +// CHECK-DAG: @_ZW6ModuleE24const_var_<wbr>module_linkage = external constant<br>
><br>
>  module Module;<br>
><br>
> @@ -28,15 +28,13 @@ void use() {<br>
>    (void)&const_var_exported;<br>
><br>
>    // FIXME: This symbol should not be visible here.<br>
> -  // CHECK: declare {{.*}}@_ZL26used_static_<wbr>module_linkagev<br>
> +  // CHECK: declare {{.*}}@_ZW6ModuleE26used_<wbr>static_module_linkagev<br>
>    used_static_module_linkage();<br>
><br>
> -  // FIXME: The module name should be mangled into the name of this function.<br>
> -  // CHECK: define linkonce_odr {{.*}}@_Z26used_inline_module_<wbr>linkagev<br>
> +  // CHECK: define linkonce_odr {{.*}}@_ZW6ModuleE26used_<wbr>inline_module_linkagev<br>
>    used_inline_module_linkage();<br>
><br>
> -  // FIXME: The module name should be mangled into the name of this function.<br>
> -  // CHECK: declare {{.*}}@_Z24noninline_module_<wbr>linkagev<br>
> +  // CHECK: declare {{.*}}@_ZW6ModuleE24noninline_<wbr>module_linkagev<br>
>    noninline_module_linkage();<br>
><br>
>    (void)&extern_var_module_<wbr>linkage;<br>
><br>
> Modified: cfe/trunk/test/CXX/modules-ts/<wbr>basic/basic.def.odr/p4/module.<wbr>cppm<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cppm?rev=312467&r1=312466&r2=312467&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/test/CXX/<wbr>modules-ts/basic/basic.def.<wbr>odr/p4/module.cppm?rev=312467&<wbr>r1=312466&r2=312467&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- cfe/trunk/test/CXX/modules-ts/<wbr>basic/basic.def.odr/p4/module.<wbr>cppm (original)<br>
> +++ cfe/trunk/test/CXX/modules-ts/<wbr>basic/basic.def.odr/p4/module.<wbr>cppm Sun Sep  3 22:37:53 2017<br>
> @@ -11,7 +11,7 @@<br>
>  // can discard this global and its initializer (if any), and other TUs are not<br>
>  // permitted to run the initializer for this variable.<br>
>  // CHECK-DAG: @inline_var_exported = linkonce_odr global<br>
> -// CHECK-DAG: @_ZL19static_var_exported = global<br>
> +// CHECK-DAG: @_ZW6ModuleE19static_var_<wbr>exported = global<br>
>  // CHECK-DAG: @const_var_exported = constant<br>
>  //<br>
>  // FIXME: The module name should be mangled into all of these.<br>
> @@ -20,8 +20,8 @@<br>
>  // can discard this global and its initializer (if any), and other TUs are not<br>
>  // permitted to run the initializer for this variable.<br>
>  // CHECK-DAG: @inline_var_module_linkage = linkonce_odr global<br>
> -// CHECK-DAG: @_ZL25static_var_module_<wbr>linkage = global<br>
> -// CHECK-DAG: @_ZL24const_var_module_linkage = constant<br>
> +// CHECK-DAG: @_ZW6ModuleE25static_var_<wbr>module_linkage = global<br>
> +// CHECK-DAG: @_ZW6ModuleE24const_var_<wbr>module_linkage = constant<br>
><br>
>  static void unused_static_global_module() {}<br>
>  static void used_static_global_module() {}<br>
> @@ -57,9 +57,9 @@ export module Module;<br>
>  export {<br>
>    // FIXME: These should be ill-formed: you can't export an internal linkage<br>
>    // symbol, per [dcl.module.interface]p2.<br>
> -  // CHECK: define void {{.*}}@_ZL22unused_static_<wbr>exportedv<br>
> +  // CHECK: define void {{.*}}@_ZW6ModuleE22unused_<wbr>static_exportedv<br>
>    static void unused_static_exported() {}<br>
> -  // CHECK: define void {{.*}}@_ZL20used_static_<wbr>exportedv<br>
> +  // CHECK: define void {{.*}}@_ZW6ModuleE20used_<wbr>static_exportedv<br>
>    static void used_static_exported() {}<br>
><br>
>    inline void unused_inline_exported() {}<br>
> @@ -88,11 +88,9 @@ export {<br>
>  // FIXME: Ideally we wouldn't emit this as its name is not visible outside this<br>
>  // TU, but this module interface might contain a template that can use this<br>
>  // function so we conservatively emit it for now.<br>
> -// FIXME: The module name should be mangled into the name of this function.<br>
> -// CHECK: define void {{.*}}@_ZL28unused_static_<wbr>module_linkagev<br>
> +// CHECK: define void {{.*}}@_ZW6ModuleE28unused_<wbr>static_module_linkagev<br>
>  static void unused_static_module_linkage() {}<br>
> -// FIXME: The module name should be mangled into the name of this function.<br>
> -// CHECK: define void {{.*}}@_ZL26used_static_<wbr>module_linkagev<br>
> +// CHECK: define void {{.*}}@_ZW6ModuleE26used_<wbr>static_module_linkagev<br>
>  static void used_static_module_linkage() {}<br>
><br>
>  inline void unused_inline_module_linkage() {}<br>
> @@ -103,12 +101,10 @@ inline int inline_var_module_linkage;<br>
>  static int static_var_module_linkage;<br>
>  const int const_var_module_linkage = 3;<br>
><br>
> -// FIXME: The module name should be mangled into the name of this function.<br>
> -// CHECK: define void {{.*}}@_Z24noninline_module_<wbr>linkagev<br>
> +// CHECK: define void {{.*}}@_ZW6ModuleE24noninline_<wbr>module_linkagev<br>
>  void noninline_module_linkage() {<br>
>    used_static_module_linkage();<br>
> -  // FIXME: The module name should be mangled into the name of this function.<br>
> -  // CHECK: define linkonce_odr {{.*}}@_Z26used_inline_module_<wbr>linkagev<br>
> +  // CHECK: define linkonce_odr {{.*}}@_ZW6ModuleE26used_<wbr>inline_module_linkagev<br>
>    used_inline_module_linkage();<br>
><br>
>    (void)&extern_var_module_<wbr>linkage;<br>
> @@ -116,3 +112,10 @@ void noninline_module_linkage() {<br>
>    (void)&static_var_module_<wbr>linkage;<br>
>    (void)&const_var_module_<wbr>linkage;<br>
>  }<br>
> +<br>
> +struct a {<br>
> +  struct b {};<br>
> +  struct c {};<br>
> +};<br>
> +// CHECK: define void @_ZW6ModuleE1fW_0EN1a1bEW_<wbr>0ENS_1cE(<br>
> +void f(a::b, a::c) {}<br>
><br>
> Modified: cfe/trunk/test/CXX/modules-ts/<wbr>basic/basic.def.odr/p4/user.<wbr>cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p4/user.cpp?rev=312467&r1=312466&r2=312467&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/test/CXX/<wbr>modules-ts/basic/basic.def.<wbr>odr/p4/user.cpp?rev=312467&r1=<wbr>312466&r2=312467&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- cfe/trunk/test/CXX/modules-ts/<wbr>basic/basic.def.odr/p4/user.<wbr>cpp (original)<br>
> +++ cfe/trunk/test/CXX/modules-ts/<wbr>basic/basic.def.odr/p4/user.<wbr>cpp Sun Sep  3 22:37:53 2017<br>
> @@ -5,7 +5,7 @@<br>
>  // FIXME: Should this be 'external global'?<br>
>  // CHECK-DAG: @inline_var_exported = linkonce_odr global<br>
>  // FIXME: These should be 'extern global' and 'extern constant'.<br>
> -// CHECK-DAG: @_ZL19static_var_exported = global<br>
> +// CHECK-DAG: @_ZW6ModuleE19static_var_<wbr>exported = global<br>
>  // CHECK-DAG: @const_var_exported = constant<br>
><br>
>  import Module;<br>
><br>
> Modified: cfe/trunk/test/CXX/modules-ts/<wbr>codegen-basics.cppm<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/modules-ts/codegen-basics.cppm?rev=312467&r1=312466&r2=312467&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/test/CXX/<wbr>modules-ts/codegen-basics.<wbr>cppm?rev=312467&r1=312466&r2=<wbr>312467&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- cfe/trunk/test/CXX/modules-ts/<wbr>codegen-basics.cppm (original)<br>
> +++ cfe/trunk/test/CXX/modules-ts/<wbr>codegen-basics.cppm Sun Sep  3 22:37:53 2017<br>
> @@ -4,20 +4,18 @@<br>
>  export module FooBar;<br>
><br>
>  export {<br>
> -  // CHECK-LABEL: define i32 @_Z1fv(<br>
> +  // CHECK-DAG: define i32 @_Z1fv(<br>
>    int f() { return 0; }<br>
>  }<br>
><br>
> -// CHECK-LABEL: define weak_odr void @_Z2f2v(<br>
> +// CHECK-DAG: define weak_odr void @_ZW6FooBarE2f2v(<br>
>  inline void f2() { }<br>
><br>
> -// FIXME: Emit global variables and their initializers with this TU.<br>
> -// Emit an initialization function that other TUs can call, with guard variable.<br>
> -<br>
> -// FIXME: Mangle non-exported symbols so they don't collide with<br>
> -// non-exported symbols from other modules?<br>
> +// CHECK-DAG: define void @_ZW6FooBarE2f3v(<br>
> +static void f3() {}<br>
> +export void use_f3() { f3(); }<br>
><br>
> -// FIXME: Formally-internal-linkage symbols that are used from an exported<br>
> -// symbol need a mangled name and external linkage.<br>
> +// FIXME: Emit global variables and their initializers with this TU.<br>
> +// Emit an initialization function that other TUs can call, with guard variable?<br>
><br>
>  // FIXME: const-qualified variables don't have implicit internal linkage when owned by a module.<br>
><br>
> Modified: cfe/trunk/test/SemaCXX/<wbr>modules-ts.cppm<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/modules-ts.cppm?rev=312467&r1=312466&r2=312467&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/test/<wbr>SemaCXX/modules-ts.cppm?rev=<wbr>312467&r1=312466&r2=312467&<wbr>view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- cfe/trunk/test/SemaCXX/<wbr>modules-ts.cppm (original)<br>
> +++ cfe/trunk/test/SemaCXX/<wbr>modules-ts.cppm Sun Sep  3 22:37:53 2017<br>
> @@ -1,7 +1,7 @@<br>
> -// RUN:     %clang_cc1 -std=c++1z -fmodules-ts -emit-module-interface %s -o %t.pcm -verify -DTEST=0<br>
> -// RUN:     %clang_cc1 -std=c++1z -fmodules-ts -emit-module-interface %s -o %t.pcm -verify -DTEST=1<br>
> -// RUN:     %clang_cc1 -std=c++1z -fmodules-ts -emit-module-interface %s -fmodule-file=%t.pcm -o %t.pcm -verify -DTEST=2<br>
> -// RUN:     %clang_cc1 -std=c++1z -fmodules-ts -emit-module-interface %s -fmodule-file=%t.pcm -o %t.pcm -verify -Dfoo=bar -DTEST=3<br>
> +// RUN:     %clang_cc1 -std=c++1z -fmodules-ts -emit-module-interface %s -o %t.0.pcm -verify -DTEST=0<br>
> +// RUN:     %clang_cc1 -std=c++1z -fmodules-ts -emit-module-interface %s -o %t.1.pcm -verify -DTEST=1<br>
> +// RUN:     %clang_cc1 -std=c++1z -fmodules-ts -emit-module-interface %s -fmodule-file=%t.0.pcm -o %t.2.pcm -verify -DTEST=2<br>
> +// RUN:     %clang_cc1 -std=c++1z -fmodules-ts -emit-module-interface %s -fmodule-file=%t.0.pcm -o %t.3.pcm -verify -Dfoo=bar -DTEST=3<br>
><br>
>  #if TEST == 0<br>
>  // expected-no-diagnostics<br>
> @@ -21,7 +21,7 @@ static int m;<br>
>  // expected-note-re@modules-ts.<wbr>cppm:1 {{'{{.*}}modules-ts.cppm' included multiple times, additional include site in header from module 'foo'}}<br>
>  #endif<br>
>  int n;<br>
> -#if TEST >= 2<br>
> +#if TEST == 2<br>
>  // expected-error@-2 {{redefinition of '}}<br>
>  // expected-note@-3 {{unguarded header; consider using #ifdef guards or #pragma once}}<br>
>  // FIXME: We should drop the "header from" in this diagnostic.<br>
> @@ -60,7 +60,7 @@ int use_b = b;<br>
>  int use_n = n; // FIXME: this should not be visible, because it is not exported<br>
><br>
>  extern int n;<br>
> -static_assert(&n == p); // FIXME: these are not the same entity<br>
> +static_assert(&n != p);<br>
>  #endif<br>
><br>
><br>
><br>
><br>
> ______________________________<wbr>_________________<br>
> cfe-commits mailing list<br>
> <a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-commits</a><br>
______________________________<wbr>_________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-commits</a><br>
</div></div></blockquote></div><br></div>