1 // This is the ASAN test of the same name ported to HWAsan. 2 3 // RUN: %clangxx_hwasan -mllvm -hwasan-use-after-scope -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 9 // REQUIRES: stable-runtime 10 11 #include <stdlib.h> 12 13 int *ptr; 14 f1(int cond)15void f1(int cond) { 16 if (cond) 17 goto label; 18 int tmp; 19 20 label: 21 ptr = &tmp; 22 *ptr = 5; 23 } 24 f2(int cond)25void 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); 36 } 37 } 38 } 39 f3(int cond)40void f3(int cond) { 41 { 42 int tmp; 43 goto l2; 44 l1: 45 ptr = &tmp; 46 *ptr = 5; 47 48 exit(0); 49 } 50 l2: 51 goto l1; 52 } 53 use(int * x)54void use(int *x) { 55 static int c = 10; 56 if (--c == 0) 57 exit(0); 58 (*x)++; 59 } 60 f4()61void f4() { 62 { 63 int x; 64 l2: 65 use(&x); 66 goto l1; 67 } 68 l1: 69 goto l2; 70 } 71 main()72int main() { 73 f1(1); 74 f2(1); 75 f3(1); 76 f4(); 77 return 0; 78 } 79