Files
codeql/cpp/ql/test/library-tests/qlcfg/switchbody.c
Jonas Jensen 26f32f0d6d C++: Initial version of CFG.qll
This implements calculation of the control-flow graph in QL. The new
code is not enabled yet as we'll need more extractor changes first.

The `SyntheticDestructorCalls.qll` file is a temporary solution that can
be removed when the extractor produces this information directly.
2019-01-04 13:34:36 +01:00

36 lines
953 B
C

// In a standard switch statement, each exit node of the conditional expression
// has an edge to the block statement of the body, and this block statement
// has an edge to each switch case.
int switch_block(int i) {
switch (i < 0 ? -i : i) {
case 0:
return 1;
default:
return i;
}
}
// If the body of a switch is not a compound statement then a block statement
// is synthesized by the extractor.
int switch_single(int i) {
switch (i < 0 ? -i : i)
case 0:
case 1:
return i;
return 2;
}
// If the body of a switch statement is a compound statement OTHER than a block
// then the CFG looks very different. Each exit node of the conditional
// expression has an edge directly to each switch case, and the body of the
// switch is unreachable. Hopefully nobody writes code like this.
int switch_notblock(int i) {
switch (i < 0 ? -i : i)
if (1) {
case 0:
return 1;
default:
return i;
}
}