Skip to content

Commit 2d010f6

Browse files
committed
C++: Test for destructors in declaration as if condition
1 parent 984c7ab commit 2d010f6

File tree

3 files changed

+153
-0
lines changed

3 files changed

+153
-0
lines changed

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

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16473,6 +16473,72 @@ ir.cpp:
1647316473
# 2159| Type = [Struct] String
1647416474
# 2159| ValueCategory = lvalue
1647516475
# 2160| getStmt(1): [ReturnStmt] return ...
16476+
# 2162| [CopyAssignmentOperator] Bool& Bool::operator=(Bool const&)
16477+
# 2162| <params>:
16478+
#-----| getParameter(0): [Parameter] (unnamed parameter 0)
16479+
#-----| Type = [LValueReferenceType] const Bool &
16480+
# 2162| [CopyConstructor] void Bool::Bool(Bool const&)
16481+
# 2162| <params>:
16482+
#-----| getParameter(0): [Parameter] (unnamed parameter 0)
16483+
#-----| Type = [LValueReferenceType] const Bool &
16484+
# 2164| [Constructor] void Bool::Bool(bool)
16485+
# 2164| <params>:
16486+
# 2164| getParameter(0): [Parameter] b_
16487+
# 2164| Type = [BoolType] bool
16488+
# 2165| [ConversionOperator] bool Bool::operator bool()
16489+
# 2165| <params>:
16490+
# 2166| [Destructor] void Bool::~Bool()
16491+
# 2166| <params>:
16492+
# 2169| [TopLevelFunction] void IfDestructors3(bool)
16493+
# 2169| <params>:
16494+
# 2169| getParameter(0): [Parameter] b
16495+
# 2169| Type = [BoolType] bool
16496+
# 2169| getEntryPoint(): [BlockStmt] { ... }
16497+
# 2170| getStmt(0): [IfStmt] if (...) ...
16498+
# 2170| getCondition(): [ConditionDeclExpr] (condition decl)
16499+
# 2170| Type = [BoolType] bool
16500+
# 2170| ValueCategory = prvalue
16501+
# 2170| getChild(0): [FunctionCall] call to operator bool
16502+
# 2170| Type = [BoolType] bool
16503+
# 2170| ValueCategory = prvalue
16504+
# 2170| getQualifier(): [VariableAccess] B
16505+
# 2170| Type = [Class] Bool
16506+
# 2170| ValueCategory = prvalue(load)
16507+
# 2170| getThen(): [BlockStmt] { ... }
16508+
# 2171| getStmt(0): [DeclStmt] declaration
16509+
# 2171| getDeclarationEntry(0): [VariableDeclarationEntry] definition of s1
16510+
# 2171| Type = [Struct] String
16511+
# 2171| getVariable().getInitializer(): [Initializer] initializer for s1
16512+
# 2171| getExpr(): [ConstructorCall] call to String
16513+
# 2171| Type = [VoidType] void
16514+
# 2171| ValueCategory = prvalue
16515+
# 2172| getImplicitDestructorCall(0): [DestructorCall] call to ~String
16516+
# 2172| Type = [VoidType] void
16517+
# 2172| ValueCategory = prvalue
16518+
# 2172| getQualifier(): [VariableAccess] s1
16519+
# 2172| Type = [Struct] String
16520+
# 2172| ValueCategory = lvalue
16521+
# 2172| getElse(): [BlockStmt] { ... }
16522+
# 2173| getStmt(0): [DeclStmt] declaration
16523+
# 2173| getDeclarationEntry(0): [VariableDeclarationEntry] definition of s2
16524+
# 2173| Type = [Struct] String
16525+
# 2173| getVariable().getInitializer(): [Initializer] initializer for s2
16526+
# 2173| getExpr(): [ConstructorCall] call to String
16527+
# 2173| Type = [VoidType] void
16528+
# 2173| ValueCategory = prvalue
16529+
# 2174| getImplicitDestructorCall(0): [DestructorCall] call to ~String
16530+
# 2174| Type = [VoidType] void
16531+
# 2174| ValueCategory = prvalue
16532+
# 2174| getQualifier(): [VariableAccess] s2
16533+
# 2174| Type = [Struct] String
16534+
# 2174| ValueCategory = lvalue
16535+
# 2174| getImplicitDestructorCall(0): [DestructorCall] call to ~Bool
16536+
# 2174| Type = [VoidType] void
16537+
# 2174| ValueCategory = prvalue
16538+
# 2174| getQualifier(): [VariableAccess] B
16539+
# 2174| Type = [Class] Bool
16540+
# 2174| ValueCategory = lvalue
16541+
# 2175| getStmt(1): [ReturnStmt] return ...
1647616542
perf-regression.cpp:
1647716543
# 4| [CopyAssignmentOperator] Big& Big::operator=(Big const&)
1647816544
# 4| <params>:

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2159,4 +2159,19 @@ void IfDestructors2(bool b) {
21592159
}
21602160
}
21612161

2162+
class Bool {
2163+
public:
2164+
Bool(bool b_);
2165+
operator bool();
2166+
~Bool();
2167+
};
2168+
2169+
void IfDestructors3(bool b) {
2170+
if(Bool B = Bool(b)) {
2171+
String s1;
2172+
} else {
2173+
String s2;
2174+
}
2175+
}
2176+
21622177
// semmle-extractor-options: -std=c++17 --clang

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

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12230,6 +12230,78 @@ ir.cpp:
1223012230
# 2154| v2154_7(void) = AliasedUse : ~m?
1223112231
# 2154| v2154_8(void) = ExitFunction :
1223212232

12233+
# 2169| void IfDestructors3(bool)
12234+
# 2169| Block 0
12235+
# 2169| v2169_1(void) = EnterFunction :
12236+
# 2169| mu2169_2(unknown) = AliasedDefinition :
12237+
# 2169| mu2169_3(unknown) = InitializeNonLocal :
12238+
# 2169| r2169_4(glval<bool>) = VariableAddress[b] :
12239+
# 2169| mu2169_5(bool) = InitializeParameter[b] : &:r2169_4
12240+
# 2170| r2170_1(glval<Bool>) = VariableAddress[B] :
12241+
# 2170| mu2170_2(Bool) = Uninitialized[B] : &:r2170_1
12242+
# 2170| r2170_3(glval<unknown>) = FunctionAddress[Bool] :
12243+
# 2170| r2170_4(glval<bool>) = VariableAddress[b] :
12244+
# 2170| r2170_5(bool) = Load[b] : &:r2170_4, ~m?
12245+
# 2170| v2170_6(void) = Call[Bool] : func:r2170_3, this:r2170_1, 0:r2170_5
12246+
# 2170| mu2170_7(unknown) = ^CallSideEffect : ~m?
12247+
# 2170| mu2170_8(Bool) = ^IndirectMayWriteSideEffect[-1] : &:r2170_1
12248+
12249+
# 2170| (no string representation)
12250+
# 2170| CopyValue: (condition decl)
12251+
# 2170| ConditionalBranch: (condition decl)
12252+
#-----| False -> Block 3
12253+
#-----| True -> Block 2
12254+
12255+
# 2170| Block 1
12256+
# 2170| r2170_9(glval<Bool>) = VariableAddress[B] :
12257+
# 2170| r2170_10(glval<unknown>) = FunctionAddress[operator bool] :
12258+
# 2170| r2170_11(bool) = Call[operator bool] : func:r2170_10, this:r2170_9
12259+
# 2170| mu2170_12(unknown) = ^CallSideEffect : ~m?
12260+
# 2170| v2170_13(void) = ^IndirectReadSideEffect[-1] : &:r2170_9, ~m?
12261+
# 2170| mu2170_14(Bool) = ^IndirectMayWriteSideEffect[-1] : &:r2170_9
12262+
12263+
# 2171| Block 2
12264+
# 2171| r2171_1(glval<String>) = VariableAddress[s1] :
12265+
# 2171| mu2171_2(String) = Uninitialized[s1] : &:r2171_1
12266+
# 2171| r2171_3(glval<unknown>) = FunctionAddress[String] :
12267+
# 2171| v2171_4(void) = Call[String] : func:r2171_3, this:r2171_1
12268+
# 2171| mu2171_5(unknown) = ^CallSideEffect : ~m?
12269+
# 2171| mu2171_6(String) = ^IndirectMayWriteSideEffect[-1] : &:r2171_1
12270+
# 2172| r2172_1(glval<String>) = VariableAddress[s1] :
12271+
# 2172| r2172_2(glval<unknown>) = FunctionAddress[~String] :
12272+
# 2172| v2172_3(void) = Call[~String] : func:r2172_2, this:r2172_1
12273+
# 2172| mu2172_4(unknown) = ^CallSideEffect : ~m?
12274+
# 2172| v2172_5(void) = ^IndirectReadSideEffect[-1] : &:r2172_1, ~m?
12275+
# 2172| mu2172_6(String) = ^IndirectMayWriteSideEffect[-1] : &:r2172_1
12276+
#-----| Goto -> Block 4
12277+
12278+
# 2173| Block 3
12279+
# 2173| r2173_1(glval<String>) = VariableAddress[s2] :
12280+
# 2173| mu2173_2(String) = Uninitialized[s2] : &:r2173_1
12281+
# 2173| r2173_3(glval<unknown>) = FunctionAddress[String] :
12282+
# 2173| v2173_4(void) = Call[String] : func:r2173_3, this:r2173_1
12283+
# 2173| mu2173_5(unknown) = ^CallSideEffect : ~m?
12284+
# 2173| mu2173_6(String) = ^IndirectMayWriteSideEffect[-1] : &:r2173_1
12285+
# 2174| r2174_1(glval<String>) = VariableAddress[s2] :
12286+
# 2174| r2174_2(glval<unknown>) = FunctionAddress[~String] :
12287+
# 2174| v2174_3(void) = Call[~String] : func:r2174_2, this:r2174_1
12288+
# 2174| mu2174_4(unknown) = ^CallSideEffect : ~m?
12289+
# 2174| v2174_5(void) = ^IndirectReadSideEffect[-1] : &:r2174_1, ~m?
12290+
# 2174| mu2174_6(String) = ^IndirectMayWriteSideEffect[-1] : &:r2174_1
12291+
#-----| Goto -> Block 4
12292+
12293+
# 2174| Block 4
12294+
# 2174| r2174_7(glval<Bool>) = VariableAddress[B] :
12295+
# 2174| r2174_8(glval<unknown>) = FunctionAddress[~Bool] :
12296+
# 2174| v2174_9(void) = Call[~Bool] : func:r2174_8, this:r2174_7
12297+
# 2174| mu2174_10(unknown) = ^CallSideEffect : ~m?
12298+
# 2174| v2174_11(void) = ^IndirectReadSideEffect[-1] : &:r2174_7, ~m?
12299+
# 2174| mu2174_12(Bool) = ^IndirectMayWriteSideEffect[-1] : &:r2174_7
12300+
# 2175| v2175_1(void) = NoOp :
12301+
# 2169| v2169_6(void) = ReturnVoid :
12302+
# 2169| v2169_7(void) = AliasedUse : ~m?
12303+
# 2169| v2169_8(void) = ExitFunction :
12304+
1223312305
perf-regression.cpp:
1223412306
# 6| void Big::Big()
1223512307
# 6| Block 0

0 commit comments

Comments
 (0)