Skip to content

Commit 5c99c5f

Browse files
committed
Add Clang diagnostic pragmas in standard library modules
1 parent cbe2ee9 commit 5c99c5f

File tree

8 files changed

+90
-23
lines changed

8 files changed

+90
-23
lines changed

stl/modules/std.compat.ixx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
// Copyright (c) Microsoft Corporation.
22
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
33

4+
module;
5+
6+
#ifdef __clang__
7+
#pragma clang diagnostic push
8+
// warning: 'std' is a reserved name for a module [-Wreserved-module-identifier]
9+
#pragma clang diagnostic ignored "-Wreserved-module-identifier"
10+
#endif // defined(__clang__)
11+
412
export module std.compat;
513

614
export import std;
@@ -531,3 +539,7 @@ export using std::towlower;
531539
export using std::towupper;
532540
export using std::towctrans;
533541
export using std::wctrans;
542+
543+
#ifdef __clang__
544+
#pragma clang diagnostic pop
545+
#endif // defined(__clang__)

stl/modules/std.ixx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ module;
3434
// <intrin.h> defines some types outside of `extern "C"` or `extern "C++"`.
3535
#include <intrin.h>
3636

37+
#ifdef __clang__
38+
#pragma clang diagnostic push
39+
// warning: '#include <filename>' attaches the declarations to the named module 'std', which is not usually intended;
40+
// consider moving that directive before the module declaration [-Winclude-angled-in-module-purview]
41+
// warning: 'std' is a reserved name for a module [-Wreserved-module-identifier]
42+
#pragma clang diagnostic ignored "-Winclude-angled-in-module-purview"
43+
#pragma clang diagnostic ignored "-Wreserved-module-identifier"
44+
#endif // defined(__clang__)
45+
3746
export module std;
3847

3948
#pragma warning(push)
@@ -155,3 +164,6 @@ export module std;
155164
#include <cwctype>
156165

157166
#pragma warning(pop)
167+
#ifdef __clang__
168+
#pragma clang diagnostic pop
169+
#endif // defined(__clang__)

tests/std/include/test_header_units_and_modules.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,9 @@ constexpr bool impl_test_source_location() {
755755
using namespace std;
756756
const auto sl = source_location::current();
757757
assert(sl.line() == __LINE__ - 1);
758+
#ifndef __clang__
758759
assert(sl.column() == 38);
760+
#endif // !defined(__clang__)
759761

760762
#ifdef __EDG__
761763
assert(sl.function_name() == "bool impl_test_source_location()"sv);

tests/std/tests/P2465R3_standard_library_modules/custom_format.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,21 @@ def getBuildSteps(self, test, litConfig, shared):
2121
test4Cpp = os.path.join(sourceDir, 'test4.cpp')
2222
classicCpp = os.path.join(sourceDir, 'classic.cpp')
2323

24-
# Dependency order is important here:
25-
inputPaths = [stdIxx, stdCompatIxx, testCpp, test2Cpp, test3Cpp, test4Cpp, classicCpp]
24+
moduleUnits = [stdIxx, stdCompatIxx]
25+
traditionalUnits = [testCpp, test2Cpp, test3Cpp, test4Cpp, classicCpp]
2626

27-
cmd = [test.cxx, *inputPaths, *test.flags, *test.compileFlags]
27+
if 'clang' in test.cxx:
28+
for modulePath in moduleUnits:
29+
cmd = [test.cxx, '-x', 'c++-module', modulePath, '--precompile', *test.flags, *test.compileFlags]
30+
yield TestStep(cmd, shared.execDir, shared.env, False)
31+
32+
inputPaths = ['-x', 'c++-module', *moduleUnits, '-x', 'none', *traditionalUnits]
33+
cmd = [test.cxx, *inputPaths, *test.flags, *test.compileFlags]
34+
else:
35+
# Dependency order is important here:
36+
inputPaths = [*moduleUnits, *traditionalUnits]
37+
38+
cmd = [test.cxx, *inputPaths, *test.flags, *test.compileFlags]
2839

2940
if TestType.COMPILE in test.testType:
3041
cmd += ['/c']

tests/std/tests/P2465R3_standard_library_modules/custombuild.pl

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,20 @@ ()
1515
my $stdIxx = "$stlModulesDir\\std.ixx";
1616
my $stdCompatIxx = "$stlModulesDir\\std.compat.ixx";
1717

18-
# Dependency order is important here:
19-
my @inputPaths = ($stdIxx, $stdCompatIxx, "test.cpp", "test2.cpp", "test3.cpp", "test4.cpp", "classic.cpp");
18+
my @moduleUnits = ($stdIxx, $stdCompatIxx);
19+
my @traditionalUnits = ("test.cpp", "test2.cpp", "test3.cpp", "test4.cpp", "classic.cpp");
2020

21-
Run::ExecuteCL(join(" ", @inputPaths, "/Fe$cwd.exe"));
21+
if ($ENV{PM_COMPILER} =~ m/clang/) {
22+
for my $modulePath (@moduleUnits) {
23+
Run::ExecuteCL("-x c++-module $modulePath --precompile");
24+
}
25+
26+
Run::ExecuteCL(join(" ", "-x", "c++-module", @moduleUnits, "-x", "none", @traditionalUnits, "/Fe$cwd.exe"));
27+
} else {
28+
# Dependency order is important here:
29+
my @inputPaths = ($stdIxx, $stdCompatIxx, "test.cpp", "test2.cpp", "test3.cpp", "test4.cpp", "classic.cpp");
30+
31+
Run::ExecuteCL(join(" ", @inputPaths, "/Fe$cwd.exe"));
32+
}
2233
}
2334
1

tests/std/tests/VSO_1775715_user_defined_modules/custom_format.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,17 @@ def getBuildSteps(self, test, litConfig, shared):
1515
sourceDir = os.path.dirname(testCpp)
1616
userIxx = os.path.join(sourceDir, 'user.ixx')
1717

18-
# Dependency order is important here:
19-
inputPaths = [userIxx, testCpp]
18+
if 'clang' in test.cxx:
19+
cmd = [test.cxx, '-x', 'c++-module', userIxx, '--precompile', *test.flags, *test.compileFlags]
20+
yield TestStep(cmd, shared.execDir, shared.env, False)
2021

21-
cmd = [test.cxx, *inputPaths, *test.flags, *test.compileFlags]
22+
inputPaths = ['-x', 'c++-module', userIxx, '-x', 'none', testCpp]
23+
cmd = [test.cxx, *inputPaths, *test.flags, *test.compileFlags]
24+
else:
25+
# Dependency order is important here:
26+
inputPaths = [userIxx, testCpp]
27+
28+
cmd = [test.cxx, *inputPaths, *test.flags, *test.compileFlags]
2229

2330
if TestType.COMPILE in test.testType:
2431
cmd += ['/c']

tests/std/tests/VSO_1775715_user_defined_modules/custombuild.pl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@ ()
1010
{
1111
my $cwd = Run::GetCWDName();
1212

13-
# Dependency order is important here:
14-
my @inputPaths = ("user.ixx", "test.cpp");
13+
if ($ENV{PM_COMPILER} =~ m/clang/) {
14+
Run::ExecuteCL("-x c++-module user.ixx --precompile");
15+
Run::ExecuteCL("-x c++-module user.ixx -x none test.cpp /Fe$cwd.exe");
16+
} else {
17+
# Dependency order is important here:
18+
my @inputPaths = ("user.ixx", "test.cpp");
1519

16-
Run::ExecuteCL(join(" ", @inputPaths, "/Fe$cwd.exe"));
20+
Run::ExecuteCL(join(" ", @inputPaths, "/Fe$cwd.exe"));
21+
}
1722
}
1823
1

tests/std/tests/modules_20_matrix.lst

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,25 @@
33

44
RUNALL_INCLUDE ..\..\universal_prefix.lst
55
RUNALL_CROSSLIST
6-
* PM_CL="/w14365 /D_ENFORCE_FACET_SPECIALIZATIONS=1 /Zc:preprocessor"
6+
* PM_CL="/w14365 /D_ENFORCE_FACET_SPECIALIZATIONS=1"
77
RUNALL_CROSSLIST
88
* PM_CL="/w14640 /Zc:threadSafeInit- /EHsc /DTEST_STANDARD=20 /std:c++20"
99
* PM_CL="/w14640 /Zc:threadSafeInit- /EHsc /DTEST_STANDARD=23 /std:c++latest"
1010
RUNALL_CROSSLIST
11-
* PM_CL="/MD"
12-
* PM_CL="/MDd"
13-
* PM_CL="/MT"
14-
* PM_CL="/MTd"
15-
* PM_CL="/MDd /analyze:only /analyze:autolog-"
16-
* PM_CL="/MDd /GR- /D_HAS_STATIC_RTTI=0"
17-
* PM_CL="/MDd /utf-8"
18-
RUNALL_CROSSLIST
19-
PM_CL=""
20-
ASAN PM_CL="-fsanitize=address /Zi" PM_LINK="/debug"
11+
PM_CL="/MD /Zc:preprocessor"
12+
ASAN PM_CL="/MD /Zc:preprocessor -fsanitize=address /Zi" PM_LINK="/debug"
13+
PM_CL="/MDd /Zc:preprocessor"
14+
ASAN PM_CL="/MDd /Zc:preprocessor -fsanitize=address /Zi" PM_LINK="/debug"
15+
PM_CL="/MT /Zc:preprocessor"
16+
ASAN PM_CL="/MT /Zc:preprocessor -fsanitize=address /Zi" PM_LINK="/debug"
17+
PM_CL="/MTd /Zc:preprocessor"
18+
ASAN PM_CL="/MTd /Zc:preprocessor -fsanitize=address /Zi" PM_LINK="/debug"
19+
PM_CL="/MDd /analyze:only /analyze:autolog- /Zc:preprocessor"
20+
ASAN PM_CL="/MDd /analyze:only /analyze:autolog- /Zc:preprocessor -fsanitize=address /Zi" PM_LINK="/debug"
21+
PM_CL="/MDd /GR- /D_HAS_STATIC_RTTI=0 /Zc:preprocessor"
22+
ASAN PM_CL="/MDd /GR- /D_HAS_STATIC_RTTI=0 /Zc:preprocessor -fsanitize=address /Zi" PM_LINK="/debug"
23+
PM_CL="/MDd /utf-8 /Zc:preprocessor"
24+
ASAN PM_CL="/MDd /utf-8 /Zc:preprocessor -fsanitize=address /Zi" PM_LINK="/debug"
25+
PM_COMPILER="clang-cl" PM_CL="-fprebuilt-module-path=. -Wno-unqualified-std-cast-call /MD"
26+
PM_COMPILER="clang-cl" PM_CL="-fprebuilt-module-path=. -Wno-unqualified-std-cast-call /MTd"
27+
PM_COMPILER="clang-cl" PM_CL="-fprebuilt-module-path=. -Wno-unqualified-std-cast-call /MT"

0 commit comments

Comments
 (0)