Skip to content

Commit 7fa8cf5

Browse files
committed
[libc++] Add a utility for checking the output of commands
1 parent 3bf91ad commit 7fa8cf5

File tree

15 files changed

+699
-5
lines changed

15 files changed

+699
-5
lines changed

libcxx/test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ add_custom_target(install-cxx-test-suite-prefix
4242
cxx
4343
cxx_experimental
4444
cxx-modules
45+
check_output
4546
COMMAND ${CMAKE_COMMAND} -E make_directory "${LIBCXX_TESTING_INSTALL_PREFIX}"
4647
COMMAND "${CMAKE_COMMAND}"
4748
-DCMAKE_INSTALL_COMPONENT=cxx-headers

libcxx/test/configs/cmake-bridge.cfg.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ config.substitutions.append(('%{lib-dir}', '@LIBCXX_TESTING_INSTALL_PREFIX@/@LIB
3131
config.substitutions.append(('%{module-dir}', '@LIBCXX_TESTING_INSTALL_PREFIX@/@LIBCXX_INSTALL_MODULES_DIR@'))
3232
config.substitutions.append(('%{test-tools-dir}', '@LIBCXX_TEST_TOOLS_PATH@'))
3333
config.substitutions.append(('%{benchmark_flags}', '-I @LIBCXX_BINARY_DIR@/test/benchmarks/google-benchmark/include -L @LIBCXX_BINARY_DIR@/test/benchmarks/google-benchmark/lib -L @LIBCXX_BINARY_DIR@/test/benchmarks/google-benchmark/lib64 -l benchmark'))
34+
config.substitutions.append(('%{check-output}', os.path.join('@CMAKE_BINARY_DIR@', 'bin/check_output') + " %s"))
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
//===----------------------------------------------------------------------===//
8+
9+
// This test is checking the LLVM IR
10+
// REQUIRES: clang
11+
12+
// RUN: %{cxx} %s %{compile_flags} -O3 -c -S -emit-llvm -o - | %{check-output}
13+
14+
#include <algorithm>
15+
16+
int* test1(int* first, int* last, int* out) {
17+
// CHECK: define dso_local void
18+
// CHECK-SAME: test
19+
// CHECK: tail call void @llvm.memmove
20+
return std::copy(first, last, out);
21+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
//===----------------------------------------------------------------------===//
8+
9+
// REQUIRES: has-clang-tidy
10+
11+
// RUN: %{clang-tidy} %s -header-filter=.* --checks='-*,libcpp-cpp-version-check' --load=%{test-tools}/clang_tidy_checks/libcxx-tidy.plugin -- %{compile_flags} -fno-modules 2>&1 | %{check-output}
12+
13+
#include <__config>
14+
15+
// CHECK: warning: _LIBCPP_STD_VER >= version should be used instead of _LIBCPP_STD_VER > prev_version
16+
#if _LIBCPP_STD_VER > 14
17+
#endif
18+
19+
// CHECK: warning: Use _LIBCPP_STD_VER instead of __cplusplus to constrain based on the C++ version
20+
#if __cplusplus >= 201103L
21+
#endif
22+
23+
// CHECK: warning: _LIBCPP_STD_VER >= 11 is always true. Did you mean '#ifndef _LIBCPP_CXX03_LANG'?
24+
#if _LIBCPP_STD_VER >= 11
25+
#endif
26+
27+
// CHECK: warning: Not a valid value for _LIBCPP_STD_VER. Use 14, 17, 20, 23, or 26
28+
#if _LIBCPP_STD_VER >= 12
29+
#endif
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
//===----------------------------------------------------------------------===//
8+
9+
// This test is checking the LLVM IR
10+
// REQUIRES: clang
11+
12+
// RUN: %{cxx} %s %{compile_flags} -O3 -c -S -emit-llvm -o - | %{check-output}
13+
14+
#include <cstdint>
15+
#include <utility>
16+
17+
bool cmp_equal_i16_i16(int16_t lhs, int16_t rhs) {
18+
// CHECK: define dso_local noundef zeroext
19+
// CHECK-SAME: cmp_equal_i16_i16
20+
// CHECK-NEXT: %3 = icmp eq i16 %0, %1
21+
// CHECK-NEXT: ret i1 %3
22+
// CHECK-NEXT: }
23+
return std::cmp_equal(lhs, rhs);
24+
}
25+
26+
bool cmp_equal_i32_i32(int32_t lhs, int32_t rhs) {
27+
// CHECK: define dso_local noundef zeroext
28+
// CHECK-SAME: cmp_equal_i32_i32
29+
// CHECK-NEXT: %3 = icmp eq i32 %0, %1
30+
// CHECK-NEXT: ret i1 %3
31+
// CHECK-NEXT: }
32+
return std::cmp_equal(lhs, rhs);
33+
}
34+
35+
bool cmp_equal_u32_i32(uint32_t lhs, int32_t rhs) {
36+
// CHECK: define dso_local noundef zeroext
37+
// CHECK-SAME: cmp_equal_u32_i32
38+
// CHECK-NEXT: %3 = icmp sgt i32 %1, -1
39+
// CHECK-NEXT: %4 = icmp eq i32 %0, %1
40+
// CHECK-NEXT: %5 = and i1 %3, %4
41+
// CHECK-NEXT: ret i1 %5
42+
// CHECK-NEXT: }
43+
return std::cmp_equal(lhs, rhs);
44+
}
45+
46+
bool cmp_equal_i32_u64(int32_t lhs, uint64_t rhs) {
47+
// CHECK: define dso_local noundef zeroext
48+
// CHECK-SAME: cmp_equal_i32_u64
49+
// CHECK-NEXT: %3 = icmp sgt i32 %0, -1
50+
// CHECK-NEXT: %4 = zext i32 %0 to i64
51+
// CHECK-NEXT: %5 = icmp eq i64 %4, %1
52+
// CHECK-NEXT: %6 = and i1 %3, %5
53+
// CHECK-NEXT: ret i1 %6
54+
// CHECK-NEXT: }
55+
return std::cmp_equal(lhs, rhs);
56+
}
57+
58+
bool cmp_equal_u32_i64(uint32_t lhs, int64_t rhs) {
59+
// CHECK: define dso_local noundef zeroext
60+
// CHECK-SAME: cmp_equal_u32_i64
61+
// CHECK-NEXT: %3 = icmp sgt i64 %1, -1
62+
// CHECK-NEXT: %4 = zext i32 %0 to i64
63+
// CHECK-NEXT: %5 = icmp eq i64 %4, %1
64+
// CHECK-NEXT: %6 = and i1 %3, %5
65+
// CHECK-NEXT: ret i1 %6
66+
// CHECK-NEXT: }
67+
return std::cmp_equal(lhs, rhs);
68+
}
69+
70+
bool cmp_equal_u32_u64(uint32_t lhs, uint64_t rhs) {
71+
// CHECK: define dso_local noundef zeroext
72+
// CHECK-SAME: cmp_equal_u32_u64
73+
// CHECK-NEXT: %3 = zext i32 %0 to i64
74+
// CHECK-NEXT: %4 = icmp eq i64 %3, %1
75+
// CHECK-NEXT: ret i1 %4
76+
// CHECK-NEXT: }
77+
return std::cmp_equal(lhs, rhs);
78+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
//===----------------------------------------------------------------------===//
8+
9+
// This test is checking the LLVM IR
10+
// REQUIRES: clang
11+
12+
// RUN: %{cxx} %s %{compile_flags} -O3 -c -S -emit-llvm -o - | %{check-output}
13+
14+
#include <cstdint>
15+
#include <utility>
16+
17+
bool cmp_greater_i16_i16(int16_t lhs, int16_t rhs) {
18+
// CHECK: define dso_local noundef zeroext
19+
// CHECK-SAME: cmp_greater_i16_i16
20+
// CHECK-NEXT: %3 = icmp slt i16 %1, %0
21+
// CHECK-NEXT: ret i1 %3
22+
// CHECK-NEXT: }
23+
return std::cmp_greater(lhs, rhs);
24+
}
25+
26+
bool cmp_greater_i32_i32(int32_t lhs, int32_t rhs) {
27+
// CHECK: define dso_local noundef zeroext
28+
// CHECK-SAME: cmp_greater_i32_i32
29+
// CHECK-NEXT: %3 = icmp slt i32 %1, %0
30+
// CHECK-NEXT: ret i1 %3
31+
// CHECK-NEXT: }
32+
return std::cmp_greater(lhs, rhs);
33+
}
34+
35+
bool cmp_greater_u32_i32(uint32_t lhs, int32_t rhs) {
36+
// CHECK: define dso_local noundef zeroext
37+
// CHECK-SAME: cmp_greater_u32_i32
38+
// CHECK-NEXT: %3 = icmp slt i32 %1, 0
39+
// CHECK-NEXT: %4 = icmp ult i32 %1, %0
40+
// CHECK-NEXT: %5 = or i1 %3, %4
41+
// CHECK-NEXT: ret i1 %5
42+
// CHECK-NEXT: }
43+
return std::cmp_greater(lhs, rhs);
44+
}
45+
46+
bool cmp_greater_i32_u64(int32_t lhs, uint64_t rhs) {
47+
// CHECK: define dso_local noundef zeroext
48+
// CHECK-SAME: cmp_greater_i32_u64
49+
// CHECK-NEXT: %3 = icmp sgt i32 %0, -1
50+
// CHECK-NEXT: %4 = zext i32 %0 to i64
51+
// CHECK-NEXT: %5 = icmp ugt i64 %4, %1
52+
// CHECK-NEXT: %6 = and i1 %3, %5
53+
// CHECK-NEXT: ret i1 %6
54+
// CHECK-NEXT: }
55+
return std::cmp_greater(lhs, rhs);
56+
}
57+
58+
bool cmp_greater_u32_i64(uint32_t lhs, int64_t rhs) {
59+
// CHECK: define dso_local noundef zeroext
60+
// CHECK-SAME: cmp_greater_u32_i64
61+
// CHECK-NEXT: %3 = icmp slt i64 %1, 0
62+
// CHECK-NEXT: %4 = zext i32 %0 to i64
63+
// CHECK-NEXT: %5 = icmp ugt i64 %4, %1
64+
// CHECK-NEXT: %6 = or i1 %3, %5
65+
// CHECK-NEXT: ret i1 %6
66+
// CHECK-NEXT: }
67+
return std::cmp_greater(lhs, rhs);
68+
}
69+
70+
bool cmp_greater_u32_u64(uint32_t lhs, uint64_t rhs) {
71+
// CHECK: define dso_local noundef zeroext
72+
// CHECK-SAME: cmp_greater_u32_u64
73+
// CHECK-NEXT: %3 = zext i32 %0 to i64
74+
// CHECK-NEXT: %4 = icmp ugt i64 %3, %1
75+
// CHECK-NEXT: ret i1 %4
76+
// CHECK-NEXT: }
77+
return std::cmp_greater(lhs, rhs);
78+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
//===----------------------------------------------------------------------===//
8+
9+
// This test is checking the LLVM IR
10+
// REQUIRES: clang
11+
12+
// RUN: %{cxx} %s %{compile_flags} -O3 -c -S -emit-llvm -o - | %{check-output}
13+
14+
#include <cstdint>
15+
#include <utility>
16+
17+
bool cmp_greater_equal_i16_i16(int16_t lhs, int16_t rhs) {
18+
// CHECK: define dso_local noundef zeroext
19+
// CHECK-SAME: cmp_greater_equal_i16_i16
20+
// CHECK-NEXT: %3 = icmp sge i16 %0, %1
21+
// CHECK-NEXT: ret i1 %3
22+
// CHECK-NEXT: }
23+
return std::cmp_greater_equal(lhs, rhs);
24+
}
25+
26+
bool cmp_greater_equal_i32_i32(int32_t lhs, int32_t rhs) {
27+
// CHECK: define dso_local noundef zeroext
28+
// CHECK-SAME: cmp_greater_equal_i32_i32
29+
// CHECK-NEXT: %3 = icmp sge i32 %0, %1
30+
// CHECK-NEXT: ret i1 %3
31+
// CHECK-NEXT: }
32+
return std::cmp_greater_equal(lhs, rhs);
33+
}
34+
35+
bool cmp_greater_equal_u32_i32(uint32_t lhs, int32_t rhs) {
36+
// CHECK: define dso_local noundef zeroext
37+
// CHECK-SAME: cmp_greater_equal_u32_i32
38+
// CHECK-NEXT: %3 = icmp slt i32 %1, 0
39+
// CHECK-NEXT: %4 = icmp uge i32 %0, %1
40+
// CHECK-NEXT: %5 = or i1 %3, %4
41+
// CHECK-NEXT: ret i1 %5
42+
// CHECK-NEXT: }
43+
return std::cmp_greater_equal(lhs, rhs);
44+
}
45+
46+
bool cmp_greater_equal_i32_u64(int32_t lhs, uint64_t rhs) {
47+
// CHECK: define dso_local noundef zeroext
48+
// CHECK-SAME: cmp_greater_equal_i32_u64
49+
// CHECK-NEXT: %3 = icmp sgt i32 %0, -1
50+
// CHECK-NEXT: %4 = zext i32 %0 to i64
51+
// CHECK-NEXT: %5 = icmp uge i64 %4, %1
52+
// CHECK-NEXT: %6 = and i1 %3, %5
53+
// CHECK-NEXT: ret i1 %6
54+
// CHECK-NEXT: }
55+
return std::cmp_greater_equal(lhs, rhs);
56+
}
57+
58+
bool cmp_greater_equal_u32_i64(uint32_t lhs, int64_t rhs) {
59+
// CHECK: define dso_local noundef zeroext
60+
// CHECK-SAME: cmp_greater_equal_u32_i64
61+
// CHECK-NEXT: %3 = icmp slt i64 %1, 0
62+
// CHECK-NEXT: %4 = zext i32 %0 to i64
63+
// CHECK-NEXT: %5 = icmp uge i64 %4, %1
64+
// CHECK-NEXT: %6 = or i1 %3, %5
65+
// CHECK-NEXT: ret i1 %6
66+
// CHECK-NEXT: }
67+
return std::cmp_greater_equal(lhs, rhs);
68+
}
69+
70+
bool cmp_greater_equal_u32_u64(uint32_t lhs, uint64_t rhs) {
71+
// CHECK: define dso_local noundef zeroext
72+
// CHECK-SAME: cmp_greater_equal_u32_u64
73+
// CHECK-NEXT: %3 = zext i32 %0 to i64
74+
// CHECK-NEXT: %4 = icmp uge i64 %3, %1
75+
// CHECK-NEXT: ret i1 %4
76+
// CHECK-NEXT: }
77+
return std::cmp_greater_equal(lhs, rhs);
78+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
//===----------------------------------------------------------------------===//
8+
9+
// This test is checking the LLVM IR
10+
// REQUIRES: clang
11+
12+
// RUN: %{cxx} %s %{compile_flags} -O3 -c -S -emit-llvm -o - | %{check-output}
13+
14+
#include <cstdint>
15+
#include <utility>
16+
17+
bool cmp_less_i16_i16(int16_t lhs, int16_t rhs) {
18+
// CHECK: define dso_local noundef zeroext
19+
// CHECK-SAME: cmp_less_i16_i16
20+
// CHECK-NEXT: %3 = icmp slt i16 %0, %1
21+
// CHECK-NEXT: ret i1 %3
22+
// CHECK-NEXT: }
23+
return std::cmp_less(lhs, rhs);
24+
}
25+
26+
bool cmp_less_i32_i32(int32_t lhs, int32_t rhs) {
27+
// CHECK: define dso_local noundef zeroext
28+
// CHECK-SAME: cmp_less_i32_i32
29+
// CHECK-NEXT: %3 = icmp slt i32 %0, %1
30+
// CHECK-NEXT: ret i1 %3
31+
// CHECK-NEXT: }
32+
return std::cmp_less(lhs, rhs);
33+
}
34+
35+
bool cmp_less_u32_i32(uint32_t lhs, int32_t rhs) {
36+
// CHECK: define dso_local noundef zeroext
37+
// CHECK-SAME: cmp_less_u32_i32
38+
// CHECK-NEXT: %3 = icmp sgt i32 %1, -1
39+
// CHECK-NEXT: %4 = icmp ult i32 %0, %1
40+
// CHECK-NEXT: %5 = and i1 %3, %4
41+
// CHECK-NEXT: ret i1 %5
42+
// CHECK-NEXT: }
43+
return std::cmp_less(lhs, rhs);
44+
}
45+
46+
bool cmp_less_i32_u64(int32_t lhs, uint64_t rhs) {
47+
// CHECK: define dso_local noundef zeroext
48+
// CHECK-SAME: cmp_less_i32_u64
49+
// CHECK-NEXT: %3 = icmp slt i32 %0, 0
50+
// CHECK-NEXT: %4 = zext i32 %0 to i64
51+
// CHECK-NEXT: %5 = icmp ult i64 %4, %1
52+
// CHECK-NEXT: %6 = or i1 %3, %5
53+
// CHECK-NEXT: ret i1 %6
54+
// CHECK-NEXT: }
55+
return std::cmp_less(lhs, rhs);
56+
}
57+
58+
bool cmp_less_u32_i64(uint32_t lhs, int64_t rhs) {
59+
// CHECK: define dso_local noundef zeroext
60+
// CHECK-SAME: cmp_less_u32_i64
61+
// CHECK-NEXT: %3 = icmp sgt i64 %1, -1
62+
// CHECK-NEXT: %4 = zext i32 %0 to i64
63+
// CHECK-NEXT: %5 = icmp ult i64 %4, %1
64+
// CHECK-NEXT: %6 = and i1 %3, %5
65+
// CHECK-NEXT: ret i1 %6
66+
// CHECK-NEXT: }
67+
return std::cmp_less(lhs, rhs);
68+
}
69+
70+
bool cmp_less_u32_u64(uint32_t lhs, uint64_t rhs) {
71+
// CHECK: define dso_local noundef zeroext
72+
// CHECK-SAME: cmp_less_u32_u64
73+
// CHECK-NEXT: %3 = zext i32 %0 to i64
74+
// CHECK-NEXT: %4 = icmp ult i64 %3, %1
75+
// CHECK-NEXT: ret i1 %4
76+
// CHECK-NEXT: }
77+
return std::cmp_less(lhs, rhs);
78+
}

0 commit comments

Comments
 (0)