Skip to content

Commit a5379b8

Browse files
committed
C++: Add assertion inside catch block. This does not yet work because the 'LocalScopeVariable' does not have a result for 'getFunction'.
1 parent d183dcd commit a5379b8

File tree

4 files changed

+60
-12
lines changed

4 files changed

+60
-12
lines changed

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25562,7 +25562,25 @@ ir.cpp:
2556225562
# 2867| Type = [IntType] int
2556325563
# 2867| Value = [ParenthesisExpr] 0
2556425564
# 2867| ValueCategory = prvalue
25565-
# 2868| getStmt(2): [ReturnStmt] return ...
25565+
# 2869| getStmt(2): [TryStmt] try { ... }
25566+
# 2869| getStmt(): [BlockStmt] { ... }
25567+
# 2871| getChild(1): [Handler] <handler>
25568+
# 2871| getParameter(): [Parameter] c
25569+
# 2871| Type = [IntType] int
25570+
# 2871| getBlock(): [CatchBlock] { ... }
25571+
# 2872| getStmt(0): [ExprStmt] ExprStmt
25572+
# 2872| getExpr(): [Literal] 0
25573+
# 2872| Type = [IntType] int
25574+
# 2872| Value = [Literal] 0
25575+
# 2872| ValueCategory = prvalue
25576+
# 2872| getExpr().getFullyConverted(): [ParenthesisExpr] (...)
25577+
# 2872| Type = [VoidType] void
25578+
# 2872| ValueCategory = prvalue
25579+
# 2872| getExpr(): [CStyleCast] (void)...
25580+
# 2872| Conversion = [VoidConversion] conversion to void
25581+
# 2872| Type = [VoidType] void
25582+
# 2872| ValueCategory = prvalue
25583+
# 2874| getStmt(3): [ReturnStmt] return ...
2556625584
ir23.cpp:
2556725585
# 1| [TopLevelFunction] bool consteval_1()
2556825586
# 1| <params>:

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20998,7 +20998,8 @@ ir.cpp:
2099820998
# 2867| r2867_6(glval<int>) = VariableAddress[#temp2867:13] :
2099920999
# 2867| r2867_7(int) = Load[#temp2867:13] : &:r2867_6, m2867_5
2100021000
# 2867| m2867_8(int) = Store[z] : &:r2867_1, r2867_7
21001-
# 2868| v2868_1(void) = NoOp :
21001+
# 2869| v2869_1(void) = NoOp :
21002+
# 2874| v2874_1(void) = NoOp :
2100221003
# 2865| v2865_11(void) = ReturnVoid :
2100321004
# 2865| v2865_12(void) = AliasedUse : m2865_3
2100421005
# 2865| v2865_13(void) = ExitFunction :

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2865,6 +2865,12 @@ template void test_assert_in_template<short>(short, int, unsigned);
28652865
void complex_assertions(int x, bool b, int max) {
28662866
int y = (assert(x > 0), x);
28672867
int z = b ? (assert(x != 0), 0) : 1;
2868+
2869+
try {
2870+
throw 41;
2871+
} catch (int c) {
2872+
assert(c < 42);
2873+
}
28682874
}
28692875

28702876
// semmle-extractor-options: -std=c++20 --clang

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

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19125,28 +19125,51 @@ ir.cpp:
1912519125
# 2867| r2867_2(glval<bool>) = VariableAddress[b] :
1912619126
# 2867| r2867_3(bool) = Load[b] : &:r2867_2, ~m?
1912719127
# 2867| v2867_4(void) = ConditionalBranch : r2867_3
19128-
#-----| False -> Block 3
19129-
#-----| True -> Block 2
19128+
#-----| False -> Block 5
19129+
#-----| True -> Block 4
19130+
19131+
# 2865| Block 1
19132+
# 2865| v2865_10(void) = AliasedUse : ~m?
19133+
# 2865| v2865_11(void) = ExitFunction :
1913019134

19131-
# 2867| Block 1
19135+
# 2865| Block 2
19136+
# 2865| v2865_12(void) = Unwind :
19137+
#-----| Goto -> Block 1
19138+
19139+
# 2867| Block 3
1913219140
# 2867| r2867_5(glval<int>) = VariableAddress[#temp2867:13] :
1913319141
# 2867| r2867_6(int) = Load[#temp2867:13] : &:r2867_5, ~m?
1913419142
# 2867| mu2867_7(int) = Store[z] : &:r2867_1, r2867_6
19135-
# 2868| v2868_1(void) = NoOp :
19136-
# 2865| v2865_10(void) = ReturnVoid :
19137-
# 2865| v2865_11(void) = AliasedUse : ~m?
19138-
# 2865| v2865_12(void) = ExitFunction :
19143+
# 2869| v2869_1(void) = NoOp :
19144+
#-----| Goto -> Block 8
1913919145

19140-
# 2867| Block 2
19146+
# 2867| Block 4
1914119147
# 2867| r2867_8(int) = Constant[0] :
1914219148
# 2867| r2867_9(glval<int>) = VariableAddress[#temp2867:13] :
1914319149
# 2867| mu2867_10(int) = Store[#temp2867:13] : &:r2867_9, r2867_8
19144-
#-----| Goto -> Block 1
19150+
#-----| Goto -> Block 3
1914519151

19146-
# 2867| Block 3
19152+
# 2867| Block 5
1914719153
# 2867| r2867_11(int) = Constant[1] :
1914819154
# 2867| r2867_12(glval<int>) = VariableAddress[#temp2867:13] :
1914919155
# 2867| mu2867_13(int) = Store[#temp2867:13] : &:r2867_12, r2867_11
19156+
#-----| Goto -> Block 3
19157+
19158+
# 2871| Block 6
19159+
# 2871| v2871_1(void) = CatchByType[int] :
19160+
#-----| C++ Exception -> Block 2
19161+
#-----| Goto -> Block 7
19162+
19163+
# 2871| Block 7
19164+
# 2871| r2871_2(glval<int>) = VariableAddress[c] :
19165+
# 2871| mu2871_3(int) = InitializeParameter[c] : &:r2871_2
19166+
# 2872| r2872_1(int) = Constant[0] :
19167+
# 2872| v2872_2(void) = Convert : r2872_1
19168+
#-----| Goto -> Block 8
19169+
19170+
# 2874| Block 8
19171+
# 2874| v2874_1(void) = NoOp :
19172+
# 2865| v2865_13(void) = ReturnVoid :
1915019173
#-----| Goto -> Block 1
1915119174

1915219175
ir23.cpp:

0 commit comments

Comments
 (0)