r312684 - [modules ts] Ensure that module linkage variables are always emitted and always have their name mangled.

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 6 17:55:55 PDT 2017


Author: rsmith
Date: Wed Sep  6 17:55:55 2017
New Revision: 312684

URL: http://llvm.org/viewvc/llvm-project?rev=312684&view=rev
Log:
[modules ts] Ensure that module linkage variables are always emitted and always have their name mangled.

Modified:
    cfe/trunk/lib/AST/Mangle.cpp
    cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
    cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cpp
    cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cppm

Modified: cfe/trunk/lib/AST/Mangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Mangle.cpp?rev=312684&r1=312683&r2=312684&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Mangle.cpp (original)
+++ cfe/trunk/lib/AST/Mangle.cpp Wed Sep  6 17:55:55 2017
@@ -103,6 +103,11 @@ bool MangleContext::shouldMangleDeclName
   if (CC != CCM_Other)
     return true;
 
+  // If the declaration has an owning module for linkage purposes that needs to
+  // be mangled, we must mangle its name.
+  if (!D->hasExternalFormalLinkage() && D->getOwningModuleForLinkage())
+    return true;
+
   // In C, functions with no attributes never need to be mangled. Fastpath them.
   if (!getASTContext().getLangOpts().CPlusPlus && !D->hasAttrs())
     return false;

Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=312684&r1=312683&r2=312684&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Wed Sep  6 17:55:55 2017
@@ -1591,11 +1591,8 @@ void ASTDeclReader::ReadCXXDefinitionDat
   Data.ODRHash = Record.readInt();
   Data.HasODRHash = true;
 
-  if (Record.readInt()) {
-    Reader.DefinitionSource[D] = Loc.F->Kind == ModuleKind::MK_MainFile
-                                     ? ExternalASTSource::EK_Never
-                                     : ExternalASTSource::EK_Always;
-  }
+  if (Record.readInt())
+    Reader.DefinitionSource[D] = Loc.F->Kind == ModuleKind::MK_MainFile;
 
   Data.NumBases = Record.readInt();
   if (Data.NumBases)
@@ -2573,11 +2570,14 @@ static bool isConsumerInterestedIn(ASTCo
   // An ObjCMethodDecl is never considered as "interesting" because its
   // implementation container always is.
 
-  // An ImportDecl or VarDecl imported from a module will get emitted when
-  // we import the relevant module.
-  if ((isa<ImportDecl>(D) || isa<VarDecl>(D)) && D->getImportedOwningModule() &&
-      Ctx.DeclMustBeEmitted(D))
-    return false;
+  // An ImportDecl or VarDecl imported from a module map module will get
+  // emitted when we import the relevant module.
+  if (isa<ImportDecl>(D) || isa<VarDecl>(D)) {
+    auto *M = D->getImportedOwningModule();
+    if (M && M->Kind == Module::ModuleMapModule &&
+        Ctx.DeclMustBeEmitted(D))
+      return false;
+  }
 
   if (isa<FileScopeAsmDecl>(D) || 
       isa<ObjCProtocolDecl>(D) || 

Modified: cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cpp?rev=312684&r1=312683&r2=312684&view=diff
==============================================================================
--- cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cpp (original)
+++ cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cpp Wed Sep  6 17:55:55 2017
@@ -6,9 +6,8 @@
 // CHECK-DAG: @_ZW6ModuleE19static_var_exported = available_externally global i32 0,
 // CHECK-DAG: @const_var_exported = available_externally constant i32 3,
 //
-// FIXME: The module name should be mangled into all of these.
-// CHECK-DAG: @extern_var_module_linkage = external global
-// CHECK-DAG: @inline_var_module_linkage = linkonce_odr global
+// CHECK-DAG: @_ZW6ModuleE25extern_var_module_linkage = external global
+// CHECK-DAG: @_ZW6ModuleE25inline_var_module_linkage = linkonce_odr global
 // CHECK-DAG: @_ZW6ModuleE25static_var_module_linkage = available_externally global i32 0,
 // CHECK-DAG: @_ZW6ModuleE24const_var_module_linkage = available_externally constant i32 3,
 

Modified: cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cppm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cppm?rev=312684&r1=312683&r2=312684&view=diff
==============================================================================
--- cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cppm (original)
+++ cfe/trunk/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cppm Wed Sep  6 17:55:55 2017
@@ -14,14 +14,17 @@
 // CHECK-DAG: @_ZW6ModuleE19static_var_exported = global
 // CHECK-DAG: @const_var_exported = constant
 //
-// FIXME: The module name should be mangled into all of these.
-// CHECK-DAG: @extern_var_module_linkage = external global
+// CHECK-DAG: @_ZW6ModuleE25extern_var_module_linkage = external global
 // FIXME: Should this be 'weak_odr global'? Presumably it must be, since we
 // can discard this global and its initializer (if any), and other TUs are not
 // permitted to run the initializer for this variable.
-// CHECK-DAG: @inline_var_module_linkage = linkonce_odr global
+// CHECK-DAG: @_ZW6ModuleE25inline_var_module_linkage = linkonce_odr global
 // CHECK-DAG: @_ZW6ModuleE25static_var_module_linkage = global
 // CHECK-DAG: @_ZW6ModuleE24const_var_module_linkage = constant
+//
+// CHECK-DAG: @_ZW6ModuleE25unused_var_module_linkage = global i32 4
+// CHECK-DAG: @_ZW6ModuleE32unused_static_var_module_linkage = global i32 5
+// CHECK-DAG: @_ZW6ModuleE31unused_const_var_module_linkage = constant i32 7
 
 static void unused_static_global_module() {}
 static void used_static_global_module() {}
@@ -113,6 +116,11 @@ void noninline_module_linkage() {
   (void)&const_var_module_linkage;
 }
 
+int unused_var_module_linkage = 4;
+static int unused_static_var_module_linkage = 5;
+inline int unused_inline_var_module_linkage = 6;
+const int unused_const_var_module_linkage = 7;
+
 struct a {
   struct b {};
   struct c {};




More information about the cfe-commits mailing list