]> granicus.if.org Git - clang/commitdiff
[modules ts] Do not emit strong function definitions from the module interface unit...
authorRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 6 Jul 2017 00:30:00 +0000 (00:30 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 6 Jul 2017 00:30:00 +0000 (00:30 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@307232 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Serialization/ASTWriterDecl.cpp
test/CXX/modules-ts/basic/basic.def.odr/p4/module.cpp [new file with mode: 0644]
test/CXX/modules-ts/basic/basic.def.odr/p4/module.cppm [new file with mode: 0644]
test/CXX/modules-ts/basic/basic.def.odr/p4/user.cpp [new file with mode: 0644]

index 2d648cb103cbf36a2d3e2c2b8b7ca738ca87eb29..ec21ca2276c1168eaaf283fec9478873a316c818 100644 (file)
@@ -2233,8 +2233,18 @@ void ASTRecordWriter::AddFunctionDefinition(const FunctionDecl *FD) {
   Writer->ClearSwitchCaseIDs();
 
   assert(FD->doesThisDeclarationHaveABody());
-  bool ModulesCodegen = Writer->Context->getLangOpts().ModulesCodegen &&
-                        Writer->WritingModule && !FD->isDependentContext();
+  bool ModulesCodegen = false;
+  if (Writer->WritingModule && !FD->isDependentContext()) {
+    // Under -fmodules-codegen, codegen is performed for all defined functions.
+    // When building a C++ Modules TS module interface unit, a strong definition
+    // in the module interface is provided by the compilation of that module
+    // interface unit, not by its users. (Inline functions are still emitted
+    // in module users.)
+    ModulesCodegen =
+        Writer->Context->getLangOpts().ModulesCodegen ||
+        (Writer->WritingModule->Kind == Module::ModuleInterfaceUnit &&
+         Writer->Context->GetGVALinkageForFunction(FD) == GVA_StrongExternal);
+  }
   Record->push_back(ModulesCodegen);
   if (ModulesCodegen)
     Writer->ModularCodegenDecls.push_back(Writer->GetDeclRef(FD));
diff --git a/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cpp b/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cpp
new file mode 100644 (file)
index 0000000..c8b8725
--- /dev/null
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -fmodules-ts %S/module.cppm -triple %itanium_abi_triple -emit-module-interface -o %t
+// RUN: %clang_cc1 -fmodules-ts %s -triple %itanium_abi_triple -fmodule-file=%t -emit-llvm -o - | FileCheck %s --implicit-check-not=unused --implicit-check-not=global_module
+
+module Module;
+
+void use() {
+  // CHECK: define linkonce_odr {{.*}}@_Z20used_inline_exportedv
+  used_inline_exported();
+  // CHECK: declare {{.*}}@_Z18noninline_exportedv
+  noninline_exported();
+
+  // FIXME: This symbol should not be visible here.
+  // CHECK: define internal {{.*}}@_ZL26used_static_module_linkagev
+  used_static_module_linkage();
+
+  // FIXME: The module name should be mangled into the name of this function.
+  // CHECK: define linkonce_odr {{.*}}@_Z26used_inline_module_linkagev
+  used_inline_module_linkage();
+
+  // FIXME: The module name should be mangled into the name of this function.
+  // CHECK: declare {{.*}}@_Z24noninline_module_linkagev
+  noninline_module_linkage();
+}
diff --git a/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cppm b/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cppm
new file mode 100644 (file)
index 0000000..be3644e
--- /dev/null
@@ -0,0 +1,54 @@
+// RUN: %clang_cc1 -fmodules-ts %s -triple %itanium_abi_triple -emit-llvm -o - | FileCheck %s --implicit-check-not=unused
+
+static void unused_static_global_module() {}
+static void used_static_global_module() {}
+inline void unused_inline_global_module() {}
+inline void used_inline_global_module() {}
+// CHECK: define void {{.*}}@_Z23noninline_global_modulev
+void noninline_global_module() {
+  // FIXME: This should be promoted to module linkage and given a
+  // module-mangled name, if it's called from an inline function within
+  // the module interface.
+  // (We should try to avoid this when it's not reachable from outside
+  // the module interface unit.)
+  // CHECK: define internal {{.*}}@_ZL25used_static_global_modulev
+  used_static_global_module();
+  // CHECK: define linkonce_odr {{.*}}@_Z25used_inline_global_modulev
+  used_inline_global_module();
+}
+
+export module Module;
+
+export {
+  // FIXME: These should be ill-formed: you can't export an internal linkage
+  // symbol, per [dcl.module.interface]p2.
+  static void unused_static_exported() {}
+  static void used_static_exported() {}
+
+  inline void unused_inline_exported() {}
+  inline void used_inline_exported() {}
+  // CHECK: define void {{.*}}@_Z18noninline_exportedv
+  void noninline_exported() {
+    // CHECK: define internal {{.*}}@_ZL20used_static_exportedv
+    used_static_exported();
+    // CHECK: define linkonce_odr {{.*}}@_Z20used_inline_exportedv
+    used_inline_exported();
+  }
+}
+
+static void unused_static_module_linkage() {}
+static void used_static_module_linkage() {}
+inline void unused_inline_module_linkage() {}
+inline void used_inline_module_linkage() {}
+// FIXME: The module name should be mangled into the name of this function.
+// CHECK: define void {{.*}}@_Z24noninline_module_linkagev
+void noninline_module_linkage() {
+  // FIXME: This should be promoted to module linkage and given a
+  // module-mangled name, if it's called from an inline function within
+  // the module interface.
+  // CHECK: define internal {{.*}}@_ZL26used_static_module_linkagev
+  used_static_module_linkage();
+  // FIXME: The module name should be mangled into the name of this function.
+  // CHECK: define linkonce_odr {{.*}}@_Z26used_inline_module_linkagev
+  used_inline_module_linkage();
+}
diff --git a/test/CXX/modules-ts/basic/basic.def.odr/p4/user.cpp b/test/CXX/modules-ts/basic/basic.def.odr/p4/user.cpp
new file mode 100644 (file)
index 0000000..bbd67e2
--- /dev/null
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fmodules-ts %S/module.cppm -triple %itanium_abi_triple -emit-module-interface -o %t
+// RUN: %clang_cc1 -fmodules-ts %s -triple %itanium_abi_triple -fmodule-file=%t -emit-llvm -o - | FileCheck %s --implicit-check-not=unused --implicit-check-not=global_module
+
+import Module;
+
+void use() {
+  // CHECK: define linkonce_odr {{.*}}@_Z20used_inline_exportedv
+  used_inline_exported();
+  // CHECK: declare {{.*}}@_Z18noninline_exportedv
+  noninline_exported();
+
+  // Module-linkage declarations are not visible here.
+}