[PATCH] D145886: [C++2x][Modules] Amend module purview constant linkage [P2788R0].
Iain Sandoe via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 13 06:15:21 PDT 2023
iains created this revision.
Herald added a project: All.
iains added a reviewer: ChuanqiXu.
iains updated this revision to Diff 504524.
iains added a comment.
iains updated this revision to Diff 504591.
iains added a reviewer: rsmith.
iains published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
rebase, remove use of fmodule-file=X=path to attempt to resolve Windows fail.
iains added a comment.
rebased, try to fix Windows CI, take 2.
iains added a comment.
I should definitely check to make sure that this was adopted as a DR against C++20 (otherwise we would need to use the previous test conditionally on < 2b).
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D145886
Files:
clang/lib/AST/Decl.cpp
clang/test/CXX/module/basic/basic.def.odr/p4.cppm
clang/test/CXX/module/basic/basic.link/p3.cppm
Index: clang/test/CXX/module/basic/basic.link/p3.cppm
===================================================================
--- clang/test/CXX/module/basic/basic.link/p3.cppm
+++ 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;
Index: clang/test/CXX/module/basic/basic.def.odr/p4.cppm
===================================================================
--- clang/test/CXX/module/basic/basic.def.odr/p4.cppm
+++ 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 @@
// 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;
Index: clang/lib/AST/Decl.cpp
===================================================================
--- clang/lib/AST/Decl.cpp
+++ clang/lib/AST/Decl.cpp
@@ -600,6 +600,12 @@
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 @@
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();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145886.504591.patch
Type: text/x-patch
Size: 4494 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230313/fdb08781/attachment.bin>
More information about the cfe-commits
mailing list