Debian Codegraph @

gcc/testsuite/c-c++-common/analyzer/paths-6.c

raw
1 /* { dg-skip-if "requires hosted libstdc++ for stdlib malloc" { ! hostedlib } } */
2
3 #include <stdlib.h>
4 #include "analyzer-decls.h"
5
6 /* Verify that ordering of writes doesn't matter when merging states. */
7
8 /* Test with locals. */
9
10 void test_1 (int flag)
11 {
12 int a, b;
13 if (flag)
14 {
15 a = 3;
16 b = 4;
17 }
18 else
19 {
20 b = 4;
21 a = 3;
22 }
23
24 __analyzer_dump_exploded_nodes (0); /* { dg-warning "1 processed enode" } */
25 __analyzer_eval (a == 3); /* { dg-warning "TRUE" } */
26 __analyzer_eval (b == 4); /* { dg-warning "TRUE" } */
27 }
28
29 /* Test with globals. */
30
31 int f, g, h;
32 void test_2 (int flag)
33 {
34 if (flag)
35 {
36 f = 3;
37 g = 4;
38 }
39 else
40 {
41 g = 4;
42 f = 3;
43 }
44
45 __analyzer_dump_exploded_nodes (0); /* { dg-warning "1 processed enode" } */
46 __analyzer_eval (f == 3); /* { dg-warning "TRUE" } */
47 __analyzer_eval (g == 4); /* { dg-warning "TRUE" } */
48 }
49
50 /* All 6 orderings of writes to 3 globals. */
51
52 void test_3 (int i)
53 {
54 switch (i)
55 {
56 default:
57 case 0:
58 f = 3;
59 g = 4;
60 h = 5;
61 break;
62
63 case 1:
64 f = 3;
65 h = 5;
66 g = 4;
67 break;
68
69 case 2:
70 g = 4;
71 f = 3;
72 h = 5;
73 break;
74
75 case 3:
76 g = 4;
77 h = 5;
78 f = 3;
79 break;
80
81 case 4:
82 h = 5;
83 f = 3;
84 g = 4;
85 break;
86
87 case 5:
88 h = 5;
89 g = 4;
90 f = 3;
91 break;
92 }
93
94 __analyzer_dump_exploded_nodes (0); /* { dg-warning "1 processed enode" } */
95 __analyzer_eval (f == 3); /* { dg-warning "TRUE" } */
96 __analyzer_eval (g == 4); /* { dg-warning "TRUE" } */
97 __analyzer_eval (h == 5); /* { dg-warning "TRUE" } */
98 }
99
100 void test_4 (int flag)
101 {
102 void *p, *q;
103 if (flag)
104 {
105 p = malloc (256);
106 q = malloc (256);
107 }
108 else
109 {
110 q = malloc (256);
111 p = malloc (256);
112 }
113 __analyzer_dump_exploded_nodes (0); /* { dg-warning "2 processed enode" } */
114 free (p);
115 free (q);
116 }