[modules ts] Do not emit strong function definitions from the module interface unit in every user.

llvm-svn: 307232
This commit is contained in:
Richard Smith 2017-07-06 00:30:00 +00:00
parent 29c5f16ad0
commit b51cf1136f
4 changed files with 102 additions and 2 deletions

View 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));

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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.
}