Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / hwasan / TestCases / use-after-scope-types.cpp
blob0d2bec089d2cd81a1c383e147e03d6282a5807a3
1 // This is the ASAN test of the same name ported to HWAsan.
3 // RUN: %clangxx_hwasan -std=c++11 -O0 %s -o %t
4 // RUN: %clangxx_hwasan -fno-exceptions -std=c++11 -O0 %s -o %t-noexcept
6 // RUN: not %run %t 0 2>&1 | FileCheck %s
7 // RUN: not %run %t 1 2>&1 | FileCheck %s
8 // RUN: not %run %t 2 2>&1 | FileCheck %s
9 // RUN: not %run %t 3 2>&1 | FileCheck %s
10 // RUN: not %run %t 4 2>&1 | FileCheck %s
11 // RUN: not %run %t 5 2>&1 | FileCheck %s
12 // RUN: not %run %t 6 2>&1 | FileCheck %s
13 // RUN: not %run %t 7 2>&1 | FileCheck %s
14 // RUN: not %run %t 8 2>&1 | FileCheck %s
15 // RUN: not %run %t 9 2>&1 | FileCheck %s
16 // RUN: not %run %t 10 2>&1 | FileCheck %s
18 // RUN: not %run %t-noexcept 0 2>&1 | FileCheck %s
19 // RUN: not %run %t-noexcept 1 2>&1 | FileCheck %s
20 // RUN: not %run %t-noexcept 2 2>&1 | FileCheck %s
21 // RUN: not %run %t-noexcept 3 2>&1 | FileCheck %s
22 // RUN: not %run %t-noexcept 4 2>&1 | FileCheck %s
23 // RUN: not %run %t-noexcept 5 2>&1 | FileCheck %s
24 // RUN: not %run %t-noexcept 6 2>&1 | FileCheck %s
25 // RUN: not %run %t-noexcept 7 2>&1 | FileCheck %s
26 // RUN: not %run %t-noexcept 8 2>&1 | FileCheck %s
27 // RUN: not %run %t-noexcept 9 2>&1 | FileCheck %s
28 // RUN: not %run %t-noexcept 10 2>&1 | FileCheck %s
30 // REQUIRES: aarch64-target-arch || riscv64-target-arch
32 #include <stdlib.h>
33 #include <string>
34 #include <vector>
36 template <class T>
37 struct Ptr {
38 void Store(T *ptr) { t = ptr; }
40 void Access() { *t = {}; }
42 T *t;
45 template <class T, size_t N>
46 struct Ptr<T[N]> {
47 using Type = T[N];
48 void Store(Type *ptr) { t = *ptr; }
50 void Access() { *t = {}; }
52 T *t;
55 template <class T>
56 __attribute__((noinline)) void test() {
57 Ptr<T> ptr;
59 T x;
60 ptr.Store(&x);
63 ptr.Access();
64 // CHECK: ERROR: HWAddressSanitizer: tag-mismatch
65 // CHECK: #{{[0-9]+}} 0x{{.*}} in {{(void )?test.*\((void)?\) .*}}use-after-scope-types.cpp
66 // CHECK: Cause: stack tag-mismatch
69 int main(int argc, char **argv) {
70 using Tests = void (*)();
71 Tests tests[] = {
72 &test<bool>,
73 &test<char>,
74 &test<int>,
75 &test<double>,
76 &test<float>,
77 &test<void *>,
78 &test<std::vector<std::string>>,
79 &test<int[3]>,
80 &test<int[1000]>,
81 &test<char[3]>,
82 &test<char[1000]>,
85 int n = atoi(argv[1]);
86 if (n == sizeof(tests) / sizeof(tests[0])) {
87 for (auto te : tests)
88 te();
89 } else {
90 tests[n]();
93 return 0;