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

source code of compiler-rt/test/asan/TestCases/use-after-scope-goto.cpp