Skip to content

Commit

Permalink
C++: Add some more tests to expose consistency issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
MathiasVP committed Nov 18, 2024
1 parent 493ea6d commit 28391d1
Show file tree
Hide file tree
Showing 10 changed files with 1,884 additions and 0 deletions.
472 changes: 472 additions & 0 deletions cpp/ql/test/library-tests/ir/ir/PrintAST.expected

Large diffs are not rendered by default.

596 changes: 596 additions & 0 deletions cpp/ql/test/library-tests/ir/ir/aliased_ir.expected

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions cpp/ql/test/library-tests/ir/ir/aliased_ssa_consistency.expected
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,41 @@ thisArgumentIsNonPointer
| ir.cpp:2546:34:2546:34 | Call: call to operator bool | Call instruction 'Call: call to operator bool' has a `this` argument operand that is not an address, in function '$@'. | ir.cpp:2545:6:2545:23 | void this_inconsistency(bool) | void this_inconsistency(bool) |
nonUniqueIRVariable
nonBooleanOperand
| ir.c:85:7:85:8 | ConditionalBranch: x1 | Conditional branch instruction ConditionalBranch: x1 with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:86:6:86:8 | ConditionalBranch: ! ... | Conditional branch instruction ConditionalBranch: ! ... with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:86:6:86:8 | LogicalNot: ! ... | Logical Not instruction LogicalNot: ! ... with non-Boolean operand, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:88:11:88:13 | LogicalNot: ! ... | Logical Not instruction LogicalNot: ! ... with non-Boolean operand, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:89:6:89:6 | ConditionalBranch: y | Conditional branch instruction ConditionalBranch: y with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:90:6:90:7 | ConditionalBranch: ! ... | Conditional branch instruction ConditionalBranch: ! ... with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:90:6:90:7 | LogicalNot: ! ... | Logical Not instruction LogicalNot: ! ... with non-Boolean operand, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:92:6:92:7 | ConditionalBranch: x1 | Conditional branch instruction ConditionalBranch: x1 with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:92:12:92:13 | ConditionalBranch: x2 | Conditional branch instruction ConditionalBranch: x2 with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:93:6:93:8 | ConditionalBranch: ! ... | Conditional branch instruction ConditionalBranch: ! ... with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:93:6:93:8 | LogicalNot: ! ... | Logical Not instruction LogicalNot: ! ... with non-Boolean operand, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:93:13:93:14 | ConditionalBranch: x2 | Conditional branch instruction ConditionalBranch: x2 with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:94:6:94:7 | ConditionalBranch: x1 | Conditional branch instruction ConditionalBranch: x1 with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:94:12:94:14 | ConditionalBranch: ! ... | Conditional branch instruction ConditionalBranch: ! ... with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:94:12:94:14 | LogicalNot: ! ... | Logical Not instruction LogicalNot: ! ... with non-Boolean operand, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:95:6:95:8 | ConditionalBranch: ! ... | Conditional branch instruction ConditionalBranch: ! ... with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:95:6:95:8 | LogicalNot: ! ... | Logical Not instruction LogicalNot: ! ... with non-Boolean operand, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:95:13:95:15 | ConditionalBranch: ! ... | Conditional branch instruction ConditionalBranch: ! ... with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:95:13:95:15 | LogicalNot: ! ... | Logical Not instruction LogicalNot: ! ... with non-Boolean operand, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:96:6:96:7 | ConditionalBranch: x1 | Conditional branch instruction ConditionalBranch: x1 with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:96:12:96:13 | ConditionalBranch: x2 | Conditional branch instruction ConditionalBranch: x2 with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:97:6:97:8 | ConditionalBranch: ! ... | Conditional branch instruction ConditionalBranch: ! ... with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:97:6:97:8 | LogicalNot: ! ... | Logical Not instruction LogicalNot: ! ... with non-Boolean operand, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:97:13:97:14 | ConditionalBranch: x2 | Conditional branch instruction ConditionalBranch: x2 with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:98:6:98:7 | ConditionalBranch: x1 | Conditional branch instruction ConditionalBranch: x1 with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:98:12:98:14 | ConditionalBranch: ! ... | Conditional branch instruction ConditionalBranch: ! ... with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:98:12:98:14 | LogicalNot: ! ... | Logical Not instruction LogicalNot: ! ... with non-Boolean operand, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:99:6:99:8 | ConditionalBranch: ! ... | Conditional branch instruction ConditionalBranch: ! ... with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:99:6:99:8 | LogicalNot: ! ... | Logical Not instruction LogicalNot: ! ... with non-Boolean operand, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:99:13:99:15 | ConditionalBranch: ! ... | Conditional branch instruction ConditionalBranch: ! ... with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:99:13:99:15 | LogicalNot: ! ... | Logical Not instruction LogicalNot: ! ... with non-Boolean operand, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:101:19:101:20 | ConditionalBranch: x1 | Conditional branch instruction ConditionalBranch: x1 with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:101:25:101:26 | ConditionalBranch: x2 | Conditional branch instruction ConditionalBranch: x2 with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:102:6:102:14 | ConditionalBranch: x_1_and_2 | Conditional branch instruction ConditionalBranch: x_1_and_2 with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:103:6:103:15 | ConditionalBranch: ! ... | Conditional branch instruction ConditionalBranch: ! ... with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:103:6:103:15 | LogicalNot: ! ... | Logical Not instruction LogicalNot: ! ... with non-Boolean operand, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| try_except.c:35:13:35:13 | ConditionalBranch: b | Conditional branch instruction ConditionalBranch: b with non-Boolean condition, in function '$@'. | try_except.c:32:6:32:6 | void h(int) | void h(int) |
missingCppType
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,41 @@ thisArgumentIsNonPointer
| ir.cpp:2546:34:2546:34 | Call: call to operator bool | Call instruction 'Call: call to operator bool' has a `this` argument operand that is not an address, in function '$@'. | ir.cpp:2545:6:2545:23 | void this_inconsistency(bool) | void this_inconsistency(bool) |
nonUniqueIRVariable
nonBooleanOperand
| ir.c:85:7:85:8 | ConditionalBranch: x1 | Conditional branch instruction ConditionalBranch: x1 with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:86:6:86:8 | ConditionalBranch: ! ... | Conditional branch instruction ConditionalBranch: ! ... with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:86:6:86:8 | LogicalNot: ! ... | Logical Not instruction LogicalNot: ! ... with non-Boolean operand, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:88:11:88:13 | LogicalNot: ! ... | Logical Not instruction LogicalNot: ! ... with non-Boolean operand, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:89:6:89:6 | ConditionalBranch: y | Conditional branch instruction ConditionalBranch: y with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:90:6:90:7 | ConditionalBranch: ! ... | Conditional branch instruction ConditionalBranch: ! ... with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:90:6:90:7 | LogicalNot: ! ... | Logical Not instruction LogicalNot: ! ... with non-Boolean operand, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:92:6:92:7 | ConditionalBranch: x1 | Conditional branch instruction ConditionalBranch: x1 with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:92:12:92:13 | ConditionalBranch: x2 | Conditional branch instruction ConditionalBranch: x2 with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:93:6:93:8 | ConditionalBranch: ! ... | Conditional branch instruction ConditionalBranch: ! ... with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:93:6:93:8 | LogicalNot: ! ... | Logical Not instruction LogicalNot: ! ... with non-Boolean operand, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:93:13:93:14 | ConditionalBranch: x2 | Conditional branch instruction ConditionalBranch: x2 with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:94:6:94:7 | ConditionalBranch: x1 | Conditional branch instruction ConditionalBranch: x1 with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:94:12:94:14 | ConditionalBranch: ! ... | Conditional branch instruction ConditionalBranch: ! ... with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:94:12:94:14 | LogicalNot: ! ... | Logical Not instruction LogicalNot: ! ... with non-Boolean operand, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:95:6:95:8 | ConditionalBranch: ! ... | Conditional branch instruction ConditionalBranch: ! ... with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:95:6:95:8 | LogicalNot: ! ... | Logical Not instruction LogicalNot: ! ... with non-Boolean operand, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:95:13:95:15 | ConditionalBranch: ! ... | Conditional branch instruction ConditionalBranch: ! ... with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:95:13:95:15 | LogicalNot: ! ... | Logical Not instruction LogicalNot: ! ... with non-Boolean operand, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:96:6:96:7 | ConditionalBranch: x1 | Conditional branch instruction ConditionalBranch: x1 with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:96:12:96:13 | ConditionalBranch: x2 | Conditional branch instruction ConditionalBranch: x2 with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:97:6:97:8 | ConditionalBranch: ! ... | Conditional branch instruction ConditionalBranch: ! ... with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:97:6:97:8 | LogicalNot: ! ... | Logical Not instruction LogicalNot: ! ... with non-Boolean operand, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:97:13:97:14 | ConditionalBranch: x2 | Conditional branch instruction ConditionalBranch: x2 with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:98:6:98:7 | ConditionalBranch: x1 | Conditional branch instruction ConditionalBranch: x1 with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:98:12:98:14 | ConditionalBranch: ! ... | Conditional branch instruction ConditionalBranch: ! ... with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:98:12:98:14 | LogicalNot: ! ... | Logical Not instruction LogicalNot: ! ... with non-Boolean operand, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:99:6:99:8 | ConditionalBranch: ! ... | Conditional branch instruction ConditionalBranch: ! ... with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:99:6:99:8 | LogicalNot: ! ... | Logical Not instruction LogicalNot: ! ... with non-Boolean operand, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:99:13:99:15 | ConditionalBranch: ! ... | Conditional branch instruction ConditionalBranch: ! ... with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:99:13:99:15 | LogicalNot: ! ... | Logical Not instruction LogicalNot: ! ... with non-Boolean operand, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:101:19:101:20 | ConditionalBranch: x1 | Conditional branch instruction ConditionalBranch: x1 with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:101:25:101:26 | ConditionalBranch: x2 | Conditional branch instruction ConditionalBranch: x2 with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:102:6:102:14 | ConditionalBranch: x_1_and_2 | Conditional branch instruction ConditionalBranch: x_1_and_2 with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:103:6:103:15 | ConditionalBranch: ! ... | Conditional branch instruction ConditionalBranch: ! ... with non-Boolean condition, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| ir.c:103:6:103:15 | LogicalNot: ! ... | Logical Not instruction LogicalNot: ! ... with non-Boolean operand, in function '$@'. | ir.c:84:6:84:28 | void branch_on_integral_in_c(int, int) | void branch_on_integral_in_c(int, int) |
| try_except.c:35:13:35:13 | ConditionalBranch: b | Conditional branch instruction ConditionalBranch: b with non-Boolean condition, in function '$@'. | try_except.c:32:6:32:6 | void h(int) | void h(int) |
missingCppType
22 changes: 22 additions & 0 deletions cpp/ql/test/library-tests/ir/ir/ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,26 @@ void raise_access_violation() {
ExRaiseAccessViolation(1);
}

void branch_on_integral_in_c(int x1, int x2) {
if (x1) {}
if(!x1) {}

int y = !x1;
if(y) {}
if(!y) {}

if(x1 && x2) {}
if(!x1 && x2) {}
if(x1 && !x2) {}
if(!x1 && !x2) {}
if(x1 || x2) {}
if(!x1 || x2) {}
if(x1 || !x2) {}
if(!x1 || !x2) {}

int x_1_and_2 = x1 && x2;
if(x_1_and_2) {}
if(!x_1_and_2) {}
}

// semmle-extractor-options: --microsoft
22 changes: 22 additions & 0 deletions cpp/ql/test/library-tests/ir/ir/ir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2695,4 +2695,26 @@ int requires_use() {

}

void branch_on_integral_in_cpp(int x1, int x2) {
if (x1) {}
if(!x1) {}

int y = !x1;
if(y) {}
if(!y) {}

if(x1 && x2) {}
if(!x1 && x2) {}
if(x1 && !x2) {}
if(!x1 && !x2) {}
if(x1 || x2) {}
if(!x1 || x2) {}
if(x1 || !x2) {}
if(!x1 || !x2) {}

int x_1_and_2 = x1 && x2;
if(x_1_and_2) {}
if(!x_1_and_2) {}
}

// semmle-extractor-options: -std=c++20 --clang
Loading

0 comments on commit 28391d1

Please sign in to comment.