[SystemZ] Use the same PatFrag for all "insert imm" fragments (NFC) (#119962)
[llvm-project.git] / libcxx / test / std / strings / basic.string / string.modifiers / string_swap / swap.asan.pass.cpp
bloba3466e76a5f5fee2ba85b9a740bc8b4574712485
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // <string>
11 // This test validates that ASan annotations are correctly updated after swaps.
12 // This test meticulously interchanges objects that store data both within their internal memory (Short
13 // String Optimization) and in external buffers (non-SSO).
15 #include <string>
16 #include <cassert>
18 #include "test_macros.h"
19 #include "asan_testing.h"
21 template <class CharT>
22 void test(const CharT val) {
23 using S = std::basic_string<CharT>;
25 S empty_s;
26 S short_s(3, val);
27 S long_s(1100, val);
29 std::swap(empty_s, empty_s);
30 std::swap(short_s, short_s);
31 std::swap(long_s, long_s);
32 LIBCPP_ASSERT(is_string_asan_correct(empty_s));
33 LIBCPP_ASSERT(is_string_asan_correct(short_s));
34 LIBCPP_ASSERT(is_string_asan_correct(long_s));
36 std::swap(empty_s, short_s);
37 LIBCPP_ASSERT(is_string_asan_correct(empty_s));
38 LIBCPP_ASSERT(is_string_asan_correct(short_s));
40 std::swap(empty_s, short_s);
41 LIBCPP_ASSERT(is_string_asan_correct(empty_s));
42 LIBCPP_ASSERT(is_string_asan_correct(short_s));
44 std::swap(empty_s, long_s);
45 LIBCPP_ASSERT(is_string_asan_correct(empty_s));
46 LIBCPP_ASSERT(is_string_asan_correct(long_s));
48 std::swap(empty_s, long_s);
49 LIBCPP_ASSERT(is_string_asan_correct(empty_s));
50 LIBCPP_ASSERT(is_string_asan_correct(long_s));
52 std::swap(short_s, long_s);
53 LIBCPP_ASSERT(is_string_asan_correct(short_s));
54 LIBCPP_ASSERT(is_string_asan_correct(long_s));
56 std::swap(short_s, long_s);
57 LIBCPP_ASSERT(is_string_asan_correct(short_s));
58 LIBCPP_ASSERT(is_string_asan_correct(long_s));
60 S long_s2(11100, val);
62 std::swap(long_s, long_s2);
63 LIBCPP_ASSERT(is_string_asan_correct(long_s));
64 LIBCPP_ASSERT(is_string_asan_correct(long_s2));
66 std::swap(long_s, long_s2);
67 LIBCPP_ASSERT(is_string_asan_correct(long_s));
68 LIBCPP_ASSERT(is_string_asan_correct(long_s2));
70 S long_s3(111, val);
72 std::swap(long_s, long_s3);
73 LIBCPP_ASSERT(is_string_asan_correct(long_s));
74 LIBCPP_ASSERT(is_string_asan_correct(long_s2));
77 int main(int, char**) {
78 test<char>('x');
79 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
80 test<wchar_t>(L'x');
81 #endif
82 #if TEST_STD_VER >= 11
83 test<char16_t>(u'x');
84 test<char32_t>(U'x');
85 #endif
86 #if TEST_STD_VER >= 20
87 test<char8_t>(u8'x');
88 #endif
90 return 0;