Skip to content

Commit 815ae37

Browse files
committed
C++: Add test case with call in initialization
Fix formatting while here.
1 parent 4a42ca8 commit 815ae37

File tree

6 files changed

+165
-30
lines changed

6 files changed

+165
-30
lines changed

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49652,6 +49652,43 @@ try_except.c:
4965249652
# 40| Type = [IntType] int
4965349653
# 40| ValueCategory = prvalue(load)
4965449654
# 42| getStmt(2): [ReturnStmt] return ...
49655+
# 44| [TopLevelFunction] int i()
49656+
# 44| <params>:
49657+
# 46| [TopLevelFunction] void j(int)
49658+
# 46| <params>:
49659+
# 46| getParameter(0): [Parameter] b
49660+
# 46| Type = [IntType] int
49661+
# 46| getEntryPoint(): [BlockStmt] { ... }
49662+
# 47| getStmt(0): [DeclStmt] declaration
49663+
# 47| getDeclarationEntry(0): [VariableDeclarationEntry] definition of x
49664+
# 47| Type = [IntType] int
49665+
# 47| getVariable().getInitializer(): [Initializer] initializer for x
49666+
# 47| getExpr(): [Literal] 0
49667+
# 47| Type = [IntType] int
49668+
# 47| Value = [Literal] 0
49669+
# 47| ValueCategory = prvalue
49670+
# 48| getStmt(1): [MicrosoftTryExceptStmt] __try { ... } __except( ... ) { ... }
49671+
# 48| getStmt(): [BlockStmt] { ... }
49672+
# 49| getStmt(0): [DeclStmt] declaration
49673+
# 49| getDeclarationEntry(0): [VariableDeclarationEntry] definition of y
49674+
# 49| Type = [IntType] int
49675+
# 49| getVariable().getInitializer(): [Initializer] initializer for y
49676+
# 49| getExpr(): [FunctionCall] call to i
49677+
# 49| Type = [IntType] int
49678+
# 49| ValueCategory = prvalue
49679+
# 51| getCondition(): [Literal] 1
49680+
# 51| Type = [IntType] int
49681+
# 51| Value = [Literal] 1
49682+
# 51| ValueCategory = prvalue
49683+
# 51| getExcept(): [BlockStmt] { ... }
49684+
# 52| getStmt(0): [ExprStmt] ExprStmt
49685+
# 52| getExpr(): [FunctionCall] call to sink
49686+
# 52| Type = [VoidType] void
49687+
# 52| ValueCategory = prvalue
49688+
# 52| getArgument(0): [VariableAccess] x
49689+
# 52| Type = [IntType] int
49690+
# 52| ValueCategory = prvalue(load)
49691+
# 54| getStmt(2): [ReturnStmt] return ...
4965549692
try_except.cpp:
4965649693
# 3| [TopLevelFunction] void ProbeFunction()
4965749694
# 3| <params>:

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

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39194,6 +39194,31 @@ try_except.c:
3919439194
# 32| Block 7
3919539195
# 32| v32_10(void) = Unreached :
3919639196

39197+
# 46| void j(int)
39198+
# 46| Block 0
39199+
# 46| v46_1(void) = EnterFunction :
39200+
# 46| m46_2(unknown) = AliasedDefinition :
39201+
# 46| m46_3(unknown) = InitializeNonLocal :
39202+
# 46| m46_4(unknown) = Chi : total:m46_2, partial:m46_3
39203+
# 46| r46_5(glval<int>) = VariableAddress[b] :
39204+
# 46| m46_6(int) = InitializeParameter[b] : &:r46_5
39205+
# 47| r47_1(glval<int>) = VariableAddress[x] :
39206+
# 47| r47_2(int) = Constant[0] :
39207+
# 47| m47_3(int) = Store[x] : &:r47_1, r47_2
39208+
# 49| r49_1(glval<int>) = VariableAddress[y] :
39209+
# 49| r49_2(glval<unknown>) = FunctionAddress[i] :
39210+
# 49| r49_3(int) = Call[i] : func:r49_2
39211+
# 49| m49_4(unknown) = ^CallSideEffect : ~m46_4
39212+
# 49| m49_5(unknown) = Chi : total:m46_4, partial:m49_4
39213+
# 49| m49_6(int) = Store[y] : &:r49_1, r49_3
39214+
# 54| v54_1(void) = NoOp :
39215+
# 46| v46_7(void) = ReturnVoid :
39216+
# 46| v46_8(void) = AliasedUse : ~m49_5
39217+
# 46| v46_9(void) = ExitFunction :
39218+
39219+
# 46| Block 1
39220+
# 46| v46_10(void) = Unreached :
39221+
3919739222
try_except.cpp:
3919839223
# 6| void f_cpp()
3919939224
# 6| Block 0
@@ -39393,10 +39418,10 @@ try_except.cpp:
3939339418
#-----| True -> Block 1
3939439419

3939539420
# 48| Block 1
39396-
# 48| r48_1(glval<int>) = VariableAddress[#throw48:13] :
39397-
# 48| r48_2(int) = Constant[1] :
39398-
# 48| m48_3(int) = Store[#throw48:13] : &:r48_1, r48_2
39399-
# 48| v48_4(void) = ThrowValue : &:r48_1, m48_3
39421+
# 48| r48_1(glval<int>) = VariableAddress[#throw48:7] :
39422+
# 48| r48_2(int) = Constant[1] :
39423+
# 48| m48_3(int) = Store[#throw48:7] : &:r48_1, r48_2
39424+
# 48| v48_4(void) = ThrowValue : &:r48_1, m48_3
3940039425
#-----| C++ Exception -> Block 4
3940139426

3940239427
# 51| Block 2

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ lostReachability
2121
backEdgeCountMismatch
2222
useNotDominatedByDefinition
2323
| ir.cpp:1535:8:1535:8 | Unary | Operand 'Unary' is not dominated by its definition in function '$@'. | ir.cpp:1535:8:1535:8 | void StructuredBindingDataMemberStruct::StructuredBindingDataMemberStruct() | void StructuredBindingDataMemberStruct::StructuredBindingDataMemberStruct() |
24+
| try_except.c:51:13:51:13 | Left | Operand 'Left' is not dominated by its definition in function '$@'. | try_except.c:46:6:46:6 | void j(int) | void j(int) |
25+
| try_except.c:51:13:51:13 | Left | Operand 'Left' is not dominated by its definition in function '$@'. | try_except.c:46:6:46:6 | void j(int) | void j(int) |
2426
switchInstructionWithoutDefaultEdge
2527
notMarkedAsConflated
2628
wronglyMarkedAsConflated

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

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37470,6 +37470,65 @@ try_except.c:
3747037470
# 32| v32_9(void) = ReturnVoid :
3747137471
#-----| Goto -> Block 1
3747237472

37473+
# 46| void j(int)
37474+
# 46| Block 0
37475+
# 46| v46_1(void) = EnterFunction :
37476+
# 46| mu46_2(unknown) = AliasedDefinition :
37477+
# 46| mu46_3(unknown) = InitializeNonLocal :
37478+
# 46| r46_4(glval<int>) = VariableAddress[b] :
37479+
# 46| mu46_5(int) = InitializeParameter[b] : &:r46_4
37480+
# 47| r47_1(glval<int>) = VariableAddress[x] :
37481+
# 47| r47_2(int) = Constant[0] :
37482+
# 47| mu47_3(int) = Store[x] : &:r47_1, r47_2
37483+
# 49| r49_1(glval<int>) = VariableAddress[y] :
37484+
# 49| r49_2(glval<unknown>) = FunctionAddress[i] :
37485+
# 49| r49_3(int) = Call[i] : func:r49_2
37486+
# 49| mu49_4(unknown) = ^CallSideEffect : ~m?
37487+
# 49| mu49_5(int) = Store[y] : &:r49_1, r49_3
37488+
#-----| Goto -> Block 7
37489+
37490+
# 46| Block 1
37491+
# 46| v46_6(void) = AliasedUse : ~m?
37492+
# 46| v46_7(void) = ExitFunction :
37493+
37494+
# 46| Block 2
37495+
# 46| v46_8(void) = Unwind :
37496+
#-----| Goto -> Block 1
37497+
37498+
# 51| Block 3
37499+
# 51| r51_1(int) = Constant[0] :
37500+
# 51| r51_2(bool) = CompareEQ : r51_7, r51_1
37501+
# 51| v51_3(void) = ConditionalBranch : r51_2
37502+
#-----| False -> Block 4
37503+
#-----| True -> Block 2
37504+
37505+
# 51| Block 4
37506+
# 51| r51_4(int) = Constant[1] :
37507+
# 51| r51_5(bool) = CompareEQ : r51_7, r51_4
37508+
# 51| v51_6(void) = ConditionalBranch : r51_5
37509+
#-----| True -> Block 6
37510+
37511+
# 51| Block 5
37512+
# 51| r51_7(int) = Constant[1] :
37513+
# 51| r51_8(int) = Constant[-1] :
37514+
# 51| r51_9(bool) = CompareEQ : r51_7, r51_8
37515+
# 51| v51_10(void) = ConditionalBranch : r51_9
37516+
#-----| False -> Block 3
37517+
#-----| True -> Block 2
37518+
37519+
# 52| Block 6
37520+
# 52| r52_1(glval<unknown>) = FunctionAddress[sink] :
37521+
# 52| r52_2(glval<int>) = VariableAddress[x] :
37522+
# 52| r52_3(int) = Load[x] : &:r52_2, ~m?
37523+
# 52| v52_4(void) = Call[sink] : func:r52_1, 0:r52_3
37524+
# 52| mu52_5(unknown) = ^CallSideEffect : ~m?
37525+
#-----| Goto -> Block 7
37526+
37527+
# 54| Block 7
37528+
# 54| v54_1(void) = NoOp :
37529+
# 46| v46_9(void) = ReturnVoid :
37530+
#-----| Goto -> Block 1
37531+
3747337532
try_except.cpp:
3747437533
# 6| void f_cpp()
3747537534
# 6| Block 0
@@ -37682,10 +37741,10 @@ try_except.cpp:
3768237741
#-----| Goto -> Block 1
3768337742

3768437743
# 48| Block 3
37685-
# 48| r48_1(glval<int>) = VariableAddress[#throw48:13] :
37686-
# 48| r48_2(int) = Constant[1] :
37687-
# 48| mu48_3(int) = Store[#throw48:13] : &:r48_1, r48_2
37688-
# 48| v48_4(void) = ThrowValue : &:r48_1, ~m?
37744+
# 48| r48_1(glval<int>) = VariableAddress[#throw48:7] :
37745+
# 48| r48_2(int) = Constant[1] :
37746+
# 48| mu48_3(int) = Store[#throw48:7] : &:r48_1, r48_2
37747+
# 48| v48_4(void) = ThrowValue : &:r48_1, ~m?
3768937748
#-----| C++ Exception -> Block 6
3769037749

3769137750
# 51| Block 4

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

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,24 @@ void AfxThrowMemoryException();
3131

3232
void h(int b) {
3333
int x = 0;
34-
__try {
35-
if (b) {
36-
AfxThrowMemoryException();
37-
}
38-
}
39-
__except (1) {
40-
sink(x);
34+
__try {
35+
if (b) {
36+
AfxThrowMemoryException();
4137
}
42-
}
38+
}
39+
__except (1) {
40+
sink(x);
41+
}
42+
}
43+
44+
int i();
45+
46+
void j(int b) {
47+
int x = 0;
48+
__try {
49+
int y = i();
50+
}
51+
__except (1) {
52+
sink(x);
53+
}
54+
}

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,24 @@ void AfxThrowMemoryException();
3131

3232
void h_cpp(int b) {
3333
int x = 0;
34-
__try {
35-
if (b) {
36-
AfxThrowMemoryException();
37-
}
38-
}
39-
__except (1) {
40-
sink(x);
34+
__try {
35+
if (b) {
36+
AfxThrowMemoryException();
4137
}
38+
}
39+
__except (1) {
40+
sink(x);
41+
}
4242
}
4343

4444
void throw_cpp(int b) {
4545
int x = 0;
46-
__try {
47-
if (b) {
48-
throw 1;
49-
}
50-
}
51-
__except (1) {
52-
sink(x);
46+
__try {
47+
if (b) {
48+
throw 1;
5349
}
50+
}
51+
__except (1) {
52+
sink(x);
53+
}
5454
}

0 commit comments

Comments
 (0)