Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6a11ef5

Browse files
C++: Add a couple test cases for unreachable code in IR
1 parent 78e5b3a commit 6a11ef5

6 files changed

Lines changed: 329 additions & 0 deletions

File tree

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

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6668,3 +6668,63 @@ ir.cpp:
66686668
# 1018| -1: p
66696669
# 1018| Type = Point *
66706670
# 1018| ValueCategory = prvalue(load)
6671+
# 1021| UnreachableViaGoto() -> int
6672+
# 1021| params:
6673+
# 1021| body: { ... }
6674+
# 1022| 0: goto ...
6675+
# 1023| 1: return ...
6676+
# 1023| 0: 1
6677+
# 1023| Type = int
6678+
# 1023| Value = 1
6679+
# 1023| ValueCategory = prvalue
6680+
# 1024| 2: label ...:
6681+
# 1025| 3: return ...
6682+
# 1025| 0: 0
6683+
# 1025| Type = int
6684+
# 1025| Value = 0
6685+
# 1025| ValueCategory = prvalue
6686+
# 1028| UnreachableIf(bool) -> int
6687+
# 1028| params:
6688+
# 1028| 0: b
6689+
# 1028| Type = bool
6690+
# 1028| body: { ... }
6691+
# 1029| 0: if (...) ...
6692+
# 1029| 0: b
6693+
# 1029| Type = bool
6694+
# 1029| ValueCategory = prvalue(load)
6695+
# 1029| 1: { ... }
6696+
# 1030| 0: if (...) ...
6697+
# 1030| 0: 0
6698+
# 1030| Type = bool
6699+
# 1030| Value = 0
6700+
# 1030| ValueCategory = prvalue
6701+
# 1030| 1: { ... }
6702+
# 1031| 0: return ...
6703+
# 1031| 0: 1
6704+
# 1031| Type = int
6705+
# 1031| Value = 1
6706+
# 1031| ValueCategory = prvalue
6707+
# 1033| 2: { ... }
6708+
# 1034| 0: return ...
6709+
# 1034| 0: 0
6710+
# 1034| Type = int
6711+
# 1034| Value = 0
6712+
# 1034| ValueCategory = prvalue
6713+
# 1037| 2: { ... }
6714+
# 1038| 0: if (...) ...
6715+
# 1038| 0: 1
6716+
# 1038| Type = bool
6717+
# 1038| Value = 1
6718+
# 1038| ValueCategory = prvalue
6719+
# 1038| 1: { ... }
6720+
# 1039| 0: return ...
6721+
# 1039| 0: 0
6722+
# 1039| Type = int
6723+
# 1039| Value = 0
6724+
# 1039| ValueCategory = prvalue
6725+
# 1041| 2: { ... }
6726+
# 1042| 0: return ...
6727+
# 1042| 0: 1
6728+
# 1042| Type = int
6729+
# 1042| Value = 1
6730+
# 1042| ValueCategory = prvalue

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

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4618,3 +4618,84 @@ ir.cpp:
46184618
# 1005| v6_13(void) = ReturnValue : r6_12, m6_11
46194619
# 1005| v6_14(void) = UnmodeledUse : mu*
46204620
# 1005| v6_15(void) = ExitFunction :
4621+
4622+
# 1021| UnreachableViaGoto() -> int
4623+
# 1021| Block 0
4624+
# 1021| v0_0(void) = EnterFunction :
4625+
# 1021| m0_1(unknown) = AliasedDefinition :
4626+
# 1021| mu0_2(unknown) = UnmodeledDefinition :
4627+
# 1022| v0_3(void) = NoOp :
4628+
# 1024| v0_4(void) = NoOp :
4629+
# 1025| r0_5(glval<int>) = VariableAddress[#return] :
4630+
# 1025| r0_6(int) = Constant[0] :
4631+
# 1025| m0_7(int) = Store : r0_5, r0_6
4632+
#-----| Goto -> Block 1
4633+
4634+
# 1021| Block 1
4635+
# 1021| m1_0(int) = Phi : from 0:m0_7, from 2:m2_2
4636+
# 1021| r1_1(glval<int>) = VariableAddress[#return] :
4637+
# 1021| v1_2(void) = ReturnValue : r1_1, m1_0
4638+
# 1021| v1_3(void) = UnmodeledUse : mu*
4639+
# 1021| v1_4(void) = ExitFunction :
4640+
4641+
# 1023| Block 2
4642+
# 1023| r2_0(glval<int>) = VariableAddress[#return] :
4643+
# 1023| r2_1(int) = Constant[1] :
4644+
# 1023| m2_2(int) = Store : r2_0, r2_1
4645+
#-----| Goto -> Block 1
4646+
4647+
# 1028| UnreachableIf(bool) -> int
4648+
# 1028| Block 0
4649+
# 1028| v0_0(void) = EnterFunction :
4650+
# 1028| m0_1(unknown) = AliasedDefinition :
4651+
# 1028| mu0_2(unknown) = UnmodeledDefinition :
4652+
# 1028| r0_3(glval<bool>) = VariableAddress[b] :
4653+
# 1028| m0_4(bool) = InitializeParameter[b] : r0_3
4654+
# 1029| r0_5(glval<bool>) = VariableAddress[b] :
4655+
# 1029| r0_6(bool) = Load : r0_5, m0_4
4656+
# 1029| v0_7(void) = ConditionalBranch : r0_6
4657+
#-----| False -> Block 5
4658+
#-----| True -> Block 2
4659+
4660+
# 1028| Block 1
4661+
# 1028| m1_0(int) = Phi : from 3:m3_2, from 4:m4_2, from 6:m6_2, from 7:m7_2
4662+
# 1028| r1_1(glval<int>) = VariableAddress[#return] :
4663+
# 1028| v1_2(void) = ReturnValue : r1_1, m1_0
4664+
# 1028| v1_3(void) = UnmodeledUse : mu*
4665+
# 1028| v1_4(void) = ExitFunction :
4666+
4667+
# 1030| Block 2
4668+
# 1030| r2_0(bool) = Constant[0] :
4669+
# 1030| v2_1(void) = ConditionalBranch : r2_0
4670+
#-----| False -> Block 4
4671+
#-----| True -> Block 3
4672+
4673+
# 1031| Block 3
4674+
# 1031| r3_0(glval<int>) = VariableAddress[#return] :
4675+
# 1031| r3_1(int) = Constant[1] :
4676+
# 1031| m3_2(int) = Store : r3_0, r3_1
4677+
#-----| Goto -> Block 1
4678+
4679+
# 1034| Block 4
4680+
# 1034| r4_0(glval<int>) = VariableAddress[#return] :
4681+
# 1034| r4_1(int) = Constant[0] :
4682+
# 1034| m4_2(int) = Store : r4_0, r4_1
4683+
#-----| Goto -> Block 1
4684+
4685+
# 1038| Block 5
4686+
# 1038| r5_0(bool) = Constant[1] :
4687+
# 1038| v5_1(void) = ConditionalBranch : r5_0
4688+
#-----| False -> Block 7
4689+
#-----| True -> Block 6
4690+
4691+
# 1039| Block 6
4692+
# 1039| r6_0(glval<int>) = VariableAddress[#return] :
4693+
# 1039| r6_1(int) = Constant[0] :
4694+
# 1039| m6_2(int) = Store : r6_0, r6_1
4695+
#-----| Goto -> Block 1
4696+
4697+
# 1042| Block 7
4698+
# 1042| r7_0(glval<int>) = VariableAddress[#return] :
4699+
# 1042| r7_1(int) = Constant[1] :
4700+
# 1042| m7_2(int) = Store : r7_0, r7_1
4701+
#-----| Goto -> Block 1

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,4 +1018,30 @@ int ChiPhiNode(Point *p, bool which1, bool which2) {
10181018
return p->x + p->y;
10191019
}
10201020

1021+
int UnreachableViaGoto() {
1022+
goto skip;
1023+
return 1;
1024+
skip:
1025+
return 0;
1026+
}
1027+
1028+
int UnreachableIf(bool b) {
1029+
if (b) {
1030+
if (false) {
1031+
return 1;
1032+
}
1033+
else {
1034+
return 0;
1035+
}
1036+
}
1037+
else {
1038+
if (true) {
1039+
return 0;
1040+
}
1041+
else {
1042+
return 1;
1043+
}
1044+
}
1045+
}
1046+
10211047
// semmle-extractor-options: -std=c++17

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

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4420,3 +4420,82 @@ ir.cpp:
44204420
# 1005| v6_12(void) = ReturnValue : r6_11, mu0_2
44214421
# 1005| v6_13(void) = UnmodeledUse : mu*
44224422
# 1005| v6_14(void) = ExitFunction :
4423+
4424+
# 1021| UnreachableViaGoto() -> int
4425+
# 1021| Block 0
4426+
# 1021| v0_0(void) = EnterFunction :
4427+
# 1021| mu0_1(unknown) = AliasedDefinition :
4428+
# 1021| mu0_2(unknown) = UnmodeledDefinition :
4429+
# 1022| v0_3(void) = NoOp :
4430+
# 1024| v0_4(void) = NoOp :
4431+
# 1025| r0_5(glval<int>) = VariableAddress[#return] :
4432+
# 1025| r0_6(int) = Constant[0] :
4433+
# 1025| mu0_7(int) = Store : r0_5, r0_6
4434+
#-----| Goto -> Block 1
4435+
4436+
# 1021| Block 1
4437+
# 1021| r1_0(glval<int>) = VariableAddress[#return] :
4438+
# 1021| v1_1(void) = ReturnValue : r1_0, mu0_2
4439+
# 1021| v1_2(void) = UnmodeledUse : mu*
4440+
# 1021| v1_3(void) = ExitFunction :
4441+
4442+
# 1023| Block 2
4443+
# 1023| r2_0(glval<int>) = VariableAddress[#return] :
4444+
# 1023| r2_1(int) = Constant[1] :
4445+
# 1023| mu2_2(int) = Store : r2_0, r2_1
4446+
#-----| Goto -> Block 1
4447+
4448+
# 1028| UnreachableIf(bool) -> int
4449+
# 1028| Block 0
4450+
# 1028| v0_0(void) = EnterFunction :
4451+
# 1028| mu0_1(unknown) = AliasedDefinition :
4452+
# 1028| mu0_2(unknown) = UnmodeledDefinition :
4453+
# 1028| r0_3(glval<bool>) = VariableAddress[b] :
4454+
# 1028| mu0_4(bool) = InitializeParameter[b] : r0_3
4455+
# 1029| r0_5(glval<bool>) = VariableAddress[b] :
4456+
# 1029| r0_6(bool) = Load : r0_5, mu0_2
4457+
# 1029| v0_7(void) = ConditionalBranch : r0_6
4458+
#-----| False -> Block 5
4459+
#-----| True -> Block 2
4460+
4461+
# 1028| Block 1
4462+
# 1028| r1_0(glval<int>) = VariableAddress[#return] :
4463+
# 1028| v1_1(void) = ReturnValue : r1_0, mu0_2
4464+
# 1028| v1_2(void) = UnmodeledUse : mu*
4465+
# 1028| v1_3(void) = ExitFunction :
4466+
4467+
# 1030| Block 2
4468+
# 1030| r2_0(bool) = Constant[0] :
4469+
# 1030| v2_1(void) = ConditionalBranch : r2_0
4470+
#-----| False -> Block 4
4471+
#-----| True -> Block 3
4472+
4473+
# 1031| Block 3
4474+
# 1031| r3_0(glval<int>) = VariableAddress[#return] :
4475+
# 1031| r3_1(int) = Constant[1] :
4476+
# 1031| mu3_2(int) = Store : r3_0, r3_1
4477+
#-----| Goto -> Block 1
4478+
4479+
# 1034| Block 4
4480+
# 1034| r4_0(glval<int>) = VariableAddress[#return] :
4481+
# 1034| r4_1(int) = Constant[0] :
4482+
# 1034| mu4_2(int) = Store : r4_0, r4_1
4483+
#-----| Goto -> Block 1
4484+
4485+
# 1038| Block 5
4486+
# 1038| r5_0(bool) = Constant[1] :
4487+
# 1038| v5_1(void) = ConditionalBranch : r5_0
4488+
#-----| False -> Block 7
4489+
#-----| True -> Block 6
4490+
4491+
# 1039| Block 6
4492+
# 1039| r6_0(glval<int>) = VariableAddress[#return] :
4493+
# 1039| r6_1(int) = Constant[0] :
4494+
# 1039| mu6_2(int) = Store : r6_0, r6_1
4495+
#-----| Goto -> Block 1
4496+
4497+
# 1042| Block 7
4498+
# 1042| r7_0(glval<int>) = VariableAddress[#return] :
4499+
# 1042| r7_1(int) = Constant[1] :
4500+
# 1042| mu7_2(int) = Store : r7_0, r7_1
4501+
#-----| Goto -> Block 1

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@
9393
| IR: TryCatch | 15 |
9494
| IR: UninitializedVariables | 1 |
9595
| IR: UnionInit | 1 |
96+
| IR: UnreachableIf | 8 |
97+
| IR: UnreachableViaGoto | 3 |
9698
| IR: VarArgUsage | 1 |
9799
| IR: VarArgs | 1 |
98100
| IR: VirtualMemberFunction | 1 |

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

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4441,3 +4441,84 @@ ir.cpp:
44414441
# 1005| v6_12(void) = ReturnValue : r6_11, m6_10
44424442
# 1005| v6_13(void) = UnmodeledUse : mu*
44434443
# 1005| v6_14(void) = ExitFunction :
4444+
4445+
# 1021| UnreachableViaGoto() -> int
4446+
# 1021| Block 0
4447+
# 1021| v0_0(void) = EnterFunction :
4448+
# 1021| mu0_1(unknown) = AliasedDefinition :
4449+
# 1021| mu0_2(unknown) = UnmodeledDefinition :
4450+
# 1022| v0_3(void) = NoOp :
4451+
# 1024| v0_4(void) = NoOp :
4452+
# 1025| r0_5(glval<int>) = VariableAddress[#return] :
4453+
# 1025| r0_6(int) = Constant[0] :
4454+
# 1025| m0_7(int) = Store : r0_5, r0_6
4455+
#-----| Goto -> Block 1
4456+
4457+
# 1021| Block 1
4458+
# 1021| m1_0(int) = Phi : from 0:m0_7, from 2:m2_2
4459+
# 1021| r1_1(glval<int>) = VariableAddress[#return] :
4460+
# 1021| v1_2(void) = ReturnValue : r1_1, m1_0
4461+
# 1021| v1_3(void) = UnmodeledUse : mu*
4462+
# 1021| v1_4(void) = ExitFunction :
4463+
4464+
# 1023| Block 2
4465+
# 1023| r2_0(glval<int>) = VariableAddress[#return] :
4466+
# 1023| r2_1(int) = Constant[1] :
4467+
# 1023| m2_2(int) = Store : r2_0, r2_1
4468+
#-----| Goto -> Block 1
4469+
4470+
# 1028| UnreachableIf(bool) -> int
4471+
# 1028| Block 0
4472+
# 1028| v0_0(void) = EnterFunction :
4473+
# 1028| mu0_1(unknown) = AliasedDefinition :
4474+
# 1028| mu0_2(unknown) = UnmodeledDefinition :
4475+
# 1028| r0_3(glval<bool>) = VariableAddress[b] :
4476+
# 1028| m0_4(bool) = InitializeParameter[b] : r0_3
4477+
# 1029| r0_5(glval<bool>) = VariableAddress[b] :
4478+
# 1029| r0_6(bool) = Load : r0_5, m0_4
4479+
# 1029| v0_7(void) = ConditionalBranch : r0_6
4480+
#-----| False -> Block 5
4481+
#-----| True -> Block 2
4482+
4483+
# 1028| Block 1
4484+
# 1028| m1_0(int) = Phi : from 3:m3_2, from 4:m4_2, from 6:m6_2, from 7:m7_2
4485+
# 1028| r1_1(glval<int>) = VariableAddress[#return] :
4486+
# 1028| v1_2(void) = ReturnValue : r1_1, m1_0
4487+
# 1028| v1_3(void) = UnmodeledUse : mu*
4488+
# 1028| v1_4(void) = ExitFunction :
4489+
4490+
# 1030| Block 2
4491+
# 1030| r2_0(bool) = Constant[0] :
4492+
# 1030| v2_1(void) = ConditionalBranch : r2_0
4493+
#-----| False -> Block 4
4494+
#-----| True -> Block 3
4495+
4496+
# 1031| Block 3
4497+
# 1031| r3_0(glval<int>) = VariableAddress[#return] :
4498+
# 1031| r3_1(int) = Constant[1] :
4499+
# 1031| m3_2(int) = Store : r3_0, r3_1
4500+
#-----| Goto -> Block 1
4501+
4502+
# 1034| Block 4
4503+
# 1034| r4_0(glval<int>) = VariableAddress[#return] :
4504+
# 1034| r4_1(int) = Constant[0] :
4505+
# 1034| m4_2(int) = Store : r4_0, r4_1
4506+
#-----| Goto -> Block 1
4507+
4508+
# 1038| Block 5
4509+
# 1038| r5_0(bool) = Constant[1] :
4510+
# 1038| v5_1(void) = ConditionalBranch : r5_0
4511+
#-----| False -> Block 7
4512+
#-----| True -> Block 6
4513+
4514+
# 1039| Block 6
4515+
# 1039| r6_0(glval<int>) = VariableAddress[#return] :
4516+
# 1039| r6_1(int) = Constant[0] :
4517+
# 1039| m6_2(int) = Store : r6_0, r6_1
4518+
#-----| Goto -> Block 1
4519+
4520+
# 1042| Block 7
4521+
# 1042| r7_0(glval<int>) = VariableAddress[#return] :
4522+
# 1042| r7_1(int) = Constant[1] :
4523+
# 1042| m7_2(int) = Store : r7_0, r7_1
4524+
#-----| Goto -> Block 1

0 commit comments

Comments
 (0)