Skip to content
8 changes: 4 additions & 4 deletions stl/inc/__msvc_sanitizer_annotate_container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,24 +128,24 @@ _STL_DISABLE_CLANG_WARNINGS
#pragma detect_mismatch("annotate_optional", "0")
#endif // ^^^ !defined(_INSERT_OPTIONAL_ANNOTATION) ^^^

extern "C" {
#ifdef _ACTIVATE_STRING_ANNOTATION
#pragma comment(lib, "stl_asan")
__declspec(selectany) extern const bool _Asan_string_should_annotate = true;
#pragma detect_mismatch("annotate_string", "1")
#endif // ^^^ defined(_ACTIVATE_STRING_ANNOTATION) ^^^
#ifdef _ACTIVATE_VECTOR_ANNOTATION
#pragma comment(lib, "stl_asan")
__declspec(selectany) extern const bool _Asan_vector_should_annotate = true;
#pragma detect_mismatch("annotate_vector", "1")
#endif // ^^^ defined(_ACTIVATE_VECTOR_ANNOTATION) ^^^
#ifdef _ACTIVATE_OPTIONAL_ANNOTATION
#pragma comment(lib, "stl_asan")
__declspec(selectany) extern const bool _Asan_optional_should_annotate = true;
#pragma detect_mismatch("annotate_optional", "1")
#endif // ^^^ defined(_ACTIVATE_OPTIONAL_ANNOTATION) ^^^

#undef _ACTIVATE_STRING_ANNOTATION
#undef _ACTIVATE_VECTOR_ANNOTATION
#undef _ACTIVATE_OPTIONAL_ANNOTATION

extern "C" {
#ifdef _INSERT_VECTOR_ANNOTATION
extern const bool _Asan_vector_should_annotate;
#endif
Expand Down
18 changes: 11 additions & 7 deletions stl/src/asan.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

namespace std {
extern "C" {
extern const bool _Asan_string_should_annotate = true;
extern const bool _Asan_vector_should_annotate = true;
extern const bool _Asan_optional_should_annotate = true;
} // extern "C"
} // namespace std
extern "C" {
// TRANSITION, ABI: preserved for compatibility with old headers, which
// added stl_asan.lib to the link line. We use __declspec(selectany) to be
// compatible with the new headers that define these variables as
// __declspec(selectany) in __msvc_sanitizer_annotate_container.hpp.
// The new method is preferred because previously enabling just string
// would also enable vector and optional. See GH-6186 for details.
__declspec(selectany) extern const bool _Asan_string_should_annotate = true;
__declspec(selectany) extern const bool _Asan_vector_should_annotate = true;
__declspec(selectany) extern const bool _Asan_optional_should_annotate = true;
} // extern "C"
1 change: 1 addition & 0 deletions tests/std/test.lst
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ tests\GH_005800_stable_sort_large_alignment
tests\GH_005816_numeric_limits_traps
tests\GH_005968_headers_provide_begin_end
tests\GH_005974_asan_annotate_optional
tests\GH_006186_asan_annotate_partial
tests\LWG2381_num_get_floating_point
tests\LWG2510_tag_classes
tests\LWG2597_complex_branch_cut
Expand Down
40 changes: 40 additions & 0 deletions tests/std/tests/GH_006186_asan_annotate_partial/env.lst
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

# This test matrix is the usual test matrix, with all currently unsupported options removed, crossed with the ASan flags.

# TRANSITION, google/sanitizers#328: clang-cl does not support /MDd or /MTd with ASan
RUNALL_INCLUDE ..\prefix.lst
RUNALL_CROSSLIST
PM_CL="/fsanitize=address /DTEST_ENSURE_VECTOR_ENABLED /DTEST_ENSURE_STRING_ENABLED /DTEST_ENSURE_OPTIONAL_ENABLED"
PM_CL="/fsanitize=address /D_DISABLE_VECTOR_ANNOTATION /DTEST_ENSURE_STRING_ENABLED /DTEST_ENSURE_OPTIONAL_ENABLED"
PM_CL="/fsanitize=address /DTEST_ENSURE_VECTOR_ENABLED /D_DISABLE_STRING_ANNOTATION /DTEST_ENSURE_OPTIONAL_ENABLED"
PM_CL="/fsanitize=address /DTEST_ENSURE_VECTOR_ENABLED /DTEST_ENSURE_STRING_ENABLED /D_DISABLE_OPTIONAL_ANNOTATION"
Comment thread
zacklj89 marked this conversation as resolved.
PM_CL="/D_ANNOTATE_STL"
RUNALL_CROSSLIST
PM_CL="/Zi /wd4611 /w14640 /Zc:threadSafeInit-" PM_LINK="/debug"
RUNALL_CROSSLIST
PM_CL="/BE /c /EHsc /MD /std:c++14"
PM_CL="/BE /c /EHsc /MDd /std:c++17 /permissive-"
PM_CL="/BE /c /EHsc /MT /std:c++20 /permissive-"
PM_CL="/BE /c /EHsc /MTd /std:c++latest /permissive-"
PM_CL="/EHsc /MD /std:c++14"
PM_CL="/EHsc /MD /std:c++17"
PM_CL="/EHsc /MD /std:c++20"
PM_CL="/EHsc /MD /std:c++latest /permissive- /Zc:char8_t- /Zc:preprocessor"
PM_CL="/EHsc /MD /std:c++latest /permissive- /Zc:noexceptTypes-"
PM_CL="/EHsc /MDd /std:c++14 /fp:except /Zc:preprocessor"
PM_CL="/EHsc /MDd /std:c++17 /permissive-"
PM_CL="/EHsc /MDd /std:c++20 /permissive-"
PM_CL="/EHsc /MDd /std:c++latest /permissive- /Zc:wchar_t-"
PM_CL="/EHsc /MDd /std:c++latest /permissive-"
PM_CL="/EHsc /MT /std:c++latest /permissive- /analyze:only /analyze:autolog-"
PM_CL="/EHsc /MT /std:c++latest /permissive-"
PM_CL="/EHsc /MTd /std:c++latest /permissive"
PM_CL="/EHsc /MTd /std:c++latest /permissive- /analyze:only /analyze:autolog-"
PM_CL="/EHsc /MTd /std:c++latest /permissive- /fp:strict"
PM_CL="/EHsc /MTd /std:c++latest /permissive-"
PM_COMPILER="clang-cl" PM_CL="-fno-ms-compatibility -fno-delayed-template-parsing -Wno-unqualified-std-cast-call /EHsc /MD /std:c++14"
PM_COMPILER="clang-cl" PM_CL="-fno-ms-compatibility -fno-delayed-template-parsing -Wno-unqualified-std-cast-call /EHsc /MD /std:c++17"
PM_COMPILER="clang-cl" PM_CL="-fno-ms-compatibility -fno-delayed-template-parsing -Wno-unqualified-std-cast-call /EHsc /MT /std:c++20 /permissive-"
PM_COMPILER="clang-cl" PM_CL="-fno-ms-compatibility -fno-delayed-template-parsing -Wno-unqualified-std-cast-call /EHsc /MT /std:c++latest /permissive- /fp:strict"
40 changes: 40 additions & 0 deletions tests/std/tests/GH_006186_asan_annotate_partial/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

// REQUIRES: x64 || x86 || arm64
Comment thread
amyw-msft marked this conversation as resolved.

#if defined(__clang__) && defined(_M_ARM64) // TRANSITION, LLVM-184902, fixed in Clang 23
#pragma comment(linker, "/INFERASANLIBS")
int main() {}
#else // ^^^ workaround / no workaround vvv

#include <cassert>
#include <vector> // include __msvc_sanitizer_annotate_container.hpp

extern "C" {
extern const bool _Asan_vector_should_annotate;
extern const bool _Asan_string_should_annotate;
extern const bool _Asan_optional_should_annotate;
} // extern "C"

int main() {
#ifdef TEST_ENSURE_VECTOR_ENABLED
assert(_Asan_vector_should_annotate == true);
#else
assert(_Asan_vector_should_annotate == false);
#endif

#ifdef TEST_ENSURE_STRING_ENABLED
assert(_Asan_string_should_annotate == true);
#else
assert(_Asan_string_should_annotate == false);
#endif

#ifdef TEST_ENSURE_OPTIONAL_ENABLED
assert(_Asan_optional_should_annotate == true);
#else
assert(_Asan_optional_should_annotate == false);
#endif
}

#endif // ^^^ no workaround ^^^