[docs] Fix build-docs.sh
[llvm-project.git] / compiler-rt / test / hwasan / TestCases / use-after-scope-goto.cpp
blob3ea25ba06b9ab56ef107923813755835a6ecaefd
1 // This is the ASAN test of the same name ported to HWAsan.
3 // RUN: %clangxx_hwasan -mllvm -hwasan-use-after-scope -O0 %s -o %t && %run %t
5 // Function jumps over variable initialization making lifetime analysis
6 // ambiguous. Asan should ignore such variable and program must not fail.
8 // REQUIRES: aarch64-target-arch
9 // REQUIRES: stable-runtime
11 #include <stdlib.h>
13 int *ptr;
15 void f1(int cond) {
16 if (cond)
17 goto label;
18 int tmp;
20 label:
21 ptr = &tmp;
22 *ptr = 5;
25 void f2(int cond) {
26 switch (cond) {
27 case 1: {
28 ++cond;
29 int tmp;
30 ptr = &tmp;
31 exit(0);
32 case 2:
33 ptr = &tmp;
34 *ptr = 5;
35 exit(0);
40 void f3(int cond) {
42 int tmp;
43 goto l2;
44 l1:
45 ptr = &tmp;
46 *ptr = 5;
48 exit(0);
50 l2:
51 goto l1;
54 void use(int *x) {
55 static int c = 10;
56 if (--c == 0)
57 exit(0);
58 (*x)++;
61 void f4() {
63 int x;
64 l2:
65 use(&x);
66 goto l1;
68 l1:
69 goto l2;
72 int main() {
73 f1(1);
74 f2(1);
75 f3(1);
76 f4();
77 return 0;