Skip to content

Commit bbabf1d

Browse files
committed
C++: add test for constructors in C++17 decl-in-if
1 parent 2d010f6 commit bbabf1d

File tree

3 files changed

+154
-0
lines changed

3 files changed

+154
-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
@@ -16539,6 +16539,72 @@ ir.cpp:
1653916539
# 2174| Type = [Class] Bool
1654016540
# 2174| ValueCategory = lvalue
1654116541
# 2175| getStmt(1): [ReturnStmt] return ...
16542+
# 2178| [CopyAssignmentOperator] Bool2& Bool2::operator=(Bool2 const&)
16543+
# 2178| <params>:
16544+
#-----| getParameter(0): [Parameter] (unnamed parameter 0)
16545+
#-----| Type = [LValueReferenceType] const Bool2 &
16546+
# 2178| [CopyConstructor] void Bool2::Bool2(Bool2 const&)
16547+
# 2178| <params>:
16548+
#-----| getParameter(0): [Parameter] (unnamed parameter 0)
16549+
#-----| Type = [LValueReferenceType] const Bool2 &
16550+
# 2180| [Constructor] void Bool2::Bool2(bool)
16551+
# 2180| <params>:
16552+
# 2180| getParameter(0): [Parameter] b_
16553+
# 2180| Type = [BoolType] bool
16554+
# 2181| [ConversionOperator] bool Bool2::operator bool()
16555+
# 2181| <params>:
16556+
# 2182| [Destructor] void Bool2::~Bool2()
16557+
# 2182| <params>:
16558+
# 2185| [TopLevelFunction] void IfInitiaiizationConstructor(bool)
16559+
# 2185| <params>:
16560+
# 2185| getParameter(0): [Parameter] b
16561+
# 2185| Type = [BoolType] bool
16562+
# 2185| getEntryPoint(): [BlockStmt] { ... }
16563+
# 2186| getStmt(0): [IfStmt] if (...) ...
16564+
# 2186| getCondition(): [ConditionDeclExpr] (condition decl)
16565+
# 2186| Type = [BoolType] bool
16566+
# 2186| ValueCategory = prvalue
16567+
# 2186| getChild(0): [FunctionCall] call to operator bool
16568+
# 2186| Type = [BoolType] bool
16569+
# 2186| ValueCategory = prvalue
16570+
# 2186| getQualifier(): [VariableAccess] B
16571+
# 2186| Type = [Class] Bool2
16572+
# 2186| ValueCategory = prvalue(load)
16573+
# 2186| getThen(): [BlockStmt] { ... }
16574+
# 2187| getStmt(0): [DeclStmt] declaration
16575+
# 2187| getDeclarationEntry(0): [VariableDeclarationEntry] definition of s1
16576+
# 2187| Type = [Struct] String
16577+
# 2187| getVariable().getInitializer(): [Initializer] initializer for s1
16578+
# 2187| getExpr(): [ConstructorCall] call to String
16579+
# 2187| Type = [VoidType] void
16580+
# 2187| ValueCategory = prvalue
16581+
# 2188| getImplicitDestructorCall(0): [DestructorCall] call to ~String
16582+
# 2188| Type = [VoidType] void
16583+
# 2188| ValueCategory = prvalue
16584+
# 2188| getQualifier(): [VariableAccess] s1
16585+
# 2188| Type = [Struct] String
16586+
# 2188| ValueCategory = lvalue
16587+
# 2188| getElse(): [BlockStmt] { ... }
16588+
# 2189| getStmt(0): [DeclStmt] declaration
16589+
# 2189| getDeclarationEntry(0): [VariableDeclarationEntry] definition of s2
16590+
# 2189| Type = [Struct] String
16591+
# 2189| getVariable().getInitializer(): [Initializer] initializer for s2
16592+
# 2189| getExpr(): [ConstructorCall] call to String
16593+
# 2189| Type = [VoidType] void
16594+
# 2189| ValueCategory = prvalue
16595+
# 2190| getImplicitDestructorCall(0): [DestructorCall] call to ~String
16596+
# 2190| Type = [VoidType] void
16597+
# 2190| ValueCategory = prvalue
16598+
# 2190| getQualifier(): [VariableAccess] s2
16599+
# 2190| Type = [Struct] String
16600+
# 2190| ValueCategory = lvalue
16601+
# 2190| getImplicitDestructorCall(0): [DestructorCall] call to ~Bool2
16602+
# 2190| Type = [VoidType] void
16603+
# 2190| ValueCategory = prvalue
16604+
# 2190| getQualifier(): [VariableAccess] B
16605+
# 2190| Type = [Class] Bool2
16606+
# 2190| ValueCategory = lvalue
16607+
# 2191| getStmt(1): [ReturnStmt] return ...
1654216608
perf-regression.cpp:
1654316609
# 4| [CopyAssignmentOperator] Big& Big::operator=(Big const&)
1654416610
# 4| <params>:

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2174,4 +2174,20 @@ void IfDestructors3(bool b) {
21742174
}
21752175
}
21762176

2177+
2178+
class Bool2 {
2179+
public:
2180+
Bool2(bool b_);
2181+
operator bool();
2182+
~Bool2();
2183+
};
2184+
2185+
void IfInitiaiizationConstructor(bool b) {
2186+
if(Bool2 B = Bool2(b)) {
2187+
String s1;
2188+
} else {
2189+
String s2;
2190+
}
2191+
}
2192+
21772193
// 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
@@ -12302,6 +12302,78 @@ ir.cpp:
1230212302
# 2169| v2169_7(void) = AliasedUse : ~m?
1230312303
# 2169| v2169_8(void) = ExitFunction :
1230412304

12305+
# 2185| void IfInitiaiizationConstructor(bool)
12306+
# 2185| Block 0
12307+
# 2185| v2185_1(void) = EnterFunction :
12308+
# 2185| mu2185_2(unknown) = AliasedDefinition :
12309+
# 2185| mu2185_3(unknown) = InitializeNonLocal :
12310+
# 2185| r2185_4(glval<bool>) = VariableAddress[b] :
12311+
# 2185| mu2185_5(bool) = InitializeParameter[b] : &:r2185_4
12312+
# 2186| r2186_1(glval<Bool2>) = VariableAddress[B] :
12313+
# 2186| mu2186_2(Bool2) = Uninitialized[B] : &:r2186_1
12314+
# 2186| r2186_3(glval<unknown>) = FunctionAddress[Bool2] :
12315+
# 2186| r2186_4(glval<bool>) = VariableAddress[b] :
12316+
# 2186| r2186_5(bool) = Load[b] : &:r2186_4, ~m?
12317+
# 2186| v2186_6(void) = Call[Bool2] : func:r2186_3, this:r2186_1, 0:r2186_5
12318+
# 2186| mu2186_7(unknown) = ^CallSideEffect : ~m?
12319+
# 2186| mu2186_8(Bool2) = ^IndirectMayWriteSideEffect[-1] : &:r2186_1
12320+
12321+
# 2186| (no string representation)
12322+
# 2186| CopyValue: (condition decl)
12323+
# 2186| ConditionalBranch: (condition decl)
12324+
#-----| False -> Block 3
12325+
#-----| True -> Block 2
12326+
12327+
# 2186| Block 1
12328+
# 2186| r2186_9(glval<Bool2>) = VariableAddress[B] :
12329+
# 2186| r2186_10(glval<unknown>) = FunctionAddress[operator bool] :
12330+
# 2186| r2186_11(bool) = Call[operator bool] : func:r2186_10, this:r2186_9
12331+
# 2186| mu2186_12(unknown) = ^CallSideEffect : ~m?
12332+
# 2186| v2186_13(void) = ^IndirectReadSideEffect[-1] : &:r2186_9, ~m?
12333+
# 2186| mu2186_14(Bool2) = ^IndirectMayWriteSideEffect[-1] : &:r2186_9
12334+
12335+
# 2187| Block 2
12336+
# 2187| r2187_1(glval<String>) = VariableAddress[s1] :
12337+
# 2187| mu2187_2(String) = Uninitialized[s1] : &:r2187_1
12338+
# 2187| r2187_3(glval<unknown>) = FunctionAddress[String] :
12339+
# 2187| v2187_4(void) = Call[String] : func:r2187_3, this:r2187_1
12340+
# 2187| mu2187_5(unknown) = ^CallSideEffect : ~m?
12341+
# 2187| mu2187_6(String) = ^IndirectMayWriteSideEffect[-1] : &:r2187_1
12342+
# 2188| r2188_1(glval<String>) = VariableAddress[s1] :
12343+
# 2188| r2188_2(glval<unknown>) = FunctionAddress[~String] :
12344+
# 2188| v2188_3(void) = Call[~String] : func:r2188_2, this:r2188_1
12345+
# 2188| mu2188_4(unknown) = ^CallSideEffect : ~m?
12346+
# 2188| v2188_5(void) = ^IndirectReadSideEffect[-1] : &:r2188_1, ~m?
12347+
# 2188| mu2188_6(String) = ^IndirectMayWriteSideEffect[-1] : &:r2188_1
12348+
#-----| Goto -> Block 4
12349+
12350+
# 2189| Block 3
12351+
# 2189| r2189_1(glval<String>) = VariableAddress[s2] :
12352+
# 2189| mu2189_2(String) = Uninitialized[s2] : &:r2189_1
12353+
# 2189| r2189_3(glval<unknown>) = FunctionAddress[String] :
12354+
# 2189| v2189_4(void) = Call[String] : func:r2189_3, this:r2189_1
12355+
# 2189| mu2189_5(unknown) = ^CallSideEffect : ~m?
12356+
# 2189| mu2189_6(String) = ^IndirectMayWriteSideEffect[-1] : &:r2189_1
12357+
# 2190| r2190_1(glval<String>) = VariableAddress[s2] :
12358+
# 2190| r2190_2(glval<unknown>) = FunctionAddress[~String] :
12359+
# 2190| v2190_3(void) = Call[~String] : func:r2190_2, this:r2190_1
12360+
# 2190| mu2190_4(unknown) = ^CallSideEffect : ~m?
12361+
# 2190| v2190_5(void) = ^IndirectReadSideEffect[-1] : &:r2190_1, ~m?
12362+
# 2190| mu2190_6(String) = ^IndirectMayWriteSideEffect[-1] : &:r2190_1
12363+
#-----| Goto -> Block 4
12364+
12365+
# 2190| Block 4
12366+
# 2190| r2190_7(glval<Bool2>) = VariableAddress[B] :
12367+
# 2190| r2190_8(glval<unknown>) = FunctionAddress[~Bool2] :
12368+
# 2190| v2190_9(void) = Call[~Bool2] : func:r2190_8, this:r2190_7
12369+
# 2190| mu2190_10(unknown) = ^CallSideEffect : ~m?
12370+
# 2190| v2190_11(void) = ^IndirectReadSideEffect[-1] : &:r2190_7, ~m?
12371+
# 2190| mu2190_12(Bool2) = ^IndirectMayWriteSideEffect[-1] : &:r2190_7
12372+
# 2191| v2191_1(void) = NoOp :
12373+
# 2185| v2185_6(void) = ReturnVoid :
12374+
# 2185| v2185_7(void) = AliasedUse : ~m?
12375+
# 2185| v2185_8(void) = ExitFunction :
12376+
1230512377
perf-regression.cpp:
1230612378
# 6| void Big::Big()
1230712379
# 6| Block 0

0 commit comments

Comments
 (0)