Skip to content

Commit 6e0b5bc

Browse files
authored
Merge pull request github#17414 from MathiasVP/add-more-try-except-testcases
C++: Add more IR inconsistency tests
2 parents 1250e72 + 353cd8c commit 6e0b5bc

9 files changed

+251
-0
lines changed

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

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4501,6 +4501,100 @@ ir.c:
45014501
# 40| Value = [Literal] 1
45024502
# 40| ValueCategory = prvalue
45034503
# 42| getStmt(1): [ReturnStmt] return ...
4504+
# 44| [TopLevelFunction] void try_with_finally()
4505+
# 44| <params>:
4506+
# 45| getEntryPoint(): [BlockStmt] { ... }
4507+
# 46| getStmt(0): [DeclStmt] declaration
4508+
# 46| getDeclarationEntry(0): [VariableDeclarationEntry] definition of x
4509+
# 46| Type = [IntType] int
4510+
# 46| getVariable().getInitializer(): [Initializer] initializer for x
4511+
# 46| getExpr(): [Literal] 0
4512+
# 46| Type = [IntType] int
4513+
# 46| Value = [Literal] 0
4514+
# 46| ValueCategory = prvalue
4515+
# 47| getStmt(1): [MicrosoftTryFinallyStmt] __try { ... } __finally { ... }
4516+
# 48| getStmt(): [BlockStmt] { ... }
4517+
# 49| getStmt(0): [ExprStmt] ExprStmt
4518+
# 49| getExpr(): [AssignExpr] ... = ...
4519+
# 49| Type = [IntType] int
4520+
# 49| ValueCategory = prvalue
4521+
# 49| getLValue(): [VariableAccess] x
4522+
# 49| Type = [IntType] int
4523+
# 49| ValueCategory = lvalue
4524+
# 49| getRValue(): [Literal] 1
4525+
# 49| Type = [IntType] int
4526+
# 49| Value = [Literal] 1
4527+
# 49| ValueCategory = prvalue
4528+
# 52| getFinally(): [BlockStmt] { ... }
4529+
# 53| getStmt(0): [ExprStmt] ExprStmt
4530+
# 53| getExpr(): [AssignExpr] ... = ...
4531+
# 53| Type = [IntType] int
4532+
# 53| ValueCategory = prvalue
4533+
# 53| getLValue(): [VariableAccess] x
4534+
# 53| Type = [IntType] int
4535+
# 53| ValueCategory = lvalue
4536+
# 53| getRValue(): [Literal] 2
4537+
# 53| Type = [IntType] int
4538+
# 53| Value = [Literal] 2
4539+
# 53| ValueCategory = prvalue
4540+
# 55| getStmt(2): [ReturnStmt] return ...
4541+
# 57| [TopLevelFunction] void throw_in_try_with_finally()
4542+
# 57| <params>:
4543+
# 58| getEntryPoint(): [BlockStmt] { ... }
4544+
# 59| getStmt(0): [DeclStmt] declaration
4545+
# 59| getDeclarationEntry(0): [VariableDeclarationEntry] definition of x
4546+
# 59| Type = [IntType] int
4547+
# 59| getVariable().getInitializer(): [Initializer] initializer for x
4548+
# 59| getExpr(): [Literal] 0
4549+
# 59| Type = [IntType] int
4550+
# 59| Value = [Literal] 0
4551+
# 59| ValueCategory = prvalue
4552+
# 60| getStmt(1): [MicrosoftTryFinallyStmt] __try { ... } __finally { ... }
4553+
# 61| getStmt(): [BlockStmt] { ... }
4554+
# 62| getStmt(0): [ExprStmt] ExprStmt
4555+
# 62| getExpr(): [FunctionCall] call to ExRaiseAccessViolation
4556+
# 62| Type = [VoidType] void
4557+
# 62| ValueCategory = prvalue
4558+
# 62| getArgument(0): [Literal] 0
4559+
# 62| Type = [IntType] int
4560+
# 62| Value = [Literal] 0
4561+
# 62| ValueCategory = prvalue
4562+
# 65| getFinally(): [BlockStmt] { ... }
4563+
# 66| getStmt(0): [ExprStmt] ExprStmt
4564+
# 66| getExpr(): [AssignExpr] ... = ...
4565+
# 66| Type = [IntType] int
4566+
# 66| ValueCategory = prvalue
4567+
# 66| getLValue(): [VariableAccess] x
4568+
# 66| Type = [IntType] int
4569+
# 66| ValueCategory = lvalue
4570+
# 66| getRValue(): [Literal] 1
4571+
# 66| Type = [IntType] int
4572+
# 66| Value = [Literal] 1
4573+
# 66| ValueCategory = prvalue
4574+
# 68| getStmt(2): [ReturnStmt] return ...
4575+
# 70| [TopLevelFunction] void throw_in_try_with_throw_in_finally()
4576+
# 70| <params>:
4577+
# 71| getEntryPoint(): [BlockStmt] { ... }
4578+
# 72| getStmt(0): [MicrosoftTryFinallyStmt] __try { ... } __finally { ... }
4579+
# 72| getStmt(): [BlockStmt] { ... }
4580+
# 73| getStmt(0): [ExprStmt] ExprStmt
4581+
# 73| getExpr(): [FunctionCall] call to ExRaiseAccessViolation
4582+
# 73| Type = [VoidType] void
4583+
# 73| ValueCategory = prvalue
4584+
# 73| getArgument(0): [Literal] 0
4585+
# 73| Type = [IntType] int
4586+
# 73| Value = [Literal] 0
4587+
# 73| ValueCategory = prvalue
4588+
# 75| getFinally(): [BlockStmt] { ... }
4589+
# 76| getStmt(0): [ExprStmt] ExprStmt
4590+
# 76| getExpr(): [FunctionCall] call to ExRaiseAccessViolation
4591+
# 76| Type = [VoidType] void
4592+
# 76| ValueCategory = prvalue
4593+
# 76| getArgument(0): [Literal] 0
4594+
# 76| Type = [IntType] int
4595+
# 76| Value = [Literal] 0
4596+
# 76| ValueCategory = prvalue
4597+
# 78| getStmt(1): [ReturnStmt] return ...
45044598
ir.cpp:
45054599
# 1| [TopLevelFunction] void Constants()
45064600
# 1| <params>:

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3203,6 +3203,53 @@ ir.c:
32033203
# 32| Block 5
32043204
# 32| v32_5(void) = Unreached :
32053205

3206+
# 44| void try_with_finally()
3207+
# 44| Block 0
3208+
# 44| v44_1(void) = EnterFunction :
3209+
# 44| m44_2(unknown) = AliasedDefinition :
3210+
# 44| m44_3(unknown) = InitializeNonLocal :
3211+
# 44| m44_4(unknown) = Chi : total:m44_2, partial:m44_3
3212+
# 46| r46_1(glval<int>) = VariableAddress[x] :
3213+
# 46| r46_2(int) = Constant[0] :
3214+
# 46| m46_3(int) = Store[x] : &:r46_1, r46_2
3215+
# 49| r49_1(int) = Constant[1] :
3216+
# 49| r49_2(glval<int>) = VariableAddress[x] :
3217+
# 49| m49_3(int) = Store[x] : &:r49_2, r49_1
3218+
# 53| r53_1(int) = Constant[2] :
3219+
# 53| r53_2(glval<int>) = VariableAddress[x] :
3220+
# 53| m53_3(int) = Store[x] : &:r53_2, r53_1
3221+
# 55| v55_1(void) = NoOp :
3222+
# 44| v44_5(void) = ReturnVoid :
3223+
# 44| v44_6(void) = AliasedUse : m44_3
3224+
# 44| v44_7(void) = ExitFunction :
3225+
3226+
# 57| void throw_in_try_with_finally()
3227+
# 57| Block 0
3228+
# 57| v57_1(void) = EnterFunction :
3229+
# 57| m57_2(unknown) = AliasedDefinition :
3230+
# 57| m57_3(unknown) = InitializeNonLocal :
3231+
# 57| m57_4(unknown) = Chi : total:m57_2, partial:m57_3
3232+
# 59| r59_1(glval<int>) = VariableAddress[x] :
3233+
# 59| r59_2(int) = Constant[0] :
3234+
# 59| m59_3(int) = Store[x] : &:r59_1, r59_2
3235+
# 62| r62_1(glval<unknown>) = FunctionAddress[ExRaiseAccessViolation] :
3236+
# 62| r62_2(int) = Constant[0] :
3237+
# 62| v62_3(void) = Call[ExRaiseAccessViolation] : func:r62_1, 0:r62_2
3238+
# 62| m62_4(unknown) = ^CallSideEffect : ~m57_4
3239+
# 62| m62_5(unknown) = Chi : total:m57_4, partial:m62_4
3240+
3241+
# 70| void throw_in_try_with_throw_in_finally()
3242+
# 70| Block 0
3243+
# 70| v70_1(void) = EnterFunction :
3244+
# 70| m70_2(unknown) = AliasedDefinition :
3245+
# 70| m70_3(unknown) = InitializeNonLocal :
3246+
# 70| m70_4(unknown) = Chi : total:m70_2, partial:m70_3
3247+
# 73| r73_1(glval<unknown>) = FunctionAddress[ExRaiseAccessViolation] :
3248+
# 73| r73_2(int) = Constant[0] :
3249+
# 73| v73_3(void) = Call[ExRaiseAccessViolation] : func:r73_1, 0:r73_2
3250+
# 73| m73_4(unknown) = ^CallSideEffect : ~m70_4
3251+
# 73| m73_5(unknown) = Chi : total:m70_4, partial:m73_4
3252+
32063253
ir.cpp:
32073254
# 1| void Constants()
32083255
# 1| Block 0

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+
| ir.c:62:5:62:26 | Chi: call to ExRaiseAccessViolation | Instruction 'Chi: call to ExRaiseAccessViolation' has no successors in function '$@'. | ir.c:57:6:57:30 | void throw_in_try_with_finally() | void throw_in_try_with_finally() |
10+
| ir.c:73:5:73:26 | Chi: call to ExRaiseAccessViolation | Instruction 'Chi: call to ExRaiseAccessViolation' has no successors in function '$@'. | ir.c:70:6:70:39 | void throw_in_try_with_throw_in_finally() | void throw_in_try_with_throw_in_finally() |
911
ambiguousSuccessors
1012
unexplainedLoop
1113
| ir.c:38:13:38:37 | Constant: 1 | Instruction 'Constant: 1' is part of an unexplained loop in function '$@'. | ir.c:32:6:32:32 | void unexplained_loop_regression() | void unexplained_loop_regression() |

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+
| ir.c:62:5:62:26 | Chi: call to ExRaiseAccessViolation | Instruction 'Chi: call to ExRaiseAccessViolation' has no successors in function '$@'. | ir.c:57:6:57:30 | void throw_in_try_with_finally() | void throw_in_try_with_finally() |
10+
| ir.c:73:5:73:26 | Chi: call to ExRaiseAccessViolation | Instruction 'Chi: call to ExRaiseAccessViolation' has no successors in function '$@'. | ir.c:70:6:70:39 | void throw_in_try_with_throw_in_finally() | void throw_in_try_with_throw_in_finally() |
911
ambiguousSuccessors
1012
unexplainedLoop
1113
| ir.c:38:13:38:37 | Constant: 1 | Instruction 'Constant: 1' is part of an unexplained loop in function '$@'. | ir.c:32:6:32:32 | void unexplained_loop_regression() | void unexplained_loop_regression() |

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,40 @@ void unexplained_loop_regression()
4141
}
4242
}
4343

44+
void try_with_finally()
45+
{
46+
int x = 0;
47+
__try
48+
{
49+
x = 1;
50+
}
51+
__finally
52+
{
53+
x = 2;
54+
}
55+
}
56+
57+
void throw_in_try_with_finally()
58+
{
59+
int x = 0;
60+
__try
61+
{
62+
ExRaiseAccessViolation(0);
63+
}
64+
__finally
65+
{
66+
x = 1;
67+
}
68+
}
69+
70+
void throw_in_try_with_throw_in_finally()
71+
{
72+
__try {
73+
ExRaiseAccessViolation(0);
74+
}
75+
__finally {
76+
ExRaiseAccessViolation(0);
77+
}
78+
}
79+
4480
// semmle-extractor-options: --microsoft

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ missingOperandType
66
duplicateChiOperand
77
sideEffectWithoutPrimary
88
instructionWithoutSuccessor
9+
| ir.c:62:5:62:26 | CallSideEffect: call to ExRaiseAccessViolation | Instruction 'CallSideEffect: call to ExRaiseAccessViolation' has no successors in function '$@'. | ir.c:57:6:57:30 | void throw_in_try_with_finally() | void throw_in_try_with_finally() |
10+
| ir.c:73:5:73:26 | CallSideEffect: call to ExRaiseAccessViolation | Instruction 'CallSideEffect: call to ExRaiseAccessViolation' has no successors in function '$@'. | ir.c:70:6:70:39 | void throw_in_try_with_throw_in_finally() | void throw_in_try_with_throw_in_finally() |
11+
| ir.c:76:5:76:26 | CallSideEffect: call to ExRaiseAccessViolation | Instruction 'CallSideEffect: call to ExRaiseAccessViolation' has no successors in function '$@'. | ir.c:70:6:70:39 | void throw_in_try_with_throw_in_finally() | void throw_in_try_with_throw_in_finally() |
912
ambiguousSuccessors
1013
unexplainedLoop
1114
| ir.c:38:13:38:37 | Constant: 1 | Instruction 'Constant: 1' is part of an unexplained loop in function '$@'. | ir.c:32:6:32:32 | void unexplained_loop_regression() | void unexplained_loop_regression() |

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

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2972,6 +2972,69 @@ ir.c:
29722972
# 40| mu40_4(unknown) = ^CallSideEffect : ~m?
29732973
#-----| Exception (back edge) -> Block 4
29742974

2975+
# 44| void try_with_finally()
2976+
# 44| Block 0
2977+
# 44| v44_1(void) = EnterFunction :
2978+
# 44| mu44_2(unknown) = AliasedDefinition :
2979+
# 44| mu44_3(unknown) = InitializeNonLocal :
2980+
# 46| r46_1(glval<int>) = VariableAddress[x] :
2981+
# 46| r46_2(int) = Constant[0] :
2982+
# 46| mu46_3(int) = Store[x] : &:r46_1, r46_2
2983+
# 49| r49_1(int) = Constant[1] :
2984+
# 49| r49_2(glval<int>) = VariableAddress[x] :
2985+
# 49| mu49_3(int) = Store[x] : &:r49_2, r49_1
2986+
# 53| r53_1(int) = Constant[2] :
2987+
# 53| r53_2(glval<int>) = VariableAddress[x] :
2988+
# 53| mu53_3(int) = Store[x] : &:r53_2, r53_1
2989+
# 55| v55_1(void) = NoOp :
2990+
# 44| v44_4(void) = ReturnVoid :
2991+
# 44| v44_5(void) = AliasedUse : ~m?
2992+
# 44| v44_6(void) = ExitFunction :
2993+
2994+
# 57| void throw_in_try_with_finally()
2995+
# 57| Block 0
2996+
# 57| v57_1(void) = EnterFunction :
2997+
# 57| mu57_2(unknown) = AliasedDefinition :
2998+
# 57| mu57_3(unknown) = InitializeNonLocal :
2999+
# 59| r59_1(glval<int>) = VariableAddress[x] :
3000+
# 59| r59_2(int) = Constant[0] :
3001+
# 59| mu59_3(int) = Store[x] : &:r59_1, r59_2
3002+
# 62| r62_1(glval<unknown>) = FunctionAddress[ExRaiseAccessViolation] :
3003+
# 62| r62_2(int) = Constant[0] :
3004+
# 62| v62_3(void) = Call[ExRaiseAccessViolation] : func:r62_1, 0:r62_2
3005+
# 62| mu62_4(unknown) = ^CallSideEffect : ~m?
3006+
3007+
# 66| Block 1
3008+
# 66| r66_1(int) = Constant[1] :
3009+
# 66| r66_2(glval<int>) = VariableAddress[x] :
3010+
# 66| mu66_3(int) = Store[x] : &:r66_2, r66_1
3011+
# 68| v68_1(void) = NoOp :
3012+
# 57| v57_4(void) = ReturnVoid :
3013+
# 57| v57_5(void) = AliasedUse : ~m?
3014+
# 57| v57_6(void) = ExitFunction :
3015+
3016+
# 70| void throw_in_try_with_throw_in_finally()
3017+
# 70| Block 0
3018+
# 70| v70_1(void) = EnterFunction :
3019+
# 70| mu70_2(unknown) = AliasedDefinition :
3020+
# 70| mu70_3(unknown) = InitializeNonLocal :
3021+
# 73| r73_1(glval<unknown>) = FunctionAddress[ExRaiseAccessViolation] :
3022+
# 73| r73_2(int) = Constant[0] :
3023+
# 73| v73_3(void) = Call[ExRaiseAccessViolation] : func:r73_1, 0:r73_2
3024+
# 73| mu73_4(unknown) = ^CallSideEffect : ~m?
3025+
3026+
# 76| Block 1
3027+
# 76| r76_1(glval<unknown>) = FunctionAddress[ExRaiseAccessViolation] :
3028+
# 76| r76_2(int) = Constant[0] :
3029+
# 76| v76_3(void) = Call[ExRaiseAccessViolation] : func:r76_1, 0:r76_2
3030+
# 76| mu76_4(unknown) = ^CallSideEffect : ~m?
3031+
3032+
# 78| Block 2
3033+
# 78| v78_1(void) = NoOp :
3034+
# 70| v70_4(void) = ReturnVoid :
3035+
# 70| v70_5(void) = AliasedUse : ~m?
3036+
# 70| v70_6(void) = ExitFunction :
3037+
29753038
ir.cpp:
29763039
# 1| void Constants()
29773040
# 1| Block 0

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+
| ir.c:62:5:62:26 | CallSideEffect: call to ExRaiseAccessViolation | Instruction 'CallSideEffect: call to ExRaiseAccessViolation' has no successors in function '$@'. | ir.c:57:6:57:30 | void throw_in_try_with_finally() | void throw_in_try_with_finally() |
10+
| ir.c:73:5:73:26 | CallSideEffect: call to ExRaiseAccessViolation | Instruction 'CallSideEffect: call to ExRaiseAccessViolation' has no successors in function '$@'. | ir.c:70:6:70:39 | void throw_in_try_with_throw_in_finally() | void throw_in_try_with_throw_in_finally() |
911
ambiguousSuccessors
1012
unexplainedLoop
1113
| ir.c:38:13:38:37 | Constant: 1 | Instruction 'Constant: 1' is part of an unexplained loop in function '$@'. | ir.c:32:6:32:32 | void unexplained_loop_regression() | void unexplained_loop_regression() |

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+
| ir.c:62:5:62:26 | CallSideEffect: call to ExRaiseAccessViolation | Instruction 'CallSideEffect: call to ExRaiseAccessViolation' has no successors in function '$@'. | ir.c:57:6:57:30 | void throw_in_try_with_finally() | void throw_in_try_with_finally() |
10+
| ir.c:73:5:73:26 | CallSideEffect: call to ExRaiseAccessViolation | Instruction 'CallSideEffect: call to ExRaiseAccessViolation' has no successors in function '$@'. | ir.c:70:6:70:39 | void throw_in_try_with_throw_in_finally() | void throw_in_try_with_throw_in_finally() |
911
ambiguousSuccessors
1012
unexplainedLoop
1113
| ir.c:38:13:38:37 | Constant: 1 | Instruction 'Constant: 1' is part of an unexplained loop in function '$@'. | ir.c:32:6:32:32 | void unexplained_loop_regression() | void unexplained_loop_regression() |

0 commit comments

Comments
 (0)