blob: 351cbe995efb2070846203b6d1ee34882ae1f00c [file] [log] [blame]
Vitaly Bukad6eee8172016-10-27 21:02:32 +00001// RUN: %clangxx_asan -O0 -fsanitize-address-use-after-scope %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(0);
27 case 2:
28 ptr = &tmp;
29 *ptr = 5;
30 exit(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(0);
44 }
45 l2:
46 goto l1;
47}
48
49void use(int *x) {
50 static int c = 10;
51 if (--c == 0)
52 exit(0);
53 (*x)++;
54}
55
56void f4() {
57 {
58 int x;
59 l2:
60 use(&x);
61 goto l1;
62 }
63 l1:
64 goto l2;
65}
66
67int main() {
68 f1(1);
69 f2(1);
70 f3(1);
71 f4();
72 return 0;
73}