-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathif.c
138 lines (121 loc) · 2.37 KB
/
if.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// This uses spec select
int fif(int a) {
if (a == 1)
a = 0;
if (a == 2) {
a = 1;
}
return a;
}
int felse(int a, int b) {
if (b == 2) {
a = 0;
} else {
a = 1;
}
if (b == 2) {
a = 0;
} else
a = 1;
if (b == 2)
a = 0;
else {
a = 1;
}
if (b == 2)
a = 0;
else
a = 1;
return a;
}
// Test dangling else
int felse_dangling(int a, int b) {
if (a == 2)
if (b == 1)
b = 0;
else b = 1;
else
b = 3;
return b;
}
// test chained if/else
int fif_chained(int a, int b) {
if (a == 1) {
b = 0;
} else if (b == 2) {
b = 5;
} else {
b = 6;
}
return b;
}
// returning from chain without end return used to exhibit a bug where
// the block was left unterminated
int fif_chainedreturn(int a, int b) {
if (a == 1) {
return 0;
} else if (b == 2) {
return 5;
} else {
return 6;
}
}
// test nested if/else
int fif_nested(int a, int b) {
if (a == 1) {
if (b == 2) {
b = 5;
} else {
b = 6;
}
} else {
if (b == 5) {
b = 8;
} else {
b = 7;
}
}
return b;
}
// Test that allocas for parameters and local variables are not done locally to
// a block (there used to be a bug where the alloca was done inside the "if"
// block and then tried to use from the "then" block, which llvm would fail to
// compile because "instruction does not dominate all uses").
int fif_param(int a, int b) {
if (a == 0) {
b = 1;
} else {
b = 2;
}
return b;
}
int fif_local(int a) {
int b;
if (a == 1) {
b = 1;
} else {
b = 2;
}
return b;
}
int fif_return(int a) {
int b;
if (a == 1) {
return 1;
} else {
return 2;
}
return b;
}
// Test that the initialization expression of variables remains in the disjoint
// block even if the alloca is bubbled up to the common code
int fif_bbinit(int a, int b) {
if (a == 1) {
int c = a * b;
b = c;
} else {
int c = a + b;
b = c;
}
return b;
}