Skip to content

Commit 9b23635

Browse files
committed
C++: Add test case that shows that no destructors are attached to unwinds
1 parent 5cde3fa commit 9b23635

File tree

4 files changed

+152
-0
lines changed

4 files changed

+152
-0
lines changed

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22605,6 +22605,41 @@ ir.cpp:
2260522605
# 2530| ValueCategory = lvalue
2260622606
# 2530| getStmt(1): [LabelStmt] label ...:
2260722607
# 2531| getStmt(2): [ReturnStmt] return ...
22608+
# 2533| [TopLevelFunction] void destructor_possibly_not_handled()
22609+
# 2533| <params>:
22610+
# 2533| getEntryPoint(): [BlockStmt] { ... }
22611+
# 2534| getStmt(0): [DeclStmt] declaration
22612+
# 2534| getDeclarationEntry(0): [VariableDeclarationEntry] definition of x
22613+
# 2534| Type = [Class] ClassWithDestructor
22614+
# 2534| getVariable().getInitializer(): [Initializer] initializer for x
22615+
# 2534| getExpr(): [ConstructorCall] call to ClassWithDestructor
22616+
# 2534| Type = [VoidType] void
22617+
# 2534| ValueCategory = prvalue
22618+
# 2535| getStmt(1): [TryStmt] try { ... }
22619+
# 2535| getStmt(): [BlockStmt] { ... }
22620+
# 2536| getStmt(0): [ExprStmt] ExprStmt
22621+
# 2536| getExpr(): [ThrowExpr] throw ...
22622+
# 2536| Type = [IntType] int
22623+
# 2536| ValueCategory = prvalue
22624+
# 2536| getExpr(): [Literal] 42
22625+
# 2536| Type = [IntType] int
22626+
# 2536| Value = [Literal] 42
22627+
# 2536| ValueCategory = prvalue
22628+
# 2538| getChild(1): [Handler] <handler>
22629+
# 2538| getBlock(): [CatchBlock] { ... }
22630+
# 2540| getImplicitDestructorCall(0): [DestructorCall] call to ~ClassWithDestructor
22631+
# 2540| Type = [VoidType] void
22632+
# 2540| ValueCategory = prvalue
22633+
# 2540| getQualifier(): [VariableAccess] x
22634+
# 2540| Type = [Class] ClassWithDestructor
22635+
# 2540| ValueCategory = lvalue
22636+
# 2540| getStmt(2): [ReturnStmt] return ...
22637+
# 2540| getImplicitDestructorCall(0): [DestructorCall] call to ~ClassWithDestructor
22638+
# 2540| Type = [VoidType] void
22639+
# 2540| ValueCategory = prvalue
22640+
# 2540| getQualifier(): [VariableAccess] x
22641+
# 2540| Type = [Class] ClassWithDestructor
22642+
# 2540| ValueCategory = lvalue
2260822643
perf-regression.cpp:
2260922644
# 4| [CopyAssignmentOperator] Big& Big::operator=(Big const&)
2261022645
# 4| <params>:

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

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18177,6 +18177,64 @@ ir.cpp:
1817718177
# 2521| v2521_8(void) = AliasedUse : ~m2530_17
1817818178
# 2521| v2521_9(void) = ExitFunction :
1817918179

18180+
# 2533| void destructor_possibly_not_handled()
18181+
# 2533| Block 0
18182+
# 2533| v2533_1(void) = EnterFunction :
18183+
# 2533| m2533_2(unknown) = AliasedDefinition :
18184+
# 2533| m2533_3(unknown) = InitializeNonLocal :
18185+
# 2533| m2533_4(unknown) = Chi : total:m2533_2, partial:m2533_3
18186+
# 2534| r2534_1(glval<ClassWithDestructor>) = VariableAddress[x] :
18187+
# 2534| m2534_2(ClassWithDestructor) = Uninitialized[x] : &:r2534_1
18188+
# 2534| r2534_3(glval<unknown>) = FunctionAddress[ClassWithDestructor] :
18189+
# 2534| v2534_4(void) = Call[ClassWithDestructor] : func:r2534_3, this:r2534_1
18190+
# 2534| m2534_5(unknown) = ^CallSideEffect : ~m2533_4
18191+
# 2534| m2534_6(unknown) = Chi : total:m2533_4, partial:m2534_5
18192+
# 2534| m2534_7(ClassWithDestructor) = ^IndirectMayWriteSideEffect[-1] : &:r2534_1
18193+
# 2534| m2534_8(ClassWithDestructor) = Chi : total:m2534_2, partial:m2534_7
18194+
# 2536| r2536_1(glval<int>) = VariableAddress[#throw2536:5] :
18195+
# 2536| r2536_2(int) = Constant[42] :
18196+
# 2536| m2536_3(int) = Store[#throw2536:5] : &:r2536_1, r2536_2
18197+
# 2536| v2536_4(void) = ThrowValue : &:r2536_1, m2536_3
18198+
#-----| Exception -> Block 3
18199+
18200+
# 2533| Block 1
18201+
# 2533| m2533_5(unknown) = Phi : from 2:~m2534_6, from 4:~m2540_14
18202+
# 2533| v2533_6(void) = AliasedUse : ~m2533_5
18203+
# 2533| v2533_7(void) = ExitFunction :
18204+
18205+
# 2533| Block 2
18206+
# 2533| v2533_8(void) = Unwind :
18207+
#-----| Goto -> Block 1
18208+
18209+
# 2538| Block 3
18210+
# 2538| v2538_1(void) = CatchByType[char] :
18211+
#-----| Exception -> Block 2
18212+
#-----| Goto -> Block 4
18213+
18214+
# 2538| Block 4
18215+
# 2538| r2538_2(glval<char>) = VariableAddress[(unnamed parameter 0)] :
18216+
# 2538| m2538_3(char) = InitializeParameter[(unnamed parameter 0)] : &:r2538_2
18217+
# 2538| v2538_4(void) = NoOp :
18218+
# 2540| r2540_1(glval<ClassWithDestructor>) = VariableAddress[x] :
18219+
# 2540| r2540_2(glval<unknown>) = FunctionAddress[~ClassWithDestructor] :
18220+
# 2540| v2540_3(void) = Call[~ClassWithDestructor] : func:r2540_2, this:r2540_1
18221+
# 2540| m2540_4(unknown) = ^CallSideEffect : ~m2534_6
18222+
# 2540| m2540_5(unknown) = Chi : total:m2534_6, partial:m2540_4
18223+
# 2540| v2540_6(void) = ^IndirectReadSideEffect[-1] : &:r2540_1, m2534_8
18224+
# 2540| m2540_7(ClassWithDestructor) = ^IndirectMayWriteSideEffect[-1] : &:r2540_1
18225+
# 2540| m2540_8(ClassWithDestructor) = Chi : total:m2534_8, partial:m2540_7
18226+
# 2540| v2540_9(void) = NoOp :
18227+
# 2540| r2540_10(glval<ClassWithDestructor>) = VariableAddress[x] :
18228+
# 2540| r2540_11(glval<unknown>) = FunctionAddress[~ClassWithDestructor] :
18229+
# 2540| v2540_12(void) = Call[~ClassWithDestructor] : func:r2540_11, this:r2540_10
18230+
# 2540| m2540_13(unknown) = ^CallSideEffect : ~m2540_5
18231+
# 2540| m2540_14(unknown) = Chi : total:m2540_5, partial:m2540_13
18232+
# 2540| v2540_15(void) = ^IndirectReadSideEffect[-1] : &:r2540_10, m2540_8
18233+
# 2540| m2540_16(ClassWithDestructor) = ^IndirectMayWriteSideEffect[-1] : &:r2540_10
18234+
# 2540| m2540_17(ClassWithDestructor) = Chi : total:m2540_8, partial:m2540_16
18235+
# 2533| v2533_9(void) = ReturnVoid :
18236+
#-----| Goto -> Block 1
18237+
1818018238
perf-regression.cpp:
1818118239
# 6| void Big::Big()
1818218240
# 6| Block 0

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2530,4 +2530,13 @@ void destruction_in_switch_3(int c) {
25302530
}
25312531
}
25322532

2533+
void destructor_possibly_not_handled() {
2534+
ClassWithDestructor x;
2535+
try {
2536+
throw 42;
2537+
}
2538+
catch(char) {
2539+
}
2540+
}
2541+
25332542
// semmle-extractor-options: -std=c++20 --clang

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16553,6 +16553,56 @@ ir.cpp:
1655316553
# 2521| v2521_7(void) = AliasedUse : ~m?
1655416554
# 2521| v2521_8(void) = ExitFunction :
1655516555

16556+
# 2533| void destructor_possibly_not_handled()
16557+
# 2533| Block 0
16558+
# 2533| v2533_1(void) = EnterFunction :
16559+
# 2533| mu2533_2(unknown) = AliasedDefinition :
16560+
# 2533| mu2533_3(unknown) = InitializeNonLocal :
16561+
# 2534| r2534_1(glval<ClassWithDestructor>) = VariableAddress[x] :
16562+
# 2534| mu2534_2(ClassWithDestructor) = Uninitialized[x] : &:r2534_1
16563+
# 2534| r2534_3(glval<unknown>) = FunctionAddress[ClassWithDestructor] :
16564+
# 2534| v2534_4(void) = Call[ClassWithDestructor] : func:r2534_3, this:r2534_1
16565+
# 2534| mu2534_5(unknown) = ^CallSideEffect : ~m?
16566+
# 2534| mu2534_6(ClassWithDestructor) = ^IndirectMayWriteSideEffect[-1] : &:r2534_1
16567+
# 2536| r2536_1(glval<int>) = VariableAddress[#throw2536:5] :
16568+
# 2536| r2536_2(int) = Constant[42] :
16569+
# 2536| mu2536_3(int) = Store[#throw2536:5] : &:r2536_1, r2536_2
16570+
# 2536| v2536_4(void) = ThrowValue : &:r2536_1, ~m?
16571+
#-----| Exception -> Block 3
16572+
16573+
# 2533| Block 1
16574+
# 2533| v2533_4(void) = AliasedUse : ~m?
16575+
# 2533| v2533_5(void) = ExitFunction :
16576+
16577+
# 2533| Block 2
16578+
# 2533| v2533_6(void) = Unwind :
16579+
#-----| Goto -> Block 1
16580+
16581+
# 2538| Block 3
16582+
# 2538| v2538_1(void) = CatchByType[char] :
16583+
#-----| Exception -> Block 2
16584+
#-----| Goto -> Block 4
16585+
16586+
# 2538| Block 4
16587+
# 2538| r2538_2(glval<char>) = VariableAddress[(unnamed parameter 0)] :
16588+
# 2538| mu2538_3(char) = InitializeParameter[(unnamed parameter 0)] : &:r2538_2
16589+
# 2538| v2538_4(void) = NoOp :
16590+
# 2540| r2540_1(glval<ClassWithDestructor>) = VariableAddress[x] :
16591+
# 2540| r2540_2(glval<unknown>) = FunctionAddress[~ClassWithDestructor] :
16592+
# 2540| v2540_3(void) = Call[~ClassWithDestructor] : func:r2540_2, this:r2540_1
16593+
# 2540| mu2540_4(unknown) = ^CallSideEffect : ~m?
16594+
# 2540| v2540_5(void) = ^IndirectReadSideEffect[-1] : &:r2540_1, ~m?
16595+
# 2540| mu2540_6(ClassWithDestructor) = ^IndirectMayWriteSideEffect[-1] : &:r2540_1
16596+
# 2540| v2540_7(void) = NoOp :
16597+
# 2540| r2540_8(glval<ClassWithDestructor>) = VariableAddress[x] :
16598+
# 2540| r2540_9(glval<unknown>) = FunctionAddress[~ClassWithDestructor] :
16599+
# 2540| v2540_10(void) = Call[~ClassWithDestructor] : func:r2540_9, this:r2540_8
16600+
# 2540| mu2540_11(unknown) = ^CallSideEffect : ~m?
16601+
# 2540| v2540_12(void) = ^IndirectReadSideEffect[-1] : &:r2540_8, ~m?
16602+
# 2540| mu2540_13(ClassWithDestructor) = ^IndirectMayWriteSideEffect[-1] : &:r2540_8
16603+
# 2533| v2533_7(void) = ReturnVoid :
16604+
#-----| Goto -> Block 1
16605+
1655616606
perf-regression.cpp:
1655716607
# 6| void Big::Big()
1655816608
# 6| Block 0

0 commit comments

Comments
 (0)