Skip to content

Make module std; and module std.compat; work with Clang#5982

Open
cpplearner wants to merge 11 commits into
microsoft:mainfrom
cpplearner:clang-modules
Open

Make module std; and module std.compat; work with Clang#5982
cpplearner wants to merge 11 commits into
microsoft:mainfrom
cpplearner:clang-modules

Conversation

@cpplearner

@cpplearner cpplearner commented Jan 1, 2026

Copy link
Copy Markdown
Contributor

This adds Clang diagnostic suppressions as requested in #5975, and makes the module-related tests work with clang-cl.

Thanks to LLVM-98761 and LLVM-89772, clang-cl understands the Clang-style options needed to produce and consume Built Module Interfaces (BMIs). This is good enough for our test purposes.

I need to guard a line that calls source_location::column, because Clang and MSVC produce different values. This isn't specific to modules. The difference can also be found in the P1208R6_source_location test.

I also need to workaround a bug, where clang thinks the declaration of _alloca in <malloc.h> has conflicting ownership. This looks similar to LLVM-37969, though the trigger is different. I've added a repro to that issue. Note that the bug only affects ARM64/ARM64EC, because <intrin.h> is included in the global module fragment, which includes <malloc.h> on x64/x86.

Fixes #5975

@cpplearner cpplearner requested a review from a team as a code owner January 1, 2026 12:38
@github-project-automation github-project-automation Bot moved this to Initial Review in STL Code Reviews Jan 1, 2026
@StephanTLavavej StephanTLavavej added the modules C++23 modules, C++20 header units label Jan 1, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR improves support for building and testing the STL named modules (module std; and module std.compat;) with Clang/clang-cl, primarily by adding Clang-specific diagnostic suppressions and adjusting module-related test build steps to use Clang’s module BMI precompile flow.

Changes:

  • Add Clang diagnostic push/pop suppressions in std.ixx and std.compat.ixx (and a Clang/ARM64EC workaround include in std.ixx).
  • Extend the modules test matrix to include clang-cl configurations and refine the per-config flag composition.
  • Update module-related custom build scripts (Perl + Lit Python formats) to add Clang-specific --precompile steps and module compilation flags.
Show a summary per file
File Description
tests/std/tests/modules_20_matrix.lst Adds clang-cl rows and restructures module test matrix flags.
tests/std/tests/VSO_1775715_user_defined_modules/custombuild.pl Adds a Clang branch that precompiles the module interface before building.
tests/std/tests/VSO_1775715_user_defined_modules/custom_format.py Adds Clang-specific Lit build steps for precompiling module BMIs.
tests/std/tests/P2465R3_standard_library_modules/custombuild.pl Adds a Clang branch to precompile std.ixx/std.compat.ixx before building.
tests/std/tests/P2465R3_standard_library_modules/custom_format.py Adds Clang-specific Lit build steps for precompiling standard library module BMIs.
tests/std/include/test_header_units_and_modules.hpp Adjusts tests for Clang/ARM64EC generator workaround and Clang source_location::column() differences.
stl/modules/std.ixx Adds Clang diagnostic suppressions and a Clang-specific include workaround in the global module fragment.
stl/modules/std.compat.ixx Adds a global module fragment and Clang diagnostic suppression for reserved module identifier warnings.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 8/8 changed files
  • Comments generated: 4

Comment thread tests/std/tests/VSO_1775715_user_defined_modules/custombuild.pl Outdated
Comment thread tests/std/tests/P2465R3_standard_library_modules/custombuild.pl Outdated
Comment thread tests/std/tests/VSO_1775715_user_defined_modules/custom_format.py Outdated
Comment thread tests/std/tests/P2465R3_standard_library_modules/custom_format.py Outdated
@cpplearner cpplearner marked this pull request as draft May 13, 2026 12:49
@cpplearner

Copy link
Copy Markdown
Contributor Author

I'll keep this PR as draft until the next toolset update brings Clang 22.

Good news: Clang 22 fixed LLVM-173689, which makes the -fmodule-output option working. This will simplify the scripts.

Bad news: Clang 22 introduced -WTU-local-entity-exposure which brings a new issue, LLVM-195661, that needs workaround. (Not a showstopper: the issue only affects <complex> and an existing fallback path can be used.)

@StephanTLavavej StephanTLavavej moved this from Initial Review to Work In Progress in STL Code Reviews May 15, 2026
@StephanTLavavej

Copy link
Copy Markdown
Member

Thank you; I will try to prioritize this when I can focus on the STL again. (I believe I'll need to write Perl to make this work in the internal test harness, like most things that need custom Python for the GitHub test harness, which makes this way more obnoxious to deal with, through no fault of your own.)

@cpplearner

Copy link
Copy Markdown
Contributor Author

The -fmodule-output approach will minimize the custom logic. All we need to do is telling Clang that the ixx files are modules.

It will basically look like:

diff --git a/tests/std/tests/P2465R3_standard_library_modules/custom_format.py b/tests/std/tests/P2465R3_standard_library_modules/custom_format.py
index d7d6a69f..1cca3ff6 100644
--- a/tests/std/tests/P2465R3_standard_library_modules/custom_format.py
+++ b/tests/std/tests/P2465R3_standard_library_modules/custom_format.py
@@ -22,7 +22,12 @@ class CustomTestFormat(STLTestFormat):
         classicCpp = os.path.join(sourceDir, 'classic.cpp')

         # Dependency order is important here:
-        inputPaths = [stdIxx, stdCompatIxx, testCpp, test2Cpp, test3Cpp, test4Cpp, classicCpp]
+        moduleUnits = [stdIxx, stdCompatIxx]
+        traditionalUnits = [testCpp, test2Cpp, test3Cpp, test4Cpp, classicCpp]
+        if 'clang' in test.config.available_features:
+            inputPaths = ['-x', 'c++-module', *moduleUnits, '-x', 'none', *traditionalUnits]
+        else:
+            inputPaths = [*moduleUnits, *traditionalUnits]

         cmd = [test.cxx, *inputPaths, *test.flags, *test.compileFlags]

@cpplearner cpplearner marked this pull request as ready for review May 29, 2026 04:03
Copilot AI review requested due to automatic review settings May 29, 2026 04:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@StephanTLavavej StephanTLavavej moved this from Work In Progress to Initial Review in STL Code Reviews Jun 11, 2026
@StephanTLavavej StephanTLavavej requested a review from Copilot June 11, 2026 21:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot's findings

  • Files reviewed: 9/9 changed files
  • Comments generated: 2

Comment thread tests/std/tests/VSO_1775715_user_defined_modules/custombuild.pl Outdated
Comment thread tests/std/tests/P2465R3_standard_library_modules/custombuild.pl Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 12, 2026 07:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Comment thread stl/modules/std.compat.ixx
Comment on lines +25 to +27
PM_COMPILER="clang-cl" PM_CL="-fmodule-output -fprebuilt-module-path=. -Wno-unqualified-std-cast-call /MD"
PM_COMPILER="clang-cl" PM_CL="-fmodule-output -fprebuilt-module-path=. -Wno-unqualified-std-cast-call /MTd"
PM_COMPILER="clang-cl" PM_CL="-fmodule-output -fprebuilt-module-path=. -Wno-unqualified-std-cast-call /MT"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

usual_20_matrix.lst covers the same three variants. Maybe the contents of module_20_matrix.lst should more closely resemble usual_20_matrix.lst, maybe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

modules C++23 modules, C++20 header units

Projects

Status: Initial Review

Development

Successfully merging this pull request may close these issues.

Add a Clang-specific diagnostic ignore push-pop for module std;

3 participants