Skip to content
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

Compiler bug workaround for using format() in a user-defined module #4919

Merged
merged 3 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions stl/inc/format
Original file line number Diff line number Diff line change
Expand Up @@ -2632,16 +2632,16 @@ template <integral _Integral>
_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:
Expand Down
1 change: 1 addition & 0 deletions tests/std/test.lst
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 1 addition & 17 deletions tests/std/tests/P2465R3_standard_library_modules/env.lst
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Original file line number Diff line number Diff line change
@@ -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)
18 changes: 18 additions & 0 deletions tests/std/tests/VSO_1775715_user_defined_modules/custombuild.pl
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions tests/std/tests/VSO_1775715_user_defined_modules/env.lst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

RUNALL_INCLUDE ..\modules_20_matrix.lst
Original file line number Diff line number Diff line change
@@ -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()
12 changes: 12 additions & 0 deletions tests/std/tests/VSO_1775715_user_defined_modules/test.cpp
Original file line number Diff line number Diff line change
@@ -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");
}
26 changes: 26 additions & 0 deletions tests/std/tests/VSO_1775715_user_defined_modules/user.ixx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

module;

#include <cassert>
#include <format>
#include <string>

#include <force_include.hpp>

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 <format> header in .cpp files using that module"
export template <class T>
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
20 changes: 20 additions & 0 deletions tests/std/tests/modules_20_matrix.lst
Original file line number Diff line number Diff line change
@@ -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"