Skip to content

[clang] [modules] Add err_main_in_named_module #146247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jun 30, 2025

Conversation

kish1n
Copy link
Contributor

@kish1n kish1n commented Jun 28, 2025

Close #146229

As the issue said, main shouldn't be in any modules.

new diagnostic output:

/my/code/directory/main.cpp:3:1: warning: 'main' should not be attached to a named module; consider adding C++ language linkage [-Wmain]
    3 | int main() {
      | ^
      | extern "C++" 
1 warning generated.

Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jun 28, 2025
@llvmbot
Copy link
Member

llvmbot commented Jun 28, 2025

@llvm/pr-subscribers-clang

Author: Ashwin Banwari (ashwinbanwari)

Changes

Close #146229

As the issue said, main shouldn't be in any modules.

New Error Output:

/my/code/directory/main.cpp:3:1: error: 'main' cannot be attached to a named module
    3 | int main() {
      | ^
1 error generated.

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

2 Files Affected:

  • (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+2)
  • (modified) clang/lib/Sema/SemaDecl.cpp (+8)
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 5062505cf3c01..ce9017ded0087 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1062,6 +1062,8 @@ def err_constexpr_main : Error<
   "'main' is not allowed to be declared %select{constexpr|consteval}0">;
 def err_deleted_main : Error<"'main' is not allowed to be deleted">;
 def err_mainlike_template_decl : Error<"%0 cannot be a template">;
+def err_main_in_named_module
+    : Error<"'main' cannot be attached to a named module">;
 def err_main_returns_nonint : Error<"'main' must return 'int'">;
 def ext_main_returns_nonint : ExtWarn<"return type of 'main' is not 'int'">,
     InGroup<MainReturnType>;
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index e1cccf068b5aa..c4ddfda9f447f 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -12490,6 +12490,14 @@ void Sema::CheckMain(FunctionDecl *FD, const DeclSpec &DS) {
                                 : FixItHint());
       FD->setInvalidDecl(true);
     }
+
+    // In C++ [basic.start.main]p3, it is said a program attaching main to a
+    // named module is ill-formed.
+    if (FD->isInNamedModule()) {
+      Diag(FD->getTypeSpecStartLoc(), diag::err_main_in_named_module)
+          << FixItHint();
+      FD->setInvalidDecl(true);
+    }
   }
 
   // Treat protoless main() as nullary.

@kish1n kish1n changed the title [clang] [modules] add err_main_in_named_module [clang] [modules] Add err_main_in_named_module Jun 28, 2025
@Mr-Anyone
Copy link
Contributor

Mr-Anyone commented Jun 29, 2025

You should add a test case and a release note for this patch to be accepted.

@MikailBag
Copy link

MikailBag commented Jun 29, 2025

It seems that clang trunk warns on extern "C++" main, which is now allowed after P3618.

I think it will be helpful for the UX to land this change after that warning is fixed.

(Disclaimer: I'm not clang contributor, just clang user)

@ChuanqiXu9
Copy link
Member

I prefer a warning instead of hard error. There are already users who uses this.

Copy link
Member

@ChuanqiXu9 ChuanqiXu9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks.

@@ -1062,6 +1062,8 @@ def err_constexpr_main : Error<
"'main' is not allowed to be declared %select{constexpr|consteval}0">;
def err_deleted_main : Error<"'main' is not allowed to be deleted">;
def err_mainlike_template_decl : Error<"%0 cannot be a template">;
def warn_main_in_named_module
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a warning option for it.

@@ -1062,6 +1062,8 @@ def err_constexpr_main : Error<
"'main' is not allowed to be declared %select{constexpr|consteval}0">;
def err_deleted_main : Error<"'main' is not allowed to be deleted">;
def err_mainlike_template_decl : Error<"%0 cannot be a template">;
def warn_main_in_named_module
: Warning<"'main' should not be attached to a named module">;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And suggest them to wrap it into language linkage.

@kish1n kish1n requested a review from ChuanqiXu9 June 30, 2025 08:25
@@ -650,6 +650,9 @@ Improvements to Clang's diagnostics
#GH69470, #GH59391, #GH58172, #GH46215, #GH45915, #GH45891, #GH44490,
#GH36703, #GH32903, #GH23312, #GH69874.

- A warning is now emitted when ``main`` is attached to a named module,
which can be turned off with ``-Wno-main``. (#GH146247)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to change the warning name to Wmain-attached-to-named-modules. There were a lot examples declaring a warning with a warning name in place.

@ChuanqiXu9
Copy link
Member

Please use a new email name. We don't accept github.noreply mail.

@ChuanqiXu9 ChuanqiXu9 merged commit 473769e into llvm:main Jun 30, 2025
3 checks passed
Copy link

@ashwinbanwari Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

@llvm-ci
Copy link
Collaborator

llvm-ci commented Jun 30, 2025

LLVM Buildbot has detected a new failure on builder openmp-offload-amdgpu-runtime-2 running on rocm-worker-hw-02 while building clang at step 7 "Add check check-clang".

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

Here is the relevant piece of the build log for the reference
Step 7 (Add check check-clang) failure: test (failure)
******************** TEST 'Clang :: Driver/autocomplete.c' FAILED ********************
Exit Code: 1

Command Output (stdout):
--



-###	Print (but do not run) the commands to run for this compilation
--amdgpu-arch-tool=	Tool used for detecting AMD GPU arch in the system.
--analyze	Run the static analyzer
--analyzer-output	Static analyzer report output format (html|plist|plist-multi-file|plist-html|sarif|sarif-html|text).
--ansi	
--config-system-dir=	System directory for configuration files
--config-user-dir=	User directory for configuration files
--config=	Specify configuration file
--coverage	
--cuda-compile-host-device	Compile CUDA code for both host and device (default). Has no effect on non-CUDA compilations.
--cuda-device-only	Compile CUDA code for device only
--cuda-feature=	Manually specify the CUDA feature to use
--cuda-gpu-arch=	
--cuda-host-only	Compile CUDA code for host only. Has no effect on non-CUDA compilations.
--cuda-include-ptx=	Include PTX for the following GPU architecture (e.g. sm_35) or 'all'. May be specified more than once.
--cuda-noopt-device-debug	Enable device-side debug info generation. Disables ptxas optimizations.
--cuda-path-ignore-env	Ignore environment variables to detect CUDA installation
--cuda-path=	CUDA installation path
--driver-mode=	Set the driver mode to either 'gcc', 'g++', 'cpp', 'cl' or 'flang'
--dxv-path=	DXIL validator installation path
--embed-dir=	Add directory to embed search path
--emit-extension-symbol-graphs	Generate additional symbol graphs for extended modules.
--emit-static-lib	Enable linker job to emit a static library.
--end-no-unused-arguments	Start emitting warnings for unused driver arguments
--extract-api-ignores=	Comma separated list of files containing a new line separated list of API symbols to ignore when extracting API information.
--gcc-install-dir=	Use GCC installation in the specified directory. The directory ends with path components like 'lib{,32,64}/gcc{,-cross}/$triple/$version'. Note: executables (e.g. ld) used by the compiler are not overridden by the selected GCC installation
--gcc-toolchain=	Specify a directory where Clang can find 'include' and 'lib{,32,64}/gcc{,-cross}/$triple/$version'. Clang will use the GCC installation with the largest version
--gcc-triple=	Search for the GCC installation with the specified triple.
--gpu-bundle-output	Bundle output files of HIP device compilation
--gpu-instrument-lib=	Instrument device library for HIP, which is a LLVM bitcode containing __cyg_profile_func_enter and __cyg_profile_func_exit
--gpu-max-threads-per-block=	Default max threads per block for kernel launch bounds for HIP
--gpu-use-aux-triple-only	Prepare '-aux-triple' only without populating '-aux-target-cpu' and '-aux-target-feature'.
--help	Display available options
--help-hidden	Display help for hidden options
--hip-device-lib-path=	
--hip-device-lib=	HIP device library
--hip-link	Link clang-offload-bundler bundles for HIP
--hip-path=	HIP runtime installation path, used for finding HIP version and adding HIP include path.
--hip-version=	HIP version in the format of major.minor.patch
--hipspv-pass-plugin=	path to a pass plugin for HIP to SPIR-V passes.
--hipstdpar	Enable HIP acceleration for standard parallel algorithms
--hipstdpar-interpose-alloc	Replace all memory allocation / deallocation calls with hipManagedMalloc / hipFree equivalents
...

@llvm-ci
Copy link
Collaborator

llvm-ci commented Jun 30, 2025

LLVM Buildbot has detected a new failure on builder llvm-clang-x86_64-sie-ubuntu-fast running on sie-linux-worker while building clang at step 6 "test-build-unified-tree-check-all".

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

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 :: Driver/autocomplete.c' FAILED ********************
Exit Code: 1

Command Output (stdout):
--



-###	Print (but do not run) the commands to run for this compilation
--amdgpu-arch-tool=	Tool used for detecting AMD GPU arch in the system.
--analyze	Run the static analyzer
--analyzer-output	Static analyzer report output format (html|plist|plist-multi-file|plist-html|sarif|sarif-html|text).
--ansi	
--config-system-dir=	System directory for configuration files
--config-user-dir=	User directory for configuration files
--config=	Specify configuration file
--coverage	
--cuda-compile-host-device	Compile CUDA code for both host and device (default). Has no effect on non-CUDA compilations.
--cuda-device-only	Compile CUDA code for device only
--cuda-feature=	Manually specify the CUDA feature to use
--cuda-gpu-arch=	
--cuda-host-only	Compile CUDA code for host only. Has no effect on non-CUDA compilations.
--cuda-include-ptx=	Include PTX for the following GPU architecture (e.g. sm_35) or 'all'. May be specified more than once.
--cuda-noopt-device-debug	Enable device-side debug info generation. Disables ptxas optimizations.
--cuda-path-ignore-env	Ignore environment variables to detect CUDA installation
--cuda-path=	CUDA installation path
--driver-mode=	Set the driver mode to either 'gcc', 'g++', 'cpp', 'cl' or 'flang'
--dxv-path=	DXIL validator installation path
--embed-dir=	Add directory to embed search path
--emit-extension-symbol-graphs	Generate additional symbol graphs for extended modules.
--emit-static-lib	Enable linker job to emit a static library.
--end-no-unused-arguments	Start emitting warnings for unused driver arguments
--extract-api-ignores=	Comma separated list of files containing a new line separated list of API symbols to ignore when extracting API information.
--gcc-install-dir=	Use GCC installation in the specified directory. The directory ends with path components like 'lib{,32,64}/gcc{,-cross}/$triple/$version'. Note: executables (e.g. ld) used by the compiler are not overridden by the selected GCC installation
--gcc-toolchain=	Specify a directory where Clang can find 'include' and 'lib{,32,64}/gcc{,-cross}/$triple/$version'. Clang will use the GCC installation with the largest version
--gcc-triple=	Search for the GCC installation with the specified triple.
--gpu-bundle-output	Bundle output files of HIP device compilation
--gpu-instrument-lib=	Instrument device library for HIP, which is a LLVM bitcode containing __cyg_profile_func_enter and __cyg_profile_func_exit
--gpu-max-threads-per-block=	Default max threads per block for kernel launch bounds for HIP
--gpu-use-aux-triple-only	Prepare '-aux-triple' only without populating '-aux-target-cpu' and '-aux-target-feature'.
--help	Display available options
--help-hidden	Display help for hidden options
--hip-device-lib-path=	
--hip-device-lib=	HIP device library
--hip-link	Link clang-offload-bundler bundles for HIP
--hip-path=	HIP runtime installation path, used for finding HIP version and adding HIP include path.
--hip-version=	HIP version in the format of major.minor.patch
--hipspv-pass-plugin=	path to a pass plugin for HIP to SPIR-V passes.
--hipstdpar	Enable HIP acceleration for standard parallel algorithms
--hipstdpar-interpose-alloc	Replace all memory allocation / deallocation calls with hipManagedMalloc / hipFree equivalents
...

@kish1n
Copy link
Contributor Author

kish1n commented Jun 30, 2025

It seems I need to add the line // WARNING-NEXT: -Wmain-attached-to-named-module on this line to fix the autocomplete test.

What is the process to amend this PR?

@llvm-ci
Copy link
Collaborator

llvm-ci commented Jun 30, 2025

LLVM Buildbot has detected a new failure on builder llvm-clang-aarch64-darwin running on doug-worker-4 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/22459

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 :: Driver/autocomplete.c' FAILED ********************
Exit Code: 1

Command Output (stdout):
--



-###	Print (but do not run) the commands to run for this compilation
--amdgpu-arch-tool=	Tool used for detecting AMD GPU arch in the system.
--analyze	Run the static analyzer
--analyzer-output	Static analyzer report output format (html|plist|plist-multi-file|plist-html|sarif|sarif-html|text).
--ansi	
--config-system-dir=	System directory for configuration files
--config-user-dir=	User directory for configuration files
--config=	Specify configuration file
--coverage	
--cuda-compile-host-device	Compile CUDA code for both host and device (default). Has no effect on non-CUDA compilations.
--cuda-device-only	Compile CUDA code for device only
--cuda-feature=	Manually specify the CUDA feature to use
--cuda-gpu-arch=	
--cuda-host-only	Compile CUDA code for host only. Has no effect on non-CUDA compilations.
--cuda-include-ptx=	Include PTX for the following GPU architecture (e.g. sm_35) or 'all'. May be specified more than once.
--cuda-noopt-device-debug	Enable device-side debug info generation. Disables ptxas optimizations.
--cuda-path-ignore-env	Ignore environment variables to detect CUDA installation
--cuda-path=	CUDA installation path
--driver-mode=	Set the driver mode to either 'gcc', 'g++', 'cpp', 'cl' or 'flang'
--dxv-path=	DXIL validator installation path
--embed-dir=	Add directory to embed search path
--emit-extension-symbol-graphs	Generate additional symbol graphs for extended modules.
--emit-static-lib	Enable linker job to emit a static library.
--end-no-unused-arguments	Start emitting warnings for unused driver arguments
--extract-api-ignores=	Comma separated list of files containing a new line separated list of API symbols to ignore when extracting API information.
--gcc-install-dir=	Use GCC installation in the specified directory. The directory ends with path components like 'lib{,32,64}/gcc{,-cross}/$triple/$version'. Note: executables (e.g. ld) used by the compiler are not overridden by the selected GCC installation
--gcc-toolchain=	Specify a directory where Clang can find 'include' and 'lib{,32,64}/gcc{,-cross}/$triple/$version'. Clang will use the GCC installation with the largest version
--gcc-triple=	Search for the GCC installation with the specified triple.
--gpu-bundle-output	Bundle output files of HIP device compilation
--gpu-instrument-lib=	Instrument device library for HIP, which is a LLVM bitcode containing __cyg_profile_func_enter and __cyg_profile_func_exit
--gpu-max-threads-per-block=	Default max threads per block for kernel launch bounds for HIP
--gpu-use-aux-triple-only	Prepare '-aux-triple' only without populating '-aux-target-cpu' and '-aux-target-feature'.
--help	Display available options
--help-hidden	Display help for hidden options
--hip-device-lib-path=	
--hip-device-lib=	HIP device library
--hip-link	Link clang-offload-bundler bundles for HIP
--hip-path=	HIP runtime installation path, used for finding HIP version and adding HIP include path.
--hip-version=	HIP version in the format of major.minor.patch
--hipspv-pass-plugin=	path to a pass plugin for HIP to SPIR-V passes.
--hipstdpar	Enable HIP acceleration for standard parallel algorithms
--hipstdpar-interpose-alloc	Replace all memory allocation / deallocation calls with hipManagedMalloc / hipFree equivalents
...

@jplehr
Copy link
Contributor

jplehr commented Jun 30, 2025

It seems I need to add the line // WARNING-NEXT: -Wmain-attached-to-named-module on this line to fix the autocomplete test.

What is the process to amend this PR?

I think you can open a new PR that fixes the issue.

@llvm-ci
Copy link
Collaborator

llvm-ci commented Jun 30, 2025

LLVM Buildbot has detected a new failure on builder premerge-monolithic-linux running on premerge-linux-1 while building clang at step 7 "test-build-unified-tree-check-all".

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

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

Command Output (stdout):
--



-###	Print (but do not run) the commands to run for this compilation
--amdgpu-arch-tool=	Tool used for detecting AMD GPU arch in the system.
--analyze	Run the static analyzer
--analyzer-output	Static analyzer report output format (html|plist|plist-multi-file|plist-html|sarif|sarif-html|text).
--ansi	
--config-system-dir=	System directory for configuration files
--config-user-dir=	User directory for configuration files
--config=	Specify configuration file
--coverage	
--cuda-compile-host-device	Compile CUDA code for both host and device (default). Has no effect on non-CUDA compilations.
--cuda-device-only	Compile CUDA code for device only
--cuda-feature=	Manually specify the CUDA feature to use
--cuda-gpu-arch=	
--cuda-host-only	Compile CUDA code for host only. Has no effect on non-CUDA compilations.
--cuda-include-ptx=	Include PTX for the following GPU architecture (e.g. sm_35) or 'all'. May be specified more than once.
--cuda-noopt-device-debug	Enable device-side debug info generation. Disables ptxas optimizations.
--cuda-path-ignore-env	Ignore environment variables to detect CUDA installation
--cuda-path=	CUDA installation path
--driver-mode=	Set the driver mode to either 'gcc', 'g++', 'cpp', 'cl' or 'flang'
--dxv-path=	DXIL validator installation path
--embed-dir=	Add directory to embed search path
--emit-extension-symbol-graphs	Generate additional symbol graphs for extended modules.
--emit-static-lib	Enable linker job to emit a static library.
--end-no-unused-arguments	Start emitting warnings for unused driver arguments
--extract-api-ignores=	Comma separated list of files containing a new line separated list of API symbols to ignore when extracting API information.
--gcc-install-dir=	Use GCC installation in the specified directory. The directory ends with path components like 'lib{,32,64}/gcc{,-cross}/$triple/$version'. Note: executables (e.g. ld) used by the compiler are not overridden by the selected GCC installation
--gcc-toolchain=	Specify a directory where Clang can find 'include' and 'lib{,32,64}/gcc{,-cross}/$triple/$version'. Clang will use the GCC installation with the largest version
--gcc-triple=	Search for the GCC installation with the specified triple.
--gpu-bundle-output	Bundle output files of HIP device compilation
--gpu-instrument-lib=	Instrument device library for HIP, which is a LLVM bitcode containing __cyg_profile_func_enter and __cyg_profile_func_exit
--gpu-max-threads-per-block=	Default max threads per block for kernel launch bounds for HIP
--gpu-use-aux-triple-only	Prepare '-aux-triple' only without populating '-aux-target-cpu' and '-aux-target-feature'.
--help	Display available options
--help-hidden	Display help for hidden options
--hip-device-lib-path=	
--hip-device-lib=	HIP device library
--hip-link	Link clang-offload-bundler bundles for HIP
--hip-path=	HIP runtime installation path, used for finding HIP version and adding HIP include path.
--hip-version=	HIP version in the format of major.minor.patch
--hipspv-pass-plugin=	path to a pass plugin for HIP to SPIR-V passes.
--hipstdpar	Enable HIP acceleration for standard parallel algorithms
--hipstdpar-interpose-alloc	Replace all memory allocation / deallocation calls with hipManagedMalloc / hipFree equivalents
...

@ChuanqiXu9
Copy link
Member

FWIW, I fixed it in 5186d4a to avoid affecting more people longer.

@llvm-ci
Copy link
Collaborator

llvm-ci commented Jun 30, 2025

LLVM Buildbot has detected a new failure on builder clang-x86_64-debian-fast running on gribozavr4 while building clang at step 6 "test-build-unified-tree-check-all".

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

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 :: Driver/autocomplete.c' FAILED ********************
Exit Code: 1

Command Output (stdout):
--



-###	Print (but do not run) the commands to run for this compilation
--amdgpu-arch-tool=	Tool used for detecting AMD GPU arch in the system.
--analyze	Run the static analyzer
--analyzer-output	Static analyzer report output format (html|plist|plist-multi-file|plist-html|sarif|sarif-html|text).
--ansi	
--config-system-dir=	System directory for configuration files
--config-user-dir=	User directory for configuration files
--config=	Specify configuration file
--coverage	
--cuda-compile-host-device	Compile CUDA code for both host and device (default). Has no effect on non-CUDA compilations.
--cuda-device-only	Compile CUDA code for device only
--cuda-feature=	Manually specify the CUDA feature to use
--cuda-gpu-arch=	
--cuda-host-only	Compile CUDA code for host only. Has no effect on non-CUDA compilations.
--cuda-include-ptx=	Include PTX for the following GPU architecture (e.g. sm_35) or 'all'. May be specified more than once.
--cuda-noopt-device-debug	Enable device-side debug info generation. Disables ptxas optimizations.
--cuda-path-ignore-env	Ignore environment variables to detect CUDA installation
--cuda-path=	CUDA installation path
--driver-mode=	Set the driver mode to either 'gcc', 'g++', 'cpp', 'cl' or 'flang'
--dxv-path=	DXIL validator installation path
--embed-dir=	Add directory to embed search path
--emit-extension-symbol-graphs	Generate additional symbol graphs for extended modules.
--emit-static-lib	Enable linker job to emit a static library.
--end-no-unused-arguments	Start emitting warnings for unused driver arguments
--extract-api-ignores=	Comma separated list of files containing a new line separated list of API symbols to ignore when extracting API information.
--gcc-install-dir=	Use GCC installation in the specified directory. The directory ends with path components like 'lib{,32,64}/gcc{,-cross}/$triple/$version'. Note: executables (e.g. ld) used by the compiler are not overridden by the selected GCC installation
--gcc-toolchain=	Specify a directory where Clang can find 'include' and 'lib{,32,64}/gcc{,-cross}/$triple/$version'. Clang will use the GCC installation with the largest version
--gcc-triple=	Search for the GCC installation with the specified triple.
--gpu-bundle-output	Bundle output files of HIP device compilation
--gpu-instrument-lib=	Instrument device library for HIP, which is a LLVM bitcode containing __cyg_profile_func_enter and __cyg_profile_func_exit
--gpu-max-threads-per-block=	Default max threads per block for kernel launch bounds for HIP
--gpu-use-aux-triple-only	Prepare '-aux-triple' only without populating '-aux-target-cpu' and '-aux-target-feature'.
--help	Display available options
--help-hidden	Display help for hidden options
--hip-device-lib-path=	
--hip-device-lib=	HIP device library
--hip-link	Link clang-offload-bundler bundles for HIP
--hip-path=	HIP runtime installation path, used for finding HIP version and adding HIP include path.
--hip-version=	HIP version in the format of major.minor.patch
--hipspv-pass-plugin=	path to a pass plugin for HIP to SPIR-V passes.
--hipstdpar	Enable HIP acceleration for standard parallel algorithms
--hipstdpar-interpose-alloc	Replace all memory allocation / deallocation calls with hipManagedMalloc / hipFree equivalents
...

@llvm-ci
Copy link
Collaborator

llvm-ci commented Jun 30, 2025

LLVM Buildbot has detected a new failure on builder llvm-x86_64-debian-dylib running on gribozavr4 while building clang at step 6 "test-build-unified-tree-check-clang".

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

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

Command Output (stdout):
--



-###	Print (but do not run) the commands to run for this compilation
--amdgpu-arch-tool=	Tool used for detecting AMD GPU arch in the system.
--analyze	Run the static analyzer
--analyzer-output	Static analyzer report output format (html|plist|plist-multi-file|plist-html|sarif|sarif-html|text).
--ansi	
--config-system-dir=	System directory for configuration files
--config-user-dir=	User directory for configuration files
--config=	Specify configuration file
--coverage	
--cuda-compile-host-device	Compile CUDA code for both host and device (default). Has no effect on non-CUDA compilations.
--cuda-device-only	Compile CUDA code for device only
--cuda-feature=	Manually specify the CUDA feature to use
--cuda-gpu-arch=	
--cuda-host-only	Compile CUDA code for host only. Has no effect on non-CUDA compilations.
--cuda-include-ptx=	Include PTX for the following GPU architecture (e.g. sm_35) or 'all'. May be specified more than once.
--cuda-noopt-device-debug	Enable device-side debug info generation. Disables ptxas optimizations.
--cuda-path-ignore-env	Ignore environment variables to detect CUDA installation
--cuda-path=	CUDA installation path
--driver-mode=	Set the driver mode to either 'gcc', 'g++', 'cpp', 'cl' or 'flang'
--dxv-path=	DXIL validator installation path
--embed-dir=	Add directory to embed search path
--emit-extension-symbol-graphs	Generate additional symbol graphs for extended modules.
--emit-static-lib	Enable linker job to emit a static library.
--end-no-unused-arguments	Start emitting warnings for unused driver arguments
--extract-api-ignores=	Comma separated list of files containing a new line separated list of API symbols to ignore when extracting API information.
--gcc-install-dir=	Use GCC installation in the specified directory. The directory ends with path components like 'lib{,32,64}/gcc{,-cross}/$triple/$version'. Note: executables (e.g. ld) used by the compiler are not overridden by the selected GCC installation
--gcc-toolchain=	Specify a directory where Clang can find 'include' and 'lib{,32,64}/gcc{,-cross}/$triple/$version'. Clang will use the GCC installation with the largest version
--gcc-triple=	Search for the GCC installation with the specified triple.
--gpu-bundle-output	Bundle output files of HIP device compilation
--gpu-instrument-lib=	Instrument device library for HIP, which is a LLVM bitcode containing __cyg_profile_func_enter and __cyg_profile_func_exit
--gpu-max-threads-per-block=	Default max threads per block for kernel launch bounds for HIP
--gpu-use-aux-triple-only	Prepare '-aux-triple' only without populating '-aux-target-cpu' and '-aux-target-feature'.
--help	Display available options
--help-hidden	Display help for hidden options
--hip-device-lib-path=	
--hip-device-lib=	HIP device library
--hip-link	Link clang-offload-bundler bundles for HIP
--hip-path=	HIP runtime installation path, used for finding HIP version and adding HIP include path.
--hip-version=	HIP version in the format of major.minor.patch
--hipspv-pass-plugin=	path to a pass plugin for HIP to SPIR-V passes.
--hipstdpar	Enable HIP acceleration for standard parallel algorithms
--hipstdpar-interpose-alloc	Replace all memory allocation / deallocation calls with hipManagedMalloc / hipFree equivalents
...

@mikaelholmen
Copy link
Collaborator

mikaelholmen commented Jun 30, 2025

Hello @ashwinbanwari

With this patch I get

Unexpectedly Passed Tests (5):
  llvm-libc++-shared.cfg.in :: libcxx/selftest/modules/std-and-std.compat-module.sh.cpp
  llvm-libc++-shared.cfg.in :: libcxx/selftest/modules/std-module.sh.cpp
  llvm-libc++-shared.cfg.in :: libcxx/selftest/modules/std.compat-module.sh.cpp
  llvm-libc++-shared.cfg.in :: std/modules/std.compat.pass.cpp
  llvm-libc++-shared.cfg.in :: std/modules/std.pass.cpp

any idea what's happening?

@qinkunbao
Copy link
Member

Hi, can you take a look at the buildbot failure?

https://lab.llvm.org/buildbot/#/builders/55/builds/13509

@ChuanqiXu9
Copy link
Member

Didn't know it. I'll revert this.

@ashwinbanwari it looks like you need to remove the diagnostics with extern "C++" main and apply it with libc++ and land this finally.

ChuanqiXu9 added a commit that referenced this pull request Jun 30, 2025
This reverts commit 473769e.

It breaks test in libc++

See #146247
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Jun 30, 2025
rlavaee pushed a commit to rlavaee/llvm-project that referenced this pull request Jul 1, 2025
Close llvm#146229

As the issue said, main shouldn't be in any modules.

new diagnostic output:
```
/my/code/directory/main.cpp:3:1: warning: 'main' should not be attached to a named module; consider adding C++ language linkage [-Wmain]
    3 | int main() {
      | ^
      | extern "C++" 
1 warning generated.
```
rlavaee pushed a commit to rlavaee/llvm-project that referenced this pull request Jul 1, 2025
rlavaee pushed a commit to rlavaee/llvm-project that referenced this pull request Jul 1, 2025
Close llvm#146229

As the issue said, main shouldn't be in any modules.

new diagnostic output:
```
/my/code/directory/main.cpp:3:1: warning: 'main' should not be attached to a named module; consider adding C++ language linkage [-Wmain]
    3 | int main() {
      | ^
      | extern "C++" 
1 warning generated.
```
rlavaee pushed a commit to rlavaee/llvm-project that referenced this pull request Jul 1, 2025
kish1n added a commit to kish1n/llvm-project that referenced this pull request Jul 2, 2025
ChuanqiXu9 pushed a commit that referenced this pull request Jul 3, 2025
Revival of #146247 which got
reverted for broken test.

Now that #146461 is merged to
allow `extern "C++"` for main, we can merge this change.
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Jul 3, 2025
Revival of llvm/llvm-project#146247 which got
reverted for broken test.

Now that llvm/llvm-project#146461 is merged to
allow `extern "C++"` for main, we can merge this change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

[clang] [modules] Clang accepts ill-formed program with main attached to named module
9 participants