Skip to content

Commit 565f8e8

Browse files
authored
Merge pull request #15594 from jketema/destructors
C++: Add additional IR tests for destructors
2 parents 4e11676 + fb072a5 commit 565f8e8

10 files changed

+21107
-20223
lines changed

cpp/ql/test/library-tests/ir/ir/PrintAST.expected

Lines changed: 6029 additions & 5740 deletions
Large diffs are not rendered by default.

cpp/ql/test/library-tests/ir/ir/aliased_ir.expected

Lines changed: 5390 additions & 5236 deletions
Large diffs are not rendered by default.

cpp/ql/test/library-tests/ir/ir/aliased_ssa_consistency.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ missingOperandType
66
duplicateChiOperand
77
sideEffectWithoutPrimary
88
instructionWithoutSuccessor
9+
| ir.cpp:2138:9:2138:9 | Chi: x | Instruction 'Chi: x' has no successors in function '$@'. | ir.cpp:2136:6:2136:35 | void initialization_with_destructor(bool, char) | void initialization_with_destructor(bool, char) |
910
ambiguousSuccessors
1011
unexplainedLoop
1112
unnecessaryPhiInstruction

cpp/ql/test/library-tests/ir/ir/aliased_ssa_consistency_unsound.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ missingOperandType
66
duplicateChiOperand
77
sideEffectWithoutPrimary
88
instructionWithoutSuccessor
9+
| ir.cpp:2138:9:2138:9 | Chi: x | Instruction 'Chi: x' has no successors in function '$@'. | ir.cpp:2136:6:2136:35 | void initialization_with_destructor(bool, char) | void initialization_with_destructor(bool, char) |
910
ambiguousSuccessors
1011
unexplainedLoop
1112
unnecessaryPhiInstruction

cpp/ql/test/library-tests/ir/ir/ir.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,8 @@ struct vector {
10651065
bool operator!=(iterator right) const;
10661066
};
10671067

1068+
vector(T);
1069+
~vector();
10681070
iterator begin() const;
10691071
iterator end() const;
10701072
};
@@ -2120,4 +2122,36 @@ void call_as_child_of_ConditionDeclExpr() {
21202122
if(HasOperatorBool b = HasOperatorBool()) {}
21212123
}
21222124

2123-
// semmle-extractor-options: -std=c++17 --clang
2125+
class ClassWithDestructor {
2126+
char *x;
2127+
public:
2128+
ClassWithDestructor() { x = new char; }
2129+
~ClassWithDestructor() { delete x; }
2130+
2131+
void set_x(char y) { *x = y; }
2132+
};
2133+
2134+
constexpr bool initialization_with_destructor_bool = true;
2135+
2136+
void initialization_with_destructor(bool b, char c) {
2137+
if (ClassWithDestructor x; b)
2138+
x.set_x('a');
2139+
2140+
if constexpr (ClassWithDestructor x; initialization_with_destructor_bool)
2141+
x.set_x('a');
2142+
2143+
switch(ClassWithDestructor x; c) {
2144+
case 'a':
2145+
x.set_x('a');
2146+
break;
2147+
default:
2148+
x.set_x('b');
2149+
break;
2150+
}
2151+
2152+
ClassWithDestructor x;
2153+
for(vector<ClassWithDestructor> ys(x); ClassWithDestructor y : ys)
2154+
y.set_x('a');
2155+
}
2156+
2157+
// semmle-extractor-options: -std=c++20 --clang

cpp/ql/test/library-tests/ir/ir/operand_locations.expected

Lines changed: 4648 additions & 4526 deletions
Large diffs are not rendered by default.

cpp/ql/test/library-tests/ir/ir/raw_consistency.expected

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ missingOperandType
66
duplicateChiOperand
77
sideEffectWithoutPrimary
88
instructionWithoutSuccessor
9+
| ir.cpp:2138:9:2138:9 | IndirectMayWriteSideEffect: x | Instruction 'IndirectMayWriteSideEffect: x' has no successors in function '$@'. | ir.cpp:2136:6:2136:35 | void initialization_with_destructor(bool, char) | void initialization_with_destructor(bool, char) |
10+
| ir.cpp:2140:39:2140:39 | IndirectMayWriteSideEffect: call to ClassWithDestructor | Instruction 'IndirectMayWriteSideEffect: call to ClassWithDestructor' has no successors in function '$@'. | ir.cpp:2136:6:2136:35 | void initialization_with_destructor(bool, char) | void initialization_with_destructor(bool, char) |
11+
| ir.cpp:2140:42:2140:76 | Constant: initialization_with_destructor_bool | Instruction 'Constant: initialization_with_destructor_bool' has no successors in function '$@'. | ir.cpp:2136:6:2136:35 | void initialization_with_destructor(bool, char) | void initialization_with_destructor(bool, char) |
12+
| ir.cpp:2141:9:2141:9 | IndirectMayWriteSideEffect: x | Instruction 'IndirectMayWriteSideEffect: x' has no successors in function '$@'. | ir.cpp:2136:6:2136:35 | void initialization_with_destructor(bool, char) | void initialization_with_destructor(bool, char) |
913
ambiguousSuccessors
1014
unexplainedLoop
1115
unnecessaryPhiInstruction
@@ -20,7 +24,7 @@ multipleIRTypes
2024
lostReachability
2125
backEdgeCountMismatch
2226
useNotDominatedByDefinition
23-
| ir.cpp:1486:8:1486:8 | Unary | Operand 'Unary' is not dominated by its definition in function '$@'. | ir.cpp:1486:8:1486:8 | void StructuredBindingDataMemberStruct::StructuredBindingDataMemberStruct() | void StructuredBindingDataMemberStruct::StructuredBindingDataMemberStruct() |
27+
| ir.cpp:1488:8:1488:8 | Unary | Operand 'Unary' is not dominated by its definition in function '$@'. | ir.cpp:1488:8:1488:8 | void StructuredBindingDataMemberStruct::StructuredBindingDataMemberStruct() | void StructuredBindingDataMemberStruct::StructuredBindingDataMemberStruct() |
2428
| try_except.c:13:13:13:13 | Left | Operand 'Left' is not dominated by its definition in function '$@'. | try_except.c:6:6:6:6 | void f() | void f() |
2529
| try_except.c:13:13:13:13 | Left | Operand 'Left' is not dominated by its definition in function '$@'. | try_except.c:6:6:6:6 | void f() | void f() |
2630
| try_except.c:39:15:39:15 | Left | Operand 'Left' is not dominated by its definition in function '$@'. | try_except.c:32:6:32:6 | void h(int) | void h(int) |
@@ -37,4 +41,5 @@ nonUniqueEnclosingIRFunction
3741
fieldAddressOnNonPointer
3842
thisArgumentIsNonPointer
3943
nonUniqueIRVariable
44+
| ir.cpp:2153:68:2153:69 | VariableAddress: ys | Variable address instruction 'VariableAddress: ys' has no associated variable, in function '$@'. | ir.cpp:2136:6:2136:35 | void initialization_with_destructor(bool, char) | void initialization_with_destructor(bool, char) |
4045
missingCppType

0 commit comments

Comments
 (0)