[clang] 62a16d5 - [C++2x][Modules] Amend module purview constant linkage [P2788R0].
Iain Sandoe via cfe-commits
cfe-commits at lists.llvm.org
Sun Mar 19 09:26:28 PDT 2023
Author: Iain Sandoe
Date: 2023-03-19T16:25:56Z
New Revision: 62a16d5e2069542351c164aa0e3b216dc8e153c4
URL: https://github.com/llvm/llvm-project/commit/62a16d5e2069542351c164aa0e3b216dc8e153c4
DIFF: https://github.com/llvm/llvm-project/commit/62a16d5e2069542351c164aa0e3b216dc8e153c4.diff
LOG: [C++2x][Modules] Amend module purview constant linkage [P2788R0].
This paper has been applied to the working draft and is believed to be
a DR against C++20, so that the patch here makes the change unconditionally.
for:
```
export module A;
const int mod_cst = 10;
```
Before the change, mod_cst would have internal linkage; after the change it
has module linkage.
Differential Revision: https://reviews.llvm.org/D145886
Added:
Modified:
clang/lib/AST/Decl.cpp
clang/test/CXX/module/basic/basic.def.odr/p4.cppm
clang/test/CXX/module/basic/basic.link/p3.cppm
Removed:
################################################################################
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 484a4a294aa5e..56042e5fd252f 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -600,6 +600,12 @@ static bool isExportedFromModuleInterfaceUnit(const NamedDecl *D) {
llvm_unreachable("unexpected module ownership kind");
}
+static bool isDeclaredInModuleInterfaceOrPartition(const NamedDecl *D) {
+ if (auto *M = D->getOwningModule())
+ return M->isInterfaceOrPartition();
+ return false;
+}
+
static LinkageInfo getInternalLinkageFor(const NamedDecl *D) {
return LinkageInfo::internal();
}
@@ -642,15 +648,15 @@ LinkageComputer::getLVForNamespaceScopeDecl(const NamedDecl *D,
if (const auto *Var = dyn_cast<VarDecl>(D)) {
// - a non-template variable of non-volatile const-qualified type, unless
// - it is explicitly declared extern, or
- // - it is inline or exported, or
+ // - it is declared in the purview of a module interface unit
+ // (outside the private-module-fragment, if any) or module partition, or
+ // - it is inline, or
// - it was previously declared and the prior declaration did not have
// internal linkage
// (There is no equivalent in C99.)
- if (Context.getLangOpts().CPlusPlus &&
- Var->getType().isConstQualified() &&
- !Var->getType().isVolatileQualified() &&
- !Var->isInline() &&
- !isExportedFromModuleInterfaceUnit(Var) &&
+ if (Context.getLangOpts().CPlusPlus && Var->getType().isConstQualified() &&
+ !Var->getType().isVolatileQualified() && !Var->isInline() &&
+ !isDeclaredInModuleInterfaceOrPartition(Var) &&
!isa<VarTemplateSpecializationDecl>(Var) &&
!Var->getDescribedVarTemplate()) {
const VarDecl *PrevVar = Var->getPreviousDecl();
diff --git a/clang/test/CXX/module/basic/basic.def.odr/p4.cppm b/clang/test/CXX/module/basic/basic.def.odr/p4.cppm
index b8f24d3ed5c8a..1542e532c635a 100644
--- a/clang/test/CXX/module/basic/basic.def.odr/p4.cppm
+++ b/clang/test/CXX/module/basic/basic.def.odr/p4.cppm
@@ -5,9 +5,9 @@
// RUN: %clang_cc1 -std=c++20 %t/Module.cppm -triple %itanium_abi_triple -emit-llvm -o - | FileCheck %t/Module.cppm --implicit-check-not unused
//
// RUN: %clang_cc1 -std=c++20 %t/Module.cppm -triple %itanium_abi_triple -emit-module-interface -o %t/Module.pcm
-// RUN: %clang_cc1 -std=c++20 %t/module.cpp -triple %itanium_abi_triple -fmodule-file=%t/Module.pcm -emit-llvm -o - | FileCheck %t/module.cpp --implicit-check-not=unused --implicit-check-not=global_module
+// RUN: %clang_cc1 -std=c++20 %t/module.cpp -triple %itanium_abi_triple -fmodule-file=Module=%t/Module.pcm -emit-llvm -o - | FileCheck %t/module.cpp --implicit-check-not=unused --implicit-check-not=global_module
//
-// RUN: %clang_cc1 -std=c++20 %t/user.cpp -triple %itanium_abi_triple -fmodule-file=%t/Module.pcm -emit-llvm -o - | FileCheck %t/user.cpp --implicit-check-not=unused --implicit-check-not=global_module
+// RUN: %clang_cc1 -std=c++20 %t/user.cpp -triple %itanium_abi_triple -fmodule-file=Module=%t/Module.pcm -emit-llvm -o - | FileCheck %t/user.cpp --implicit-check-not=unused --implicit-check-not=global_module
//--- Module.cppm
// CHECK-DAG: @extern_var_global_module = external {{(dso_local )?}}global
@@ -30,7 +30,7 @@
// permitted to run the initializer for this variable.
// CHECK-DAG: @_ZW6Module25inline_var_module_linkage = linkonce_odr {{(dso_local )?}}global
// CHECK-DAG: @_ZL25static_var_module_linkage = internal
-// CHECK-DAG: @_ZL24const_var_module_linkage = internal
+// CHECK-DAG: @_ZW6Module24const_var_module_linkage = {{(dso_local )?}}constant
//
// CHECK-DAG: @_ZW6Module25unused_var_module_linkage = {{(dso_local )?}}global i32 4
@@ -129,7 +129,7 @@ void f(a::b, a::c) {}
// CHECK-DAG: @_ZW6Module25extern_var_module_linkage = external {{(dso_local )?}}global
// CHECK-DAG: @_ZW6Module25inline_var_module_linkage = linkonce_odr {{(dso_local )?}}global
// CHECK-DAG: @_ZL25static_var_module_linkage = internal {{(dso_local )?}}global i32 0,
-// CHECK-DAG: @_ZL24const_var_module_linkage = internal {{(dso_local )?}}constant i32 3,
+// CHECK-DAG: @_ZW6Module24const_var_module_linkage = available_externally {{(dso_local )?}}constant i32 3,
module Module;
diff --git a/clang/test/CXX/module/basic/basic.link/p3.cppm b/clang/test/CXX/module/basic/basic.link/p3.cppm
index 60505d8ba8b4b..945cfea1cffa0 100644
--- a/clang/test/CXX/module/basic/basic.link/p3.cppm
+++ b/clang/test/CXX/module/basic/basic.link/p3.cppm
@@ -3,7 +3,7 @@
export module M;
-// CHECK-NOT: @_ZW1M1a ={{.*}}
+// CHECK: @_ZW1M1a ={{.*}} constant i32 1
const int a = 1;
// CHECK: @_ZW1M1b ={{.*}} constant i32 2
export const int b = 2;
More information about the cfe-commits
mailing list