Skip to content

Commit cd6e421

Browse files
committed
C++: Add a test with '__try __except' and '__try __finally' in the 'ir' test directory.
1 parent 073e9bc commit cd6e421

9 files changed

+242
-0
lines changed

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

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14822,3 +14822,112 @@ struct_init.cpp:
1482214822
# 41| Type = [PointerType] Info *
1482314823
# 41| ValueCategory = prvalue
1482414824
# 42| getStmt(2): [ReturnStmt] return ...
14825+
try_except.c:
14826+
# 3| [TopLevelFunction] void ProbeFunction()
14827+
# 3| <params>:
14828+
# 4| [TopLevelFunction] void sink()
14829+
# 4| <params>:
14830+
# 6| [TopLevelFunction] void f()
14831+
# 6| <params>:
14832+
# 6| getEntryPoint(): [BlockStmt] { ... }
14833+
# 7| getStmt(0): [DeclStmt] declaration
14834+
# 7| getDeclarationEntry(0): [VariableDeclarationEntry] definition of x
14835+
# 7| Type = [IntType] int
14836+
# 7| getDeclarationEntry(1): [VariableDeclarationEntry] definition of y
14837+
# 7| Type = [IntType] int
14838+
# 7| getVariable().getInitializer(): [Initializer] initializer for y
14839+
# 7| getExpr(): [Literal] 0
14840+
# 7| Type = [IntType] int
14841+
# 7| Value = [Literal] 0
14842+
# 7| ValueCategory = prvalue
14843+
# 8| getStmt(1): [MicrosoftTryExceptStmt] __try { ... } __except( ... ) { ... }
14844+
# 8| getStmt(): [BlockStmt] { ... }
14845+
# 9| getStmt(0): [ExprStmt] ExprStmt
14846+
# 9| getExpr(): [FunctionCall] call to ProbeFunction
14847+
# 9| Type = [VoidType] void
14848+
# 9| ValueCategory = prvalue
14849+
# 9| getArgument(0): [Literal] 0
14850+
# 9| Type = [IntType] int
14851+
# 9| Value = [Literal] 0
14852+
# 9| ValueCategory = prvalue
14853+
# 10| getStmt(1): [ExprStmt] ExprStmt
14854+
# 10| getExpr(): [AssignExpr] ... = ...
14855+
# 10| Type = [IntType] int
14856+
# 10| ValueCategory = prvalue
14857+
# 10| getLValue(): [VariableAccess] x
14858+
# 10| Type = [IntType] int
14859+
# 10| ValueCategory = lvalue
14860+
# 10| getRValue(): [VariableAccess] y
14861+
# 10| Type = [IntType] int
14862+
# 10| ValueCategory = prvalue(load)
14863+
# 11| getStmt(2): [ExprStmt] ExprStmt
14864+
# 11| getExpr(): [FunctionCall] call to ProbeFunction
14865+
# 11| Type = [VoidType] void
14866+
# 11| ValueCategory = prvalue
14867+
# 11| getArgument(0): [Literal] 0
14868+
# 11| Type = [IntType] int
14869+
# 11| Value = [Literal] 0
14870+
# 11| ValueCategory = prvalue
14871+
# 13| getCondition(): [Literal] 0
14872+
# 13| Type = [IntType] int
14873+
# 13| Value = [Literal] 0
14874+
# 13| ValueCategory = prvalue
14875+
# 13| getExcept(): [BlockStmt] { ... }
14876+
# 14| getStmt(0): [ExprStmt] ExprStmt
14877+
# 14| getExpr(): [FunctionCall] call to sink
14878+
# 14| Type = [VoidType] void
14879+
# 14| ValueCategory = prvalue
14880+
# 14| getArgument(0): [VariableAccess] x
14881+
# 14| Type = [IntType] int
14882+
# 14| ValueCategory = prvalue(load)
14883+
# 16| getStmt(2): [ReturnStmt] return ...
14884+
# 18| [TopLevelFunction] void g()
14885+
# 18| <params>:
14886+
# 18| getEntryPoint(): [BlockStmt] { ... }
14887+
# 19| getStmt(0): [DeclStmt] declaration
14888+
# 19| getDeclarationEntry(0): [VariableDeclarationEntry] definition of x
14889+
# 19| Type = [IntType] int
14890+
# 19| getDeclarationEntry(1): [VariableDeclarationEntry] definition of y
14891+
# 19| Type = [IntType] int
14892+
# 19| getVariable().getInitializer(): [Initializer] initializer for y
14893+
# 19| getExpr(): [Literal] 0
14894+
# 19| Type = [IntType] int
14895+
# 19| Value = [Literal] 0
14896+
# 19| ValueCategory = prvalue
14897+
# 20| getStmt(1): [MicrosoftTryFinallyStmt] __try { ... } __finally { ... }
14898+
# 20| getStmt(): [BlockStmt] { ... }
14899+
# 21| getStmt(0): [ExprStmt] ExprStmt
14900+
# 21| getExpr(): [FunctionCall] call to ProbeFunction
14901+
# 21| Type = [VoidType] void
14902+
# 21| ValueCategory = prvalue
14903+
# 21| getArgument(0): [Literal] 0
14904+
# 21| Type = [IntType] int
14905+
# 21| Value = [Literal] 0
14906+
# 21| ValueCategory = prvalue
14907+
# 22| getStmt(1): [ExprStmt] ExprStmt
14908+
# 22| getExpr(): [AssignExpr] ... = ...
14909+
# 22| Type = [IntType] int
14910+
# 22| ValueCategory = prvalue
14911+
# 22| getLValue(): [VariableAccess] x
14912+
# 22| Type = [IntType] int
14913+
# 22| ValueCategory = lvalue
14914+
# 22| getRValue(): [VariableAccess] y
14915+
# 22| Type = [IntType] int
14916+
# 22| ValueCategory = prvalue(load)
14917+
# 23| getStmt(2): [ExprStmt] ExprStmt
14918+
# 23| getExpr(): [FunctionCall] call to ProbeFunction
14919+
# 23| Type = [VoidType] void
14920+
# 23| ValueCategory = prvalue
14921+
# 23| getArgument(0): [Literal] 0
14922+
# 23| Type = [IntType] int
14923+
# 23| Value = [Literal] 0
14924+
# 23| ValueCategory = prvalue
14925+
# 25| getFinally(): [BlockStmt] { ... }
14926+
# 26| getStmt(0): [ExprStmt] ExprStmt
14927+
# 26| getExpr(): [FunctionCall] call to sink
14928+
# 26| Type = [VoidType] void
14929+
# 26| ValueCategory = prvalue
14930+
# 26| getArgument(0): [VariableAccess] x
14931+
# 26| Type = [IntType] int
14932+
# 26| ValueCategory = prvalue(load)
14933+
# 28| getStmt(2): [ReturnStmt] return ...

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ missingOperandType
66
duplicateChiOperand
77
sideEffectWithoutPrimary
88
instructionWithoutSuccessor
9+
| try_except.c:7:13:7:14 | Store: 0 | Instruction 'Store: 0' has no successors in function '$@'. | try_except.c:6:6:6:6 | void f() | void f() |
10+
| try_except.c:19:13:19:14 | Store: 0 | Instruction 'Store: 0' has no successors in function '$@'. | try_except.c:18:6:18:6 | void g() | void g() |
911
ambiguousSuccessors
1012
unexplainedLoop
1113
unnecessaryPhiInstruction

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ missingOperandType
66
duplicateChiOperand
77
sideEffectWithoutPrimary
88
instructionWithoutSuccessor
9+
| try_except.c:7:13:7:14 | Store: 0 | Instruction 'Store: 0' has no successors in function '$@'. | try_except.c:6:6:6:6 | void f() | void f() |
10+
| try_except.c:19:13:19:14 | Store: 0 | Instruction 'Store: 0' has no successors in function '$@'. | try_except.c:18:6:18:6 | void g() | void g() |
911
ambiguousSuccessors
1012
unexplainedLoop
1113
unnecessaryPhiInstruction

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9140,3 +9140,13 @@
91409140
| struct_init.cpp:41:21:41:32 | ChiTotal | total:m41_7 |
91419141
| struct_init.cpp:41:21:41:32 | SideEffect | ~m41_7 |
91429142
| struct_init.cpp:41:21:41:32 | Unary | r41_3 |
9143+
| try_except.c:6:6:6:6 | ChiPartial | partial:m6_3 |
9144+
| try_except.c:6:6:6:6 | ChiTotal | total:m6_2 |
9145+
| try_except.c:7:7:7:7 | Address | &:r7_1 |
9146+
| try_except.c:7:10:7:10 | Address | &:r7_3 |
9147+
| try_except.c:7:13:7:14 | StoreValue | r7_4 |
9148+
| try_except.c:18:6:18:6 | ChiPartial | partial:m18_3 |
9149+
| try_except.c:18:6:18:6 | ChiTotal | total:m18_2 |
9150+
| try_except.c:19:7:19:7 | Address | &:r19_1 |
9151+
| try_except.c:19:10:19:10 | Address | &:r19_3 |
9152+
| try_except.c:19:13:19:14 | StoreValue | r19_4 |

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ missingOperandType
66
duplicateChiOperand
77
sideEffectWithoutPrimary
88
instructionWithoutSuccessor
9+
| try_except.c:7:13:7:14 | Store: 0 | Instruction 'Store: 0' has no successors in function '$@'. | try_except.c:6:6:6:6 | void f() | void f() |
10+
| try_except.c:11:5:11:17 | CallSideEffect: call to ProbeFunction | Instruction 'CallSideEffect: call to ProbeFunction' has no successors in function '$@'. | try_except.c:6:6:6:6 | void f() | void f() |
11+
| try_except.c:13:13:13:13 | Constant: 0 | Instruction 'Constant: 0' has no successors in function '$@'. | try_except.c:6:6:6:6 | void f() | void f() |
12+
| try_except.c:14:5:14:8 | CallSideEffect: call to sink | Instruction 'CallSideEffect: call to sink' has no successors in function '$@'. | try_except.c:6:6:6:6 | void f() | void f() |
13+
| try_except.c:19:13:19:14 | Store: 0 | Instruction 'Store: 0' has no successors in function '$@'. | try_except.c:18:6:18:6 | void g() | void g() |
14+
| try_except.c:23:5:23:17 | CallSideEffect: call to ProbeFunction | Instruction 'CallSideEffect: call to ProbeFunction' has no successors in function '$@'. | try_except.c:18:6:18:6 | void g() | void g() |
15+
| try_except.c:26:5:26:8 | CallSideEffect: call to sink | Instruction 'CallSideEffect: call to sink' has no successors in function '$@'. | try_except.c:18:6:18:6 | void g() | void g() |
916
ambiguousSuccessors
1017
unexplainedLoop
1118
unnecessaryPhiInstruction

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

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10410,3 +10410,83 @@ struct_init.cpp:
1041010410
# 36| v36_9(void) = ReturnVoid :
1041110411
# 36| v36_10(void) = AliasedUse : ~m?
1041210412
# 36| v36_11(void) = ExitFunction :
10413+
10414+
try_except.c:
10415+
# 6| void f()
10416+
# 6| Block 0
10417+
# 6| v6_1(void) = EnterFunction :
10418+
# 6| mu6_2(unknown) = AliasedDefinition :
10419+
# 6| mu6_3(unknown) = InitializeNonLocal :
10420+
# 7| r7_1(glval<int>) = VariableAddress[x] :
10421+
# 7| mu7_2(int) = Uninitialized[x] : &:r7_1
10422+
# 7| r7_3(glval<int>) = VariableAddress[y] :
10423+
# 7| r7_4(int) = Constant[0] :
10424+
# 7| mu7_5(int) = Store[y] : &:r7_3, r7_4
10425+
10426+
# 13| Block 1
10427+
# 13| r13_1(int) = Constant[0] :
10428+
10429+
# 9| Block 2
10430+
# 9| r9_1(glval<unknown>) = FunctionAddress[ProbeFunction] :
10431+
# 9| r9_2(int) = Constant[0] :
10432+
# 9| v9_3(void) = Call[ProbeFunction] : func:r9_1, 0:r9_2
10433+
# 9| mu9_4(unknown) = ^CallSideEffect : ~m?
10434+
# 10| r10_1(glval<int>) = VariableAddress[y] :
10435+
# 10| r10_2(int) = Load[y] : &:r10_1, ~m?
10436+
# 10| r10_3(glval<int>) = VariableAddress[x] :
10437+
# 10| mu10_4(int) = Store[x] : &:r10_3, r10_2
10438+
# 11| r11_1(glval<unknown>) = FunctionAddress[ProbeFunction] :
10439+
# 11| r11_2(int) = Constant[0] :
10440+
# 11| v11_3(void) = Call[ProbeFunction] : func:r11_1, 0:r11_2
10441+
# 11| mu11_4(unknown) = ^CallSideEffect : ~m?
10442+
10443+
# 14| Block 2
10444+
# 14| r14_1(glval<unknown>) = FunctionAddress[sink] :
10445+
# 14| r14_2(glval<int>) = VariableAddress[x] :
10446+
# 14| r14_3(int) = Load[x] : &:r14_2, ~m?
10447+
# 14| v14_4(void) = Call[sink] : func:r14_1, 0:r14_3
10448+
# 14| mu14_5(unknown) = ^CallSideEffect : ~m?
10449+
10450+
# 16| Block 4
10451+
# 16| v16_1(void) = NoOp :
10452+
# 6| v6_4(void) = ReturnVoid :
10453+
# 6| v6_5(void) = AliasedUse : ~m?
10454+
# 6| v6_6(void) = ExitFunction :
10455+
10456+
# 18| void g()
10457+
# 18| Block 0
10458+
# 18| v18_1(void) = EnterFunction :
10459+
# 18| mu18_2(unknown) = AliasedDefinition :
10460+
# 18| mu18_3(unknown) = InitializeNonLocal :
10461+
# 19| r19_1(glval<int>) = VariableAddress[x] :
10462+
# 19| mu19_2(int) = Uninitialized[x] : &:r19_1
10463+
# 19| r19_3(glval<int>) = VariableAddress[y] :
10464+
# 19| r19_4(int) = Constant[0] :
10465+
# 19| mu19_5(int) = Store[y] : &:r19_3, r19_4
10466+
10467+
# 21| Block 1
10468+
# 21| r21_1(glval<unknown>) = FunctionAddress[ProbeFunction] :
10469+
# 21| r21_2(int) = Constant[0] :
10470+
# 21| v21_3(void) = Call[ProbeFunction] : func:r21_1, 0:r21_2
10471+
# 21| mu21_4(unknown) = ^CallSideEffect : ~m?
10472+
# 22| r22_1(glval<int>) = VariableAddress[y] :
10473+
# 22| r22_2(int) = Load[y] : &:r22_1, ~m?
10474+
# 22| r22_3(glval<int>) = VariableAddress[x] :
10475+
# 22| mu22_4(int) = Store[x] : &:r22_3, r22_2
10476+
# 23| r23_1(glval<unknown>) = FunctionAddress[ProbeFunction] :
10477+
# 23| r23_2(int) = Constant[0] :
10478+
# 23| v23_3(void) = Call[ProbeFunction] : func:r23_1, 0:r23_2
10479+
# 23| mu23_4(unknown) = ^CallSideEffect : ~m?
10480+
10481+
# 26| Block 1
10482+
# 26| r26_1(glval<unknown>) = FunctionAddress[sink] :
10483+
# 26| r26_2(glval<int>) = VariableAddress[x] :
10484+
# 26| r26_3(int) = Load[x] : &:r26_2, ~m?
10485+
# 26| v26_4(void) = Call[sink] : func:r26_1, 0:r26_3
10486+
# 26| mu26_5(unknown) = ^CallSideEffect : ~m?
10487+
10488+
# 28| Block 3
10489+
# 28| v28_1(void) = NoOp :
10490+
# 18| v18_4(void) = ReturnVoid :
10491+
# 18| v18_5(void) = AliasedUse : ~m?
10492+
# 18| v18_6(void) = ExitFunction :
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// semmle-extractor-options: --microsoft
2+
3+
void ProbeFunction();
4+
void sink();
5+
6+
void f() {
7+
int x, y = 0;
8+
__try {
9+
ProbeFunction(0);
10+
x = y;
11+
ProbeFunction(0);
12+
}
13+
__except (0) {
14+
sink(x);
15+
}
16+
}
17+
18+
void g() {
19+
int x, y = 0;
20+
__try {
21+
ProbeFunction(0);
22+
x = y;
23+
ProbeFunction(0);
24+
}
25+
__finally {
26+
sink(x);
27+
}
28+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ missingOperandType
66
duplicateChiOperand
77
sideEffectWithoutPrimary
88
instructionWithoutSuccessor
9+
| try_except.c:7:13:7:14 | Store: 0 | Instruction 'Store: 0' has no successors in function '$@'. | try_except.c:6:6:6:6 | void f() | void f() |
10+
| try_except.c:19:13:19:14 | Store: 0 | Instruction 'Store: 0' has no successors in function '$@'. | try_except.c:18:6:18:6 | void g() | void g() |
911
ambiguousSuccessors
1012
unexplainedLoop
1113
unnecessaryPhiInstruction

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ missingOperandType
66
duplicateChiOperand
77
sideEffectWithoutPrimary
88
instructionWithoutSuccessor
9+
| try_except.c:7:13:7:14 | Store: 0 | Instruction 'Store: 0' has no successors in function '$@'. | try_except.c:6:6:6:6 | void f() | void f() |
10+
| try_except.c:19:13:19:14 | Store: 0 | Instruction 'Store: 0' has no successors in function '$@'. | try_except.c:18:6:18:6 | void g() | void g() |
911
ambiguousSuccessors
1012
unexplainedLoop
1113
unnecessaryPhiInstruction

0 commit comments

Comments
 (0)