Files
codeql/cpp/ql/test/library-tests/ir/constant_func/constant_func.cpp
Dave Bartolomeo 56bb9dcde0 C++: Remove infeasible edges to reachable blocks
The existing unreachable IR removal code only retargeted an infeasible edge to an `Unreached` instruction if the successor of the edge was an unreachable block. This is too conservative, because it doesn't remove an infeasible edge that targets a block that is still reachable via other paths. The trivial example of this is `do { } while (false);`, where the back edge is infeasible, but the body block is still reachable from the loop entry.

This change retargets all infeasible edges to `Unreached` instructions, regardless of the reachability of the successor block.
2018-12-14 12:13:22 -08:00

71 lines
789 B
C++

int ReturnConstant() {
return 7;
}
int ReturnConstantPhi(bool b) {
if (b) {
return 7;
}
else {
return 7;
}
}
int GetInt();
int ReturnNonConstantPhi(bool b) {
if (b) {
return 7;
}
else {
return GetInt();
}
}
int ReturnConstantPhiLoop(int x) {
int y = 7;
while (x > 0) {
y = 7;
--x;
}
return y;
}
int UnreachableViaGoto() {
goto skip;
return 1;
skip:
return 0;
}
int UnreachableIf(bool b) {
int x = 5;
int y = 10;
if (b) {
if (x == y) {
return 1;
}
else {
return 0;
}
}
else {
if (x < y) {
return 0;
}
else {
return 1;
}
}
}
int DoWhileFalse() {
int i = 0;
do {
i++;
} while (false);
return i;
}