Skip to content

Commit 984c7ab

Browse files
committed
C++: test for declarations in if statement
1 parent 4513fd1 commit 984c7ab

File tree

3 files changed

+101
-1
lines changed

3 files changed

+101
-1
lines changed

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16425,6 +16425,54 @@ ir.cpp:
1642516425
# 2149| Type = [NestedStruct] iterator
1642616426
# 2149| ValueCategory = lvalue
1642716427
# 2152| getStmt(3): [ReturnStmt] return ...
16428+
# 2154| [TopLevelFunction] void IfDestructors2(bool)
16429+
# 2154| <params>:
16430+
# 2154| getParameter(0): [Parameter] b
16431+
# 2154| Type = [BoolType] bool
16432+
# 2154| getEntryPoint(): [BlockStmt] { ... }
16433+
# 2155| getStmt(0): [IfStmt] if (...) ...
16434+
# 2155| getInitialization(): [DeclStmt] declaration
16435+
# 2155| getDeclarationEntry(0): [VariableDeclarationEntry] definition of s
16436+
# 2155| Type = [Struct] String
16437+
# 2155| getVariable().getInitializer(): [Initializer] initializer for s
16438+
# 2155| getExpr(): [ConstructorCall] call to String
16439+
# 2155| Type = [VoidType] void
16440+
# 2155| ValueCategory = prvalue
16441+
# 2155| getArgument(0): hello
16442+
# 2155| Type = [ArrayType] const char[6]
16443+
# 2155| Value = [StringLiteral] "hello"
16444+
# 2155| ValueCategory = lvalue
16445+
# 2155| getArgument(0).getFullyConverted(): [ArrayToPointerConversion] array to pointer conversion
16446+
# 2155| Type = [PointerType] const char *
16447+
# 2155| ValueCategory = prvalue
16448+
# 2155| getCondition(): [VariableAccess] b
16449+
# 2155| Type = [BoolType] bool
16450+
# 2155| ValueCategory = prvalue(load)
16451+
# 2155| getThen(): [BlockStmt] { ... }
16452+
# 2156| getStmt(0): [DeclStmt] declaration
16453+
# 2156| getDeclarationEntry(0): [VariableDeclarationEntry] definition of x
16454+
# 2156| Type = [IntType] int
16455+
# 2156| getVariable().getInitializer(): [Initializer] initializer for x
16456+
# 2156| getExpr(): [Literal] 0
16457+
# 2156| Type = [IntType] int
16458+
# 2156| Value = [Literal] 0
16459+
# 2156| ValueCategory = prvalue
16460+
# 2157| getElse(): [BlockStmt] { ... }
16461+
# 2158| getStmt(0): [DeclStmt] declaration
16462+
# 2158| getDeclarationEntry(0): [VariableDeclarationEntry] definition of y
16463+
# 2158| Type = [IntType] int
16464+
# 2158| getVariable().getInitializer(): [Initializer] initializer for y
16465+
# 2158| getExpr(): [Literal] 0
16466+
# 2158| Type = [IntType] int
16467+
# 2158| Value = [Literal] 0
16468+
# 2158| ValueCategory = prvalue
16469+
# 2159| getImplicitDestructorCall(0): [DestructorCall] call to ~String
16470+
# 2159| Type = [VoidType] void
16471+
# 2159| ValueCategory = prvalue
16472+
# 2159| getQualifier(): [VariableAccess] s
16473+
# 2159| Type = [Struct] String
16474+
# 2159| ValueCategory = lvalue
16475+
# 2160| getStmt(1): [ReturnStmt] return ...
1642816476
perf-regression.cpp:
1642916477
# 4| [CopyAssignmentOperator] Big& Big::operator=(Big const&)
1643016478
# 4| <params>:

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2151,6 +2151,12 @@ void ForDestructors() {
21512151
}
21522152
}
21532153

2154-
2154+
void IfDestructors2(bool b) {
2155+
if(String s = String("hello"); b) {
2156+
int x = 0;
2157+
} else {
2158+
int y = 0;
2159+
}
2160+
}
21552161

21562162
// semmle-extractor-options: -std=c++17 --clang

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12184,6 +12184,52 @@ ir.cpp:
1218412184
# 2143| v2143_5(void) = AliasedUse : ~m?
1218512185
# 2143| v2143_6(void) = ExitFunction :
1218612186

12187+
# 2154| void IfDestructors2(bool)
12188+
# 2154| Block 0
12189+
# 2154| v2154_1(void) = EnterFunction :
12190+
# 2154| mu2154_2(unknown) = AliasedDefinition :
12191+
# 2154| mu2154_3(unknown) = InitializeNonLocal :
12192+
# 2154| r2154_4(glval<bool>) = VariableAddress[b] :
12193+
# 2154| mu2154_5(bool) = InitializeParameter[b] : &:r2154_4
12194+
# 2155| r2155_1(glval<String>) = VariableAddress[s] :
12195+
# 2155| mu2155_2(String) = Uninitialized[s] : &:r2155_1
12196+
# 2155| r2155_3(glval<unknown>) = FunctionAddress[String] :
12197+
# 2155| r2155_4(glval<char[6]>) = StringConstant["hello"] :
12198+
# 2155| r2155_5(char *) = Convert : r2155_4
12199+
# 2155| v2155_6(void) = Call[String] : func:r2155_3, this:r2155_1, 0:r2155_5
12200+
# 2155| mu2155_7(unknown) = ^CallSideEffect : ~m?
12201+
# 2155| v2155_8(void) = ^BufferReadSideEffect[0] : &:r2155_5, ~m?
12202+
# 2155| mu2155_9(String) = ^IndirectMayWriteSideEffect[-1] : &:r2155_1
12203+
# 2155| r2155_10(glval<bool>) = VariableAddress[b] :
12204+
# 2155| r2155_11(bool) = Load[b] : &:r2155_10, ~m?
12205+
# 2155| v2155_12(void) = ConditionalBranch : r2155_11
12206+
#-----| False -> Block 2
12207+
#-----| True -> Block 1
12208+
12209+
# 2156| Block 1
12210+
# 2156| r2156_1(glval<int>) = VariableAddress[x] :
12211+
# 2156| r2156_2(int) = Constant[0] :
12212+
# 2156| mu2156_3(int) = Store[x] : &:r2156_1, r2156_2
12213+
#-----| Goto -> Block 3
12214+
12215+
# 2158| Block 2
12216+
# 2158| r2158_1(glval<int>) = VariableAddress[y] :
12217+
# 2158| r2158_2(int) = Constant[0] :
12218+
# 2158| mu2158_3(int) = Store[y] : &:r2158_1, r2158_2
12219+
#-----| Goto -> Block 3
12220+
12221+
# 2159| Block 3
12222+
# 2159| r2159_1(glval<String>) = VariableAddress[s] :
12223+
# 2159| r2159_2(glval<unknown>) = FunctionAddress[~String] :
12224+
# 2159| v2159_3(void) = Call[~String] : func:r2159_2, this:r2159_1
12225+
# 2159| mu2159_4(unknown) = ^CallSideEffect : ~m?
12226+
# 2159| v2159_5(void) = ^IndirectReadSideEffect[-1] : &:r2159_1, ~m?
12227+
# 2159| mu2159_6(String) = ^IndirectMayWriteSideEffect[-1] : &:r2159_1
12228+
# 2160| v2160_1(void) = NoOp :
12229+
# 2154| v2154_6(void) = ReturnVoid :
12230+
# 2154| v2154_7(void) = AliasedUse : ~m?
12231+
# 2154| v2154_8(void) = ExitFunction :
12232+
1218712233
perf-regression.cpp:
1218812234
# 6| void Big::Big()
1218912235
# 6| Block 0

0 commit comments

Comments
 (0)