| 1 | // This is the ASAN test of the same name ported to HWAsan. |
| 2 | |
| 3 | // RUN: %clangxx_hwasan -O0 %s -o %t && %run %t |
| 4 | |
| 5 | // Function jumps over variable initialization making lifetime analysis |
| 6 | // ambiguous. Asan should ignore such variable and program must not fail. |
| 7 | |
| 8 | // REQUIRES: aarch64-target-arch || riscv64-target-arch |
| 9 | |
| 10 | #include <stdlib.h> |
| 11 | |
| 12 | int *ptr; |
| 13 | |
| 14 | void f1(int cond) { |
| 15 | if (cond) |
| 16 | goto label; |
| 17 | int tmp; |
| 18 | |
| 19 | label: |
| 20 | ptr = &tmp; |
| 21 | *ptr = 5; |
| 22 | } |
| 23 | |
| 24 | void f2(int cond) { |
| 25 | switch (cond) { |
| 26 | case 1: { |
| 27 | ++cond; |
| 28 | int tmp; |
| 29 | ptr = &tmp; |
| 30 | exit(status: 0); |
| 31 | case 2: |
| 32 | ptr = &tmp; |
| 33 | *ptr = 5; |
| 34 | exit(status: 0); |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | void f3(int cond) { |
| 40 | { |
| 41 | int tmp; |
| 42 | goto l2; |
| 43 | l1: |
| 44 | ptr = &tmp; |
| 45 | *ptr = 5; |
| 46 | |
| 47 | exit(status: 0); |
| 48 | } |
| 49 | l2: |
| 50 | goto l1; |
| 51 | } |
| 52 | |
| 53 | void use(int *x) { |
| 54 | static int c = 10; |
| 55 | if (--c == 0) |
| 56 | exit(status: 0); |
| 57 | (*x)++; |
| 58 | } |
| 59 | |
| 60 | void f4() { |
| 61 | { |
| 62 | int x; |
| 63 | l2: |
| 64 | use(x: &x); |
| 65 | goto l1; |
| 66 | } |
| 67 | l1: |
| 68 | goto l2; |
| 69 | } |
| 70 | |
| 71 | int main() { |
| 72 | f1(cond: 1); |
| 73 | f2(cond: 1); |
| 74 | f3(cond: 1); |
| 75 | f4(); |
| 76 | return 0; |
| 77 | } |
| 78 | |