Skip to content

Conversation

AaronBallman
Copy link
Collaborator

This requires invalid signatures of main to be diagnosed while still allowing for common extensions. Clang has always supported this.

This requires invalid signatures of main to be diagnosed while still
allowing for common extensions. Clang has always supported this.
@AaronBallman AaronBallman added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" c2y labels Oct 10, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 10, 2025

@llvm/pr-subscribers-clang

Author: Aaron Ballman (AaronBallman)

Changes

This requires invalid signatures of main to be diagnosed while still allowing for common extensions. Clang has always supported this.


Full diff: https://github.com/llvm/llvm-project/pull/162843.diff

2 Files Affected:

  • (added) clang/test/C/C2y/n3623.c (+74)
  • (modified) clang/www/c_status.html (+1-1)
diff --git a/clang/test/C/C2y/n3623.c b/clang/test/C/C2y/n3623.c
new file mode 100644
index 0000000000000..a557edadae078
--- /dev/null
+++ b/clang/test/C/C2y/n3623.c
@@ -0,0 +1,74 @@
+// RUN: %clang_cc1 -verify -std=c2y -DSTD1 %s
+// RUN: %clang_cc1 -verify -std=c2y -DSTD2 %s
+// RUN: %clang_cc1 -verify=gnu1 -std=gnu2y -DGNU1 %s
+// RUN: %clang_cc1 -verify -std=gnu2y -DGNU2 %s
+// RUN: %clang_cc1 -verify=gnu3 -std=gnu2y -DGNU3 %s
+// RUN: %clang_cc1 -verify -std=gnu2y -DGNU4 %s
+// RUN: %clang_cc1 -verify -std=gnu2y -DGNU5 %s
+// RUN: %clang_cc1 -verify -std=gnu2y -DGNU6 %s
+// RUN: %clang_cc1 -verify=gnu7 -std=gnu2y -DGNU7 %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin12 -verify -std=c2y -DDARWIN1 %s
+// RUN: %clang_cc1 -triple x86_64-pc-win32-mscv -verify -std=c2y -fms-compatibility -DMS1 %s
+// RUN: %clang_cc1 -triple x86_64-pc-win32-mscv -verify -std=c2y -fms-compatibility -DMS2 %s
+// RUN: %clang_cc1 -verify=invalid -std=c2y -DINVALID1 %s
+// RUN: %clang_cc1 -verify=invalid -std=c2y -DINVALID2 %s
+// expected-no-diagnostics
+
+/* WG14 N3623: Yes
+ * Earthly Demon XV: Definition of Main
+ *
+ * This validates that we accept the standard type definitions of main or some
+ * other implementation-defined type.
+ */
+
+typedef __WCHAR_TYPE__ wchar_t;
+
+// These are the signatures required by the standard.
+#if defined(STD1)
+int main(void) {}
+#elif defined(STD2)
+int main(int argc, char *argv[]) {}
+#endif
+
+// GNU extensions.
+#if defined(GNU1)
+void main(void) {} /* gnu1-warning {{return type of 'main' is not 'int'}}
+                      gnu1-note {{change return type to 'int'}}
+                    */
+#elif defined(GNU2)
+const int main(void) {}
+#elif defined(GNU3)
+int main(...) {} /* gnu3-warning {{'main' is not allowed to be declared variadic}} */
+#elif defined(GNU4)
+int main(int, const char **) {}
+#elif defined(GNU5)
+int main(int, char const * const *) {}
+#elif defined(GNU6)
+int main(int, char * const *) {}
+#elif defined(GNU7)
+int main(int) {} /* gnu7-warning {{only one parameter on 'main' declaration}} */
+#endif
+
+// Darwin extensions.
+#if defined(DARWIN1)
+int main(int argc, char *argv[], char *environ[], char **undocumented) {}
+#endif
+
+// Microsoft extensions.
+#if defined(MS1)
+int wmain(int, wchar_t *[]) {}
+#elif defined(MS2)
+int wmain(int, wchar_t *[], wchar_t *[]) {}
+#endif
+
+// Invalid signatures.
+#if defined(INVALID1)
+inline int main(int, char *[]); /* invalid-error {{'main' is not allowed to be declared inline}} */
+int main(int, char *[], char *[], float); /* invalid-error {{too many parameters (4) for 'main': must be 0, 2, or 3}} */
+float main(int); /* invalid-error {{'main' must return 'int'}} */
+_Noreturn int main(int, char *[]); /* invalid-warning {{'main' is not allowed to be declared _Noreturn}}
+                                      invalid-note {{remove '_Noreturn'}}
+                                    */
+#elif defined(INVALID2)
+static int main(void); /* invalid-warning {{'main' should not be declared static}} */
+#endif
diff --git a/clang/www/c_status.html b/clang/www/c_status.html
index f16c40202aa21..a6bcd4c197133 100644
--- a/clang/www/c_status.html
+++ b/clang/www/c_status.html
@@ -339,7 +339,7 @@ <h2 id="c2y">C2y implementation status</h2>
     <tr>
       <td>Earthly Demon XV: Definition of Main</td>
       <td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3623.pdf">N3623</a></td>
-      <td class="unknown" align="center">Unknown</td>
+      <td class="full" align="center">Yes</td>
 	</tr>
     <tr>
       <td>static_assert without UB</td>

@AaronBallman AaronBallman merged commit 2992d3d into llvm:main Oct 10, 2025
14 checks passed
@AaronBallman AaronBallman deleted the aballman-wg14-n3623 branch October 10, 2025 14:28
@llvm-ci
Copy link
Collaborator

llvm-ci commented Oct 10, 2025

LLVM Buildbot has detected a new failure on builder llvm-clang-aarch64-darwin running on doug-worker-5 while building clang at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/190/builds/28819

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'Clang :: C/C2y/n3623.c' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
/Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/bin/clang -cc1 -internal-isystem /Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/lib/clang/22/include -nostdsysteminc -verify -std=c2y -DSTD1 /Users/buildbot/buildbot-root2/aarch64-darwin/llvm-project/clang/test/C/C2y/n3623.c # RUN: at line 1
+ /Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/bin/clang -cc1 -internal-isystem /Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/lib/clang/22/include -nostdsysteminc -verify -std=c2y -DSTD1 /Users/buildbot/buildbot-root2/aarch64-darwin/llvm-project/clang/test/C/C2y/n3623.c
/Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/bin/clang -cc1 -internal-isystem /Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/lib/clang/22/include -nostdsysteminc -verify -std=c2y -DSTD2 /Users/buildbot/buildbot-root2/aarch64-darwin/llvm-project/clang/test/C/C2y/n3623.c # RUN: at line 2
+ /Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/bin/clang -cc1 -internal-isystem /Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/lib/clang/22/include -nostdsysteminc -verify -std=c2y -DSTD2 /Users/buildbot/buildbot-root2/aarch64-darwin/llvm-project/clang/test/C/C2y/n3623.c
/Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/bin/clang -cc1 -internal-isystem /Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/lib/clang/22/include -nostdsysteminc -verify=gnu1 -std=gnu2y -DGNU1 /Users/buildbot/buildbot-root2/aarch64-darwin/llvm-project/clang/test/C/C2y/n3623.c # RUN: at line 3
+ /Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/bin/clang -cc1 -internal-isystem /Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/lib/clang/22/include -nostdsysteminc -verify=gnu1 -std=gnu2y -DGNU1 /Users/buildbot/buildbot-root2/aarch64-darwin/llvm-project/clang/test/C/C2y/n3623.c
/Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/bin/clang -cc1 -internal-isystem /Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/lib/clang/22/include -nostdsysteminc -verify -std=gnu2y -DGNU2 /Users/buildbot/buildbot-root2/aarch64-darwin/llvm-project/clang/test/C/C2y/n3623.c # RUN: at line 4
+ /Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/bin/clang -cc1 -internal-isystem /Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/lib/clang/22/include -nostdsysteminc -verify -std=gnu2y -DGNU2 /Users/buildbot/buildbot-root2/aarch64-darwin/llvm-project/clang/test/C/C2y/n3623.c
/Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/bin/clang -cc1 -internal-isystem /Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/lib/clang/22/include -nostdsysteminc -verify=gnu3 -std=gnu2y -DGNU3 /Users/buildbot/buildbot-root2/aarch64-darwin/llvm-project/clang/test/C/C2y/n3623.c # RUN: at line 5
+ /Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/bin/clang -cc1 -internal-isystem /Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/lib/clang/22/include -nostdsysteminc -verify=gnu3 -std=gnu2y -DGNU3 /Users/buildbot/buildbot-root2/aarch64-darwin/llvm-project/clang/test/C/C2y/n3623.c
/Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/bin/clang -cc1 -internal-isystem /Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/lib/clang/22/include -nostdsysteminc -verify -std=gnu2y -DGNU4 /Users/buildbot/buildbot-root2/aarch64-darwin/llvm-project/clang/test/C/C2y/n3623.c # RUN: at line 6
+ /Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/bin/clang -cc1 -internal-isystem /Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/lib/clang/22/include -nostdsysteminc -verify -std=gnu2y -DGNU4 /Users/buildbot/buildbot-root2/aarch64-darwin/llvm-project/clang/test/C/C2y/n3623.c
/Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/bin/clang -cc1 -internal-isystem /Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/lib/clang/22/include -nostdsysteminc -verify -std=gnu2y -DGNU5 /Users/buildbot/buildbot-root2/aarch64-darwin/llvm-project/clang/test/C/C2y/n3623.c # RUN: at line 7
+ /Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/bin/clang -cc1 -internal-isystem /Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/lib/clang/22/include -nostdsysteminc -verify -std=gnu2y -DGNU5 /Users/buildbot/buildbot-root2/aarch64-darwin/llvm-project/clang/test/C/C2y/n3623.c
/Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/bin/clang -cc1 -internal-isystem /Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/lib/clang/22/include -nostdsysteminc -verify -std=gnu2y -DGNU6 /Users/buildbot/buildbot-root2/aarch64-darwin/llvm-project/clang/test/C/C2y/n3623.c # RUN: at line 8
+ /Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/bin/clang -cc1 -internal-isystem /Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/lib/clang/22/include -nostdsysteminc -verify -std=gnu2y -DGNU6 /Users/buildbot/buildbot-root2/aarch64-darwin/llvm-project/clang/test/C/C2y/n3623.c
/Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/bin/clang -cc1 -internal-isystem /Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/lib/clang/22/include -nostdsysteminc -verify=gnu7 -std=gnu2y -DGNU7 /Users/buildbot/buildbot-root2/aarch64-darwin/llvm-project/clang/test/C/C2y/n3623.c # RUN: at line 9
+ /Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/bin/clang -cc1 -internal-isystem /Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/lib/clang/22/include -nostdsysteminc -verify=gnu7 -std=gnu2y -DGNU7 /Users/buildbot/buildbot-root2/aarch64-darwin/llvm-project/clang/test/C/C2y/n3623.c
/Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/bin/clang -cc1 -internal-isystem /Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/lib/clang/22/include -nostdsysteminc -triple x86_64-apple-darwin12 -verify -std=c2y -DDARWIN1 /Users/buildbot/buildbot-root2/aarch64-darwin/llvm-project/clang/test/C/C2y/n3623.c # RUN: at line 10
+ /Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/bin/clang -cc1 -internal-isystem /Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/lib/clang/22/include -nostdsysteminc -triple x86_64-apple-darwin12 -verify -std=c2y -DDARWIN1 /Users/buildbot/buildbot-root2/aarch64-darwin/llvm-project/clang/test/C/C2y/n3623.c
/Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/bin/clang -cc1 -internal-isystem /Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/lib/clang/22/include -nostdsysteminc -triple x86_64-pc-win32-mscv -verify -std=c2y -fms-compatibility -DMS1 /Users/buildbot/buildbot-root2/aarch64-darwin/llvm-project/clang/test/C/C2y/n3623.c # RUN: at line 11
+ /Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/bin/clang -cc1 -internal-isystem /Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/lib/clang/22/include -nostdsysteminc -triple x86_64-pc-win32-mscv -verify -std=c2y -fms-compatibility -DMS1 /Users/buildbot/buildbot-root2/aarch64-darwin/llvm-project/clang/test/C/C2y/n3623.c
/Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/bin/clang -cc1 -internal-isystem /Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/lib/clang/22/include -nostdsysteminc -triple x86_64-pc-win32-mscv -verify -std=c2y -fms-compatibility -DMS2 /Users/buildbot/buildbot-root2/aarch64-darwin/llvm-project/clang/test/C/C2y/n3623.c # RUN: at line 12
+ /Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/bin/clang -cc1 -internal-isystem /Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/lib/clang/22/include -nostdsysteminc -triple x86_64-pc-win32-mscv -verify -std=c2y -fms-compatibility -DMS2 /Users/buildbot/buildbot-root2/aarch64-darwin/llvm-project/clang/test/C/C2y/n3623.c
/Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/bin/clang -cc1 -internal-isystem /Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/lib/clang/22/include -nostdsysteminc -verify=invalid -std=c2y -DINVALID1 /Users/buildbot/buildbot-root2/aarch64-darwin/llvm-project/clang/test/C/C2y/n3623.c # RUN: at line 13
+ /Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/bin/clang -cc1 -internal-isystem /Volumes/ExternalSSD/buildbot-root/aarch64-darwin/build/lib/clang/22/include -nostdsysteminc -verify=invalid -std=c2y -DINVALID1 /Users/buildbot/buildbot-root2/aarch64-darwin/llvm-project/clang/test/C/C2y/n3623.c
error: 'invalid-error' diagnostics expected but not seen: 
  File /Users/buildbot/buildbot-root2/aarch64-darwin/llvm-project/clang/test/C/C2y/n3623.c Line 67: too many parameters (4) for 'main': must be 0, 2, or 3
error: 'invalid-error' diagnostics seen but not expected: 
  File /Users/buildbot/buildbot-root2/aarch64-darwin/llvm-project/clang/test/C/C2y/n3623.c Line 67: fourth parameter of 'main' (platform-specific data) must be of type 'char **'
2 errors generated.

--

********************


@nico
Copy link
Contributor

nico commented Oct 10, 2025

Seems to fail on mac: http://45.33.8.238/macm1/115293/step_6.txt

…oh, llvm-ci already said this above too.

Looking?

@AaronBallman
Copy link
Collaborator Author

Seems to fail on mac: http://45.33.8.238/macm1/115293/step_6.txt

…oh, llvm-ci already said this above too.

Looking?

Yup, investigating and will either fix or revert shortly.

AaronBallman added a commit that referenced this pull request Oct 10, 2025
#162843 landed a test that is
broken on darwin:

https://lab.llvm.org/buildbot/#/builders/190/builds/28819

This is an attempted quick fix.
@AaronBallman
Copy link
Collaborator Author

f6caec6 should hopefully fix things up, I'll watch the bot

llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Oct 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c2y clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants