https://github.com/ChuanqiXu9 created 
https://github.com/llvm/llvm-project/pull/102574

Close https://github.com/llvm/llvm-project/issues/99825

The root cause of the issue is that I didn't realize the things in implicit 
global module (the language linkage in module interfaces) should be considered 
in module purview.

>From cb862a139cc2a3e987b37092a9a03bb05fa060ea Mon Sep 17 00:00:00 2001
From: Chuanqi Xu <yedeng...@linux.alibaba.com>
Date: Fri, 9 Aug 2024 14:14:08 +0800
Subject: [PATCH] [C++20] [Moduels] Correct the linkage of const variable in
 language linkage from module interfaces

---
 clang/lib/AST/Decl.cpp          | 14 +++++++-------
 clang/test/Modules/pr99825.cppm |  8 ++++++++
 2 files changed, 15 insertions(+), 7 deletions(-)
 create mode 100644 clang/test/Modules/pr99825.cppm

diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index d832ce4190ff1a..e125143bc1b270 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -583,12 +583,6 @@ static bool isSingleLineLanguageLinkage(const Decl &D) {
   return false;
 }
 
-static bool isDeclaredInModuleInterfaceOrPartition(const NamedDecl *D) {
-  if (auto *M = D->getOwningModule())
-    return M->isInterfaceOrPartition();
-  return false;
-}
-
 static LinkageInfo getExternalLinkageFor(const NamedDecl *D) {
   return LinkageInfo::external();
 }
@@ -642,7 +636,13 @@ LinkageComputer::getLVForNamespaceScopeDecl(const 
NamedDecl *D,
     // (There is no equivalent in C99.)
     if (Context.getLangOpts().CPlusPlus && Var->getType().isConstQualified() &&
         !Var->getType().isVolatileQualified() && !Var->isInline() &&
-        !isDeclaredInModuleInterfaceOrPartition(Var) &&
+        ![Var]() {
+          // Check if it is module purview except private module fragment
+          // and implementation unit.
+          if (auto *M = Var->getOwningModule())
+            return M->isInterfaceOrPartition() || M->isImplicitGlobalModule();
+          return false;
+        }() &&
         !isa<VarTemplateSpecializationDecl>(Var) &&
         !Var->getDescribedVarTemplate()) {
       const VarDecl *PrevVar = Var->getPreviousDecl();
diff --git a/clang/test/Modules/pr99825.cppm b/clang/test/Modules/pr99825.cppm
new file mode 100644
index 00000000000000..fe6541c6e68e50
--- /dev/null
+++ b/clang/test/Modules/pr99825.cppm
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -std=c++20 %s -fsyntax-only -verify
+// expected-no-diagnostics
+export module mod;
+
+extern "C++"
+{
+    export constexpr auto x = 10;
+}

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to