From ef159724aa539fe1bcb1967ec9db51e7660e7993 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Mon, 26 Aug 2024 14:53:25 -0700 Subject: [PATCH 1/3] Add workarounds to product code. --- stl/inc/format | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/stl/inc/format b/stl/inc/format index e5ac72dcc0a..a53b3164b8d 100644 --- a/stl/inc/format +++ b/stl/inc/format @@ -2632,16 +2632,16 @@ template _NODISCARD constexpr string_view _Get_integral_prefix(const char _Type, const _Integral _Value) noexcept { switch (_Type) { case 'b': - return "0b"sv; + return string_view{"0b", 2}; // TRANSITION, VSO-1775715 (should use UDLs in this function) case 'B': - return "0B"sv; + return string_view{"0B", 2}; case 'x': - return "0x"sv; + return string_view{"0x", 2}; case 'X': - return "0X"sv; + return string_view{"0X", 2}; case 'o': if (_Value != _Integral{0}) { - return "0"sv; + return string_view{"0", 1}; } return {}; default: From 74d3759ee23518c3af9e358ecd5ee43c2f0e348e Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Mon, 26 Aug 2024 14:54:45 -0700 Subject: [PATCH 2/3] Extract modules_20_matrix.lst. --- .../P2465R3_standard_library_modules/env.lst | 18 +---------------- tests/std/tests/modules_20_matrix.lst | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 17 deletions(-) create mode 100644 tests/std/tests/modules_20_matrix.lst diff --git a/tests/std/tests/P2465R3_standard_library_modules/env.lst b/tests/std/tests/P2465R3_standard_library_modules/env.lst index e4566f5a9b4..b940ef942d9 100644 --- a/tests/std/tests/P2465R3_standard_library_modules/env.lst +++ b/tests/std/tests/P2465R3_standard_library_modules/env.lst @@ -1,20 +1,4 @@ # Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -RUNALL_INCLUDE ..\..\..\universal_prefix.lst -RUNALL_CROSSLIST -* PM_CL="/w14365 /D_ENFORCE_FACET_SPECIALIZATIONS=1 /D_STL_CALL_ABORT_INSTEAD_OF_INVALID_PARAMETER /Zc:preprocessor" -RUNALL_CROSSLIST -* PM_CL="/w14640 /Zc:threadSafeInit- /EHsc /DTEST_STANDARD=20 /std:c++20" -* PM_CL="/w14640 /Zc:threadSafeInit- /EHsc /DTEST_STANDARD=23 /std:c++latest" -RUNALL_CROSSLIST -* PM_CL="/MD" -* PM_CL="/MDd" -* PM_CL="/MT" -* PM_CL="/MTd" -* PM_CL="/MDd /analyze:only /analyze:autolog-" -* PM_CL="/MDd /GR- /D_HAS_STATIC_RTTI=0" -* PM_CL="/MDd /utf-8" -RUNALL_CROSSLIST -PM_CL="" -ASAN PM_CL="-fsanitize=address /Zi" PM_LINK="/debug" +RUNALL_INCLUDE ..\modules_20_matrix.lst diff --git a/tests/std/tests/modules_20_matrix.lst b/tests/std/tests/modules_20_matrix.lst new file mode 100644 index 00000000000..22a3a5ea9d4 --- /dev/null +++ b/tests/std/tests/modules_20_matrix.lst @@ -0,0 +1,20 @@ +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +RUNALL_INCLUDE ..\..\universal_prefix.lst +RUNALL_CROSSLIST +* PM_CL="/w14365 /D_ENFORCE_FACET_SPECIALIZATIONS=1 /D_STL_CALL_ABORT_INSTEAD_OF_INVALID_PARAMETER /Zc:preprocessor" +RUNALL_CROSSLIST +* PM_CL="/w14640 /Zc:threadSafeInit- /EHsc /DTEST_STANDARD=20 /std:c++20" +* PM_CL="/w14640 /Zc:threadSafeInit- /EHsc /DTEST_STANDARD=23 /std:c++latest" +RUNALL_CROSSLIST +* PM_CL="/MD" +* PM_CL="/MDd" +* PM_CL="/MT" +* PM_CL="/MTd" +* PM_CL="/MDd /analyze:only /analyze:autolog-" +* PM_CL="/MDd /GR- /D_HAS_STATIC_RTTI=0" +* PM_CL="/MDd /utf-8" +RUNALL_CROSSLIST +PM_CL="" +ASAN PM_CL="-fsanitize=address /Zi" PM_LINK="/debug" From e897c454e21270d48dddf046e8e16d210492c12a Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Mon, 26 Aug 2024 14:55:11 -0700 Subject: [PATCH 3/3] Add VSO_1775715_user_defined_modules. Verified that without the product code workaround, this fails with: D:\GitHub\STL\out\x64\out\inc\format(2635): error C3688: invalid literal suffix 'sv'; literal operator or literal operator template 'operator ""sv' not found D:\GitHub\STL\out\x64\out\inc\format(2637): error C3688: invalid literal suffix 'sv'; literal operator or literal operator template 'operator ""sv' not found D:\GitHub\STL\out\x64\out\inc\format(2639): error C3688: invalid literal suffix 'sv'; literal operator or literal operator template 'operator ""sv' not found D:\GitHub\STL\out\x64\out\inc\format(2641): error C3688: invalid literal suffix 'sv'; literal operator or literal operator template 'operator ""sv' not found D:\GitHub\STL\out\x64\out\inc\format(2644): error C3688: invalid literal suffix 'sv'; literal operator or literal operator template 'operator ""sv' not found Perl also tested positively and negatively. --- tests/std/test.lst | 1 + .../__init__.py | 2 ++ .../custom_format.py | 29 +++++++++++++++++++ .../custombuild.pl | 18 ++++++++++++ .../VSO_1775715_user_defined_modules/env.lst | 4 +++ .../lit.local.cfg | 9 ++++++ .../VSO_1775715_user_defined_modules/test.cpp | 12 ++++++++ .../VSO_1775715_user_defined_modules/user.ixx | 26 +++++++++++++++++ 8 files changed, 101 insertions(+) create mode 100644 tests/std/tests/VSO_1775715_user_defined_modules/__init__.py create mode 100644 tests/std/tests/VSO_1775715_user_defined_modules/custom_format.py create mode 100644 tests/std/tests/VSO_1775715_user_defined_modules/custombuild.pl create mode 100644 tests/std/tests/VSO_1775715_user_defined_modules/env.lst create mode 100644 tests/std/tests/VSO_1775715_user_defined_modules/lit.local.cfg create mode 100644 tests/std/tests/VSO_1775715_user_defined_modules/test.cpp create mode 100644 tests/std/tests/VSO_1775715_user_defined_modules/user.ixx diff --git a/tests/std/test.lst b/tests/std/test.lst index 41ecb21be85..aed83280766 100644 --- a/tests/std/test.lst +++ b/tests/std/test.lst @@ -762,5 +762,6 @@ tests\VSO_0849827_multicontainer_emplace_hint_position tests\VSO_0938757_attribute_order tests\VSO_0961751_hash_range_erase tests\VSO_0971246_legacy_await_headers +tests\VSO_1775715_user_defined_modules tests\VSO_1804139_static_analysis_warning_with_single_element_array tests\VSO_1925201_iter_traits diff --git a/tests/std/tests/VSO_1775715_user_defined_modules/__init__.py b/tests/std/tests/VSO_1775715_user_defined_modules/__init__.py new file mode 100644 index 00000000000..2ac2a854cb0 --- /dev/null +++ b/tests/std/tests/VSO_1775715_user_defined_modules/__init__.py @@ -0,0 +1,2 @@ +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception diff --git a/tests/std/tests/VSO_1775715_user_defined_modules/custom_format.py b/tests/std/tests/VSO_1775715_user_defined_modules/custom_format.py new file mode 100644 index 00000000000..4432e6ba306 --- /dev/null +++ b/tests/std/tests/VSO_1775715_user_defined_modules/custom_format.py @@ -0,0 +1,29 @@ +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +import os + +from stl.test.format import STLTestFormat, TestStep +from stl.test.tests import TestType + + +class CustomTestFormat(STLTestFormat): + def getBuildSteps(self, test, litConfig, shared): + _, outputBase = test.getTempPaths() + + testCpp = test.getSourcePath() + sourceDir = os.path.dirname(testCpp) + userIxx = os.path.join(sourceDir, 'user.ixx') + + # Dependency order is important here: + inputPaths = [userIxx, testCpp] + + cmd = [test.cxx, *inputPaths, *test.flags, *test.compileFlags] + + if TestType.COMPILE in test.testType: + cmd += ['/c'] + elif TestType.RUN in test.testType: + shared.execFile = f'{outputBase}.exe' + cmd += [f'/Fe{shared.execFile}', '/link', *test.linkFlags] + + yield TestStep(cmd, shared.execDir, shared.env, False) diff --git a/tests/std/tests/VSO_1775715_user_defined_modules/custombuild.pl b/tests/std/tests/VSO_1775715_user_defined_modules/custombuild.pl new file mode 100644 index 00000000000..cd5b08f5d5a --- /dev/null +++ b/tests/std/tests/VSO_1775715_user_defined_modules/custombuild.pl @@ -0,0 +1,18 @@ +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +use strict; +use warnings; + +use Run; + +sub CustomBuildHook() +{ + my $cwd = Run::GetCWDName(); + + # Dependency order is important here: + my @inputPaths = ("user.ixx", "test.cpp"); + + Run::ExecuteCL(join(" ", @inputPaths, "/Fe$cwd.exe")); +} +1 diff --git a/tests/std/tests/VSO_1775715_user_defined_modules/env.lst b/tests/std/tests/VSO_1775715_user_defined_modules/env.lst new file mode 100644 index 00000000000..b940ef942d9 --- /dev/null +++ b/tests/std/tests/VSO_1775715_user_defined_modules/env.lst @@ -0,0 +1,4 @@ +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +RUNALL_INCLUDE ..\modules_20_matrix.lst diff --git a/tests/std/tests/VSO_1775715_user_defined_modules/lit.local.cfg b/tests/std/tests/VSO_1775715_user_defined_modules/lit.local.cfg new file mode 100644 index 00000000000..6648ba774e2 --- /dev/null +++ b/tests/std/tests/VSO_1775715_user_defined_modules/lit.local.cfg @@ -0,0 +1,9 @@ +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +import os +import site +site.addsitedir(os.path.dirname(os.path.dirname(__file__))) +import VSO_1775715_user_defined_modules.custom_format + +config.test_format = VSO_1775715_user_defined_modules.custom_format.CustomTestFormat() diff --git a/tests/std/tests/VSO_1775715_user_defined_modules/test.cpp b/tests/std/tests/VSO_1775715_user_defined_modules/test.cpp new file mode 100644 index 00000000000..599515d10bc --- /dev/null +++ b/tests/std/tests/VSO_1775715_user_defined_modules/test.cpp @@ -0,0 +1,12 @@ +// Copyright (c) Microsoft Corporation. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +// Note: To properly test the fix for VSO-1775715, don't include any headers here. + +import User; + +int main() { + user::prepare_test_environment(); + user::test_vso_1775715(0, "0 0 0b0 0B0 0x0 0X0 0"); + user::test_vso_1775715(77, "77 77 0b1001101 0B1001101 0x4d 0X4D 0115"); +} diff --git a/tests/std/tests/VSO_1775715_user_defined_modules/user.ixx b/tests/std/tests/VSO_1775715_user_defined_modules/user.ixx new file mode 100644 index 00000000000..bfe86c63f97 --- /dev/null +++ b/tests/std/tests/VSO_1775715_user_defined_modules/user.ixx @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +module; + +#include +#include +#include + +#include + +export module User; + +namespace user { + export void prepare_test_environment() { + assert(test_environment_preparer.succeeded()); + } + + // DevCom-10313766 VSO-1775715 "Using std::format in a module + // requires including header in .cpp files using that module" + export template + void test_vso_1775715(const T& value, const char* const expected_str) { + const std::string actual_str = std::format("{0:#} {0:#d} {0:#b} {0:#B} {0:#x} {0:#X} {0:#o}", value); + assert(actual_str == expected_str); + } +} // namespace user