https://github.com/ashwinbanwari updated 
https://github.com/llvm/llvm-project/pull/146461

>From 845f99834c6c9a78c05396a0337051273b1ae138 Mon Sep 17 00:00:00 2001
From: Ashwin Banwari <ashwinkbanw...@gmail.com>
Date: Mon, 30 Jun 2025 20:45:39 -0700
Subject: [PATCH 1/6] Implement P3618R0

---
 clang/docs/ReleaseNotes.rst                      | 2 ++
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 +-
 clang/lib/Sema/SemaDecl.cpp                      | 9 +++------
 clang/test/SemaCXX/modules.cppm                  | 2 ++
 libcxx/utils/libcxx/test/features.py             | 2 +-
 5 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e6c8f9df22170..33dd07179aeea 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -135,6 +135,8 @@ C++2c Feature Support
 
 - Implemented `P2719R4 Type-aware allocation and deallocation functions 
<https://wg21.link/P2719>`_.
 
+- Implemented `P3618R0 Allow attaching main to the global 
module<https://wg21.link/P3618>`_.
+
 C++23 Feature Support
 ^^^^^^^^^^^^^^^^^^^^^
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 5062505cf3c01..d5d982d20eaa5 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1086,7 +1086,7 @@ def ext_main_used : Extension<
     "referring to 'main' within an expression is a Clang extension">, 
InGroup<Main>;
 def ext_main_invalid_linkage_specification : ExtWarn<
   "'main' should not be "
-  "'extern \"%select{C|C++}0\"'">, InGroup<Main>;
+  "'extern \"C\"'">, InGroup<Main>;
 
 /// parser diagnostics
 def ext_no_declarators : ExtWarn<"declaration does not declare anything">,
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index a34e2c9cbb003..61b82b8377e22 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -12400,12 +12400,9 @@ bool Sema::CheckFunctionDeclaration(Scope *S, 
FunctionDecl *NewFD,
 
 void Sema::CheckMain(FunctionDecl *FD, const DeclSpec &DS) {
   // [basic.start.main]p3
-  //    The main function shall not be declared with a linkage-specification.
-  if (FD->isExternCContext() ||
-      (FD->isExternCXXContext() &&
-       FD->getDeclContext()->getRedeclContext()->isTranslationUnit()))
-    Diag(FD->getLocation(), diag::ext_main_invalid_linkage_specification)
-        << FD->getLanguageLinkage();
+  //    The main function shall not be declared with C linkage-specification.
+  if (FD->isExternCContext())
+    Diag(FD->getLocation(), diag::ext_main_invalid_linkage_specification);
 
   // C++11 [basic.start.main]p3:
   //   A program that [...] declares main to be inline, static or
diff --git a/clang/test/SemaCXX/modules.cppm b/clang/test/SemaCXX/modules.cppm
index 5d0d6da44a2ed..ddbbc7cd86360 100644
--- a/clang/test/SemaCXX/modules.cppm
+++ b/clang/test/SemaCXX/modules.cppm
@@ -68,6 +68,8 @@ int n;
 //--- test3.cpp
 export module bar;
 
+extern "C++" int main() {}
+
 static int m;
 
 int n;
diff --git a/libcxx/utils/libcxx/test/features.py 
b/libcxx/utils/libcxx/test/features.py
index 74746e37d3bc4..a479ea48ac810 100644
--- a/libcxx/utils/libcxx/test/features.py
+++ b/libcxx/utils/libcxx/test/features.py
@@ -340,7 +340,7 @@ def _mingwSupportsModules(cfg):
             cfg,
             """
             export module test;
-            int main(int, char**) { return 0; }
+            extern "C++" int main(int, char**) { return 0; }
           """,
         ),
     ),

>From 70afaf39fb597d7d0ae50e7bf20bc3fa3d28e848 Mon Sep 17 00:00:00 2001
From: Ashwin Banwari <ashwinkbanw...@gmail.com>
Date: Mon, 30 Jun 2025 20:48:19 -0700
Subject: [PATCH 2/6] typo

---
 clang/docs/ReleaseNotes.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 33dd07179aeea..9877b0e651596 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -135,7 +135,7 @@ C++2c Feature Support
 
 - Implemented `P2719R4 Type-aware allocation and deallocation functions 
<https://wg21.link/P2719>`_.
 
-- Implemented `P3618R0 Allow attaching main to the global 
module<https://wg21.link/P3618>`_.
+- Implemented `P3618R0 Allow attaching main to the global module 
<https://wg21.link/P3618>`_.
 
 C++23 Feature Support
 ^^^^^^^^^^^^^^^^^^^^^

>From 880f14b1773c3064151e695a526127b79dc22db0 Mon Sep 17 00:00:00 2001
From: Ashwin Banwari <ashwinkbanw...@gmail.com>
Date: Mon, 30 Jun 2025 20:48:50 -0700
Subject: [PATCH 3/6] clang-format

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index d5d982d20eaa5..6e48f3bc88bab 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1084,9 +1084,9 @@ def warn_main_redefined : Warning<"variable named 'main' 
with external linkage "
     "has undefined behavior">, InGroup<Main>;
 def ext_main_used : Extension<
     "referring to 'main' within an expression is a Clang extension">, 
InGroup<Main>;
-def ext_main_invalid_linkage_specification : ExtWarn<
-  "'main' should not be "
-  "'extern \"C\"'">, InGroup<Main>;
+def ext_main_invalid_linkage_specification : ExtWarn<"'main' should not be "
+                                                     "'extern \"C\"'">,
+                                             InGroup<Main>;
 
 /// parser diagnostics
 def ext_no_declarators : ExtWarn<"declaration does not declare anything">,

>From fd91a7279ac8bf2109e7a6fc3f0e7fa745176289 Mon Sep 17 00:00:00 2001
From: Ashwin Banwari <ashwinkbanw...@gmail.com>
Date: Mon, 30 Jun 2025 21:24:22 -0700
Subject: [PATCH 4/6] fix libcxx test

---
 libcxx/utils/libcxx/test/features.py | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/libcxx/utils/libcxx/test/features.py 
b/libcxx/utils/libcxx/test/features.py
index a479ea48ac810..7e16a9b69fda8 100644
--- a/libcxx/utils/libcxx/test/features.py
+++ b/libcxx/utils/libcxx/test/features.py
@@ -336,13 +336,20 @@ def _mingwSupportsModules(cfg):
         or platform.system().lower().startswith("aix")
         # Avoid building on platforms that don't support modules properly.
         or not hasCompileFlag(cfg, "-Wno-reserved-module-identifier")
-        or not sourceBuilds(
+        # older versions don't support extern "C++", newer versions don't 
support main in named module.
+        or not (sourceBuilds(
             cfg,
             """
             export module test;
             extern "C++" int main(int, char**) { return 0; }
           """,
-        ),
+        ) or sourceBuilds(
+            cfg,
+            """
+            export module test;
+            int main(int, char**) { return 0; }
+          """,
+        )),
     ),
     # The time zone validation tests compare the output of zdump against the
     # output generated by <chrono>'s time zone support.

>From 035592a9ba9098f0153b38af191d3beb2ac14605 Mon Sep 17 00:00:00 2001
From: Ashwin Banwari <ashwinkbanw...@gmail.com>
Date: Mon, 30 Jun 2025 21:46:42 -0700
Subject: [PATCH 5/6] darker format

---
 libcxx/utils/libcxx/test/features.py | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/libcxx/utils/libcxx/test/features.py 
b/libcxx/utils/libcxx/test/features.py
index 7e16a9b69fda8..c478d99fbed00 100644
--- a/libcxx/utils/libcxx/test/features.py
+++ b/libcxx/utils/libcxx/test/features.py
@@ -337,19 +337,22 @@ def _mingwSupportsModules(cfg):
         # Avoid building on platforms that don't support modules properly.
         or not hasCompileFlag(cfg, "-Wno-reserved-module-identifier")
         # older versions don't support extern "C++", newer versions don't 
support main in named module.
-        or not (sourceBuilds(
-            cfg,
-            """
+        or not (
+            sourceBuilds(
+                cfg,
+                """
             export module test;
             extern "C++" int main(int, char**) { return 0; }
           """,
-        ) or sourceBuilds(
-            cfg,
-            """
+            )
+            or sourceBuilds(
+                cfg,
+                """
             export module test;
             int main(int, char**) { return 0; }
           """,
-        )),
+            )
+        ),
     ),
     # The time zone validation tests compare the output of zdump against the
     # output generated by <chrono>'s time zone support.

>From bf5dd7036bf6c369a4a3c26b2d8679280e780204 Mon Sep 17 00:00:00 2001
From: Ashwin Banwari <ashwinkbanw...@gmail.com>
Date: Mon, 30 Jun 2025 21:52:50 -0700
Subject: [PATCH 6/6] fix p3 test

---
 clang/test/CXX/basic/basic.start/basic.start.main/p3.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/test/CXX/basic/basic.start/basic.start.main/p3.cpp 
b/clang/test/CXX/basic/basic.start/basic.start.main/p3.cpp
index 497a9328c1156..a8cd523b0837f 100644
--- a/clang/test/CXX/basic/basic.start/basic.start.main/p3.cpp
+++ b/clang/test/CXX/basic/basic.start/basic.start.main/p3.cpp
@@ -102,11 +102,12 @@ namespace ns {
 }
 
 #elif TEST13
+// expected-no-diagnostics
 extern "C++" {
-  int main(); // expected-warning {{'main' should not be 'extern "C++"'}}
+  int main();
 }
 
-extern "C++" int main(); // expected-warning {{'main' should not be 'extern 
"C++"'}}
+extern "C++" int main();
 
 namespace ns1 {
   extern "C++" int main(); // ok

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

Reply via email to