C++: Add a couple test cases for unreachable code in IR

This commit is contained in:
Dave Bartolomeo 2018-12-07 10:05:38 -08:00
Родитель 78e5b3ad63
Коммит 6a11ef5c18
6 изменённых файлов: 329 добавлений и 0 удалений

Просмотреть файл

@ -6668,3 +6668,63 @@ ir.cpp:
# 1018| -1: p
# 1018| Type = Point *
# 1018| ValueCategory = prvalue(load)
# 1021| UnreachableViaGoto() -> int
# 1021| params:
# 1021| body: { ... }
# 1022| 0: goto ...
# 1023| 1: return ...
# 1023| 0: 1
# 1023| Type = int
# 1023| Value = 1
# 1023| ValueCategory = prvalue
# 1024| 2: label ...:
# 1025| 3: return ...
# 1025| 0: 0
# 1025| Type = int
# 1025| Value = 0
# 1025| ValueCategory = prvalue
# 1028| UnreachableIf(bool) -> int
# 1028| params:
# 1028| 0: b
# 1028| Type = bool
# 1028| body: { ... }
# 1029| 0: if (...) ...
# 1029| 0: b
# 1029| Type = bool
# 1029| ValueCategory = prvalue(load)
# 1029| 1: { ... }
# 1030| 0: if (...) ...
# 1030| 0: 0
# 1030| Type = bool
# 1030| Value = 0
# 1030| ValueCategory = prvalue
# 1030| 1: { ... }
# 1031| 0: return ...
# 1031| 0: 1
# 1031| Type = int
# 1031| Value = 1
# 1031| ValueCategory = prvalue
# 1033| 2: { ... }
# 1034| 0: return ...
# 1034| 0: 0
# 1034| Type = int
# 1034| Value = 0
# 1034| ValueCategory = prvalue
# 1037| 2: { ... }
# 1038| 0: if (...) ...
# 1038| 0: 1
# 1038| Type = bool
# 1038| Value = 1
# 1038| ValueCategory = prvalue
# 1038| 1: { ... }
# 1039| 0: return ...
# 1039| 0: 0
# 1039| Type = int
# 1039| Value = 0
# 1039| ValueCategory = prvalue
# 1041| 2: { ... }
# 1042| 0: return ...
# 1042| 0: 1
# 1042| Type = int
# 1042| Value = 1
# 1042| ValueCategory = prvalue

Просмотреть файл

@ -4618,3 +4618,84 @@ ir.cpp:
# 1005| v6_13(void) = ReturnValue : r6_12, m6_11
# 1005| v6_14(void) = UnmodeledUse : mu*
# 1005| v6_15(void) = ExitFunction :
# 1021| UnreachableViaGoto() -> int
# 1021| Block 0
# 1021| v0_0(void) = EnterFunction :
# 1021| m0_1(unknown) = AliasedDefinition :
# 1021| mu0_2(unknown) = UnmodeledDefinition :
# 1022| v0_3(void) = NoOp :
# 1024| v0_4(void) = NoOp :
# 1025| r0_5(glval<int>) = VariableAddress[#return] :
# 1025| r0_6(int) = Constant[0] :
# 1025| m0_7(int) = Store : r0_5, r0_6
#-----| Goto -> Block 1
# 1021| Block 1
# 1021| m1_0(int) = Phi : from 0:m0_7, from 2:m2_2
# 1021| r1_1(glval<int>) = VariableAddress[#return] :
# 1021| v1_2(void) = ReturnValue : r1_1, m1_0
# 1021| v1_3(void) = UnmodeledUse : mu*
# 1021| v1_4(void) = ExitFunction :
# 1023| Block 2
# 1023| r2_0(glval<int>) = VariableAddress[#return] :
# 1023| r2_1(int) = Constant[1] :
# 1023| m2_2(int) = Store : r2_0, r2_1
#-----| Goto -> Block 1
# 1028| UnreachableIf(bool) -> int
# 1028| Block 0
# 1028| v0_0(void) = EnterFunction :
# 1028| m0_1(unknown) = AliasedDefinition :
# 1028| mu0_2(unknown) = UnmodeledDefinition :
# 1028| r0_3(glval<bool>) = VariableAddress[b] :
# 1028| m0_4(bool) = InitializeParameter[b] : r0_3
# 1029| r0_5(glval<bool>) = VariableAddress[b] :
# 1029| r0_6(bool) = Load : r0_5, m0_4
# 1029| v0_7(void) = ConditionalBranch : r0_6
#-----| False -> Block 5
#-----| True -> Block 2
# 1028| Block 1
# 1028| m1_0(int) = Phi : from 3:m3_2, from 4:m4_2, from 6:m6_2, from 7:m7_2
# 1028| r1_1(glval<int>) = VariableAddress[#return] :
# 1028| v1_2(void) = ReturnValue : r1_1, m1_0
# 1028| v1_3(void) = UnmodeledUse : mu*
# 1028| v1_4(void) = ExitFunction :
# 1030| Block 2
# 1030| r2_0(bool) = Constant[0] :
# 1030| v2_1(void) = ConditionalBranch : r2_0
#-----| False -> Block 4
#-----| True -> Block 3
# 1031| Block 3
# 1031| r3_0(glval<int>) = VariableAddress[#return] :
# 1031| r3_1(int) = Constant[1] :
# 1031| m3_2(int) = Store : r3_0, r3_1
#-----| Goto -> Block 1
# 1034| Block 4
# 1034| r4_0(glval<int>) = VariableAddress[#return] :
# 1034| r4_1(int) = Constant[0] :
# 1034| m4_2(int) = Store : r4_0, r4_1
#-----| Goto -> Block 1
# 1038| Block 5
# 1038| r5_0(bool) = Constant[1] :
# 1038| v5_1(void) = ConditionalBranch : r5_0
#-----| False -> Block 7
#-----| True -> Block 6
# 1039| Block 6
# 1039| r6_0(glval<int>) = VariableAddress[#return] :
# 1039| r6_1(int) = Constant[0] :
# 1039| m6_2(int) = Store : r6_0, r6_1
#-----| Goto -> Block 1
# 1042| Block 7
# 1042| r7_0(glval<int>) = VariableAddress[#return] :
# 1042| r7_1(int) = Constant[1] :
# 1042| m7_2(int) = Store : r7_0, r7_1
#-----| Goto -> Block 1

Просмотреть файл

@ -1018,4 +1018,30 @@ int ChiPhiNode(Point *p, bool which1, bool which2) {
return p->x + p->y;
}
int UnreachableViaGoto() {
goto skip;
return 1;
skip:
return 0;
}
int UnreachableIf(bool b) {
if (b) {
if (false) {
return 1;
}
else {
return 0;
}
}
else {
if (true) {
return 0;
}
else {
return 1;
}
}
}
// semmle-extractor-options: -std=c++17

Просмотреть файл

@ -4420,3 +4420,82 @@ ir.cpp:
# 1005| v6_12(void) = ReturnValue : r6_11, mu0_2
# 1005| v6_13(void) = UnmodeledUse : mu*
# 1005| v6_14(void) = ExitFunction :
# 1021| UnreachableViaGoto() -> int
# 1021| Block 0
# 1021| v0_0(void) = EnterFunction :
# 1021| mu0_1(unknown) = AliasedDefinition :
# 1021| mu0_2(unknown) = UnmodeledDefinition :
# 1022| v0_3(void) = NoOp :
# 1024| v0_4(void) = NoOp :
# 1025| r0_5(glval<int>) = VariableAddress[#return] :
# 1025| r0_6(int) = Constant[0] :
# 1025| mu0_7(int) = Store : r0_5, r0_6
#-----| Goto -> Block 1
# 1021| Block 1
# 1021| r1_0(glval<int>) = VariableAddress[#return] :
# 1021| v1_1(void) = ReturnValue : r1_0, mu0_2
# 1021| v1_2(void) = UnmodeledUse : mu*
# 1021| v1_3(void) = ExitFunction :
# 1023| Block 2
# 1023| r2_0(glval<int>) = VariableAddress[#return] :
# 1023| r2_1(int) = Constant[1] :
# 1023| mu2_2(int) = Store : r2_0, r2_1
#-----| Goto -> Block 1
# 1028| UnreachableIf(bool) -> int
# 1028| Block 0
# 1028| v0_0(void) = EnterFunction :
# 1028| mu0_1(unknown) = AliasedDefinition :
# 1028| mu0_2(unknown) = UnmodeledDefinition :
# 1028| r0_3(glval<bool>) = VariableAddress[b] :
# 1028| mu0_4(bool) = InitializeParameter[b] : r0_3
# 1029| r0_5(glval<bool>) = VariableAddress[b] :
# 1029| r0_6(bool) = Load : r0_5, mu0_2
# 1029| v0_7(void) = ConditionalBranch : r0_6
#-----| False -> Block 5
#-----| True -> Block 2
# 1028| Block 1
# 1028| r1_0(glval<int>) = VariableAddress[#return] :
# 1028| v1_1(void) = ReturnValue : r1_0, mu0_2
# 1028| v1_2(void) = UnmodeledUse : mu*
# 1028| v1_3(void) = ExitFunction :
# 1030| Block 2
# 1030| r2_0(bool) = Constant[0] :
# 1030| v2_1(void) = ConditionalBranch : r2_0
#-----| False -> Block 4
#-----| True -> Block 3
# 1031| Block 3
# 1031| r3_0(glval<int>) = VariableAddress[#return] :
# 1031| r3_1(int) = Constant[1] :
# 1031| mu3_2(int) = Store : r3_0, r3_1
#-----| Goto -> Block 1
# 1034| Block 4
# 1034| r4_0(glval<int>) = VariableAddress[#return] :
# 1034| r4_1(int) = Constant[0] :
# 1034| mu4_2(int) = Store : r4_0, r4_1
#-----| Goto -> Block 1
# 1038| Block 5
# 1038| r5_0(bool) = Constant[1] :
# 1038| v5_1(void) = ConditionalBranch : r5_0
#-----| False -> Block 7
#-----| True -> Block 6
# 1039| Block 6
# 1039| r6_0(glval<int>) = VariableAddress[#return] :
# 1039| r6_1(int) = Constant[0] :
# 1039| mu6_2(int) = Store : r6_0, r6_1
#-----| Goto -> Block 1
# 1042| Block 7
# 1042| r7_0(glval<int>) = VariableAddress[#return] :
# 1042| r7_1(int) = Constant[1] :
# 1042| mu7_2(int) = Store : r7_0, r7_1
#-----| Goto -> Block 1

Просмотреть файл

@ -93,6 +93,8 @@
| IR: TryCatch | 15 |
| IR: UninitializedVariables | 1 |
| IR: UnionInit | 1 |
| IR: UnreachableIf | 8 |
| IR: UnreachableViaGoto | 3 |
| IR: VarArgUsage | 1 |
| IR: VarArgs | 1 |
| IR: VirtualMemberFunction | 1 |

Просмотреть файл

@ -4441,3 +4441,84 @@ ir.cpp:
# 1005| v6_12(void) = ReturnValue : r6_11, m6_10
# 1005| v6_13(void) = UnmodeledUse : mu*
# 1005| v6_14(void) = ExitFunction :
# 1021| UnreachableViaGoto() -> int
# 1021| Block 0
# 1021| v0_0(void) = EnterFunction :
# 1021| mu0_1(unknown) = AliasedDefinition :
# 1021| mu0_2(unknown) = UnmodeledDefinition :
# 1022| v0_3(void) = NoOp :
# 1024| v0_4(void) = NoOp :
# 1025| r0_5(glval<int>) = VariableAddress[#return] :
# 1025| r0_6(int) = Constant[0] :
# 1025| m0_7(int) = Store : r0_5, r0_6
#-----| Goto -> Block 1
# 1021| Block 1
# 1021| m1_0(int) = Phi : from 0:m0_7, from 2:m2_2
# 1021| r1_1(glval<int>) = VariableAddress[#return] :
# 1021| v1_2(void) = ReturnValue : r1_1, m1_0
# 1021| v1_3(void) = UnmodeledUse : mu*
# 1021| v1_4(void) = ExitFunction :
# 1023| Block 2
# 1023| r2_0(glval<int>) = VariableAddress[#return] :
# 1023| r2_1(int) = Constant[1] :
# 1023| m2_2(int) = Store : r2_0, r2_1
#-----| Goto -> Block 1
# 1028| UnreachableIf(bool) -> int
# 1028| Block 0
# 1028| v0_0(void) = EnterFunction :
# 1028| mu0_1(unknown) = AliasedDefinition :
# 1028| mu0_2(unknown) = UnmodeledDefinition :
# 1028| r0_3(glval<bool>) = VariableAddress[b] :
# 1028| m0_4(bool) = InitializeParameter[b] : r0_3
# 1029| r0_5(glval<bool>) = VariableAddress[b] :
# 1029| r0_6(bool) = Load : r0_5, m0_4
# 1029| v0_7(void) = ConditionalBranch : r0_6
#-----| False -> Block 5
#-----| True -> Block 2
# 1028| Block 1
# 1028| m1_0(int) = Phi : from 3:m3_2, from 4:m4_2, from 6:m6_2, from 7:m7_2
# 1028| r1_1(glval<int>) = VariableAddress[#return] :
# 1028| v1_2(void) = ReturnValue : r1_1, m1_0
# 1028| v1_3(void) = UnmodeledUse : mu*
# 1028| v1_4(void) = ExitFunction :
# 1030| Block 2
# 1030| r2_0(bool) = Constant[0] :
# 1030| v2_1(void) = ConditionalBranch : r2_0
#-----| False -> Block 4
#-----| True -> Block 3
# 1031| Block 3
# 1031| r3_0(glval<int>) = VariableAddress[#return] :
# 1031| r3_1(int) = Constant[1] :
# 1031| m3_2(int) = Store : r3_0, r3_1
#-----| Goto -> Block 1
# 1034| Block 4
# 1034| r4_0(glval<int>) = VariableAddress[#return] :
# 1034| r4_1(int) = Constant[0] :
# 1034| m4_2(int) = Store : r4_0, r4_1
#-----| Goto -> Block 1
# 1038| Block 5
# 1038| r5_0(bool) = Constant[1] :
# 1038| v5_1(void) = ConditionalBranch : r5_0
#-----| False -> Block 7
#-----| True -> Block 6
# 1039| Block 6
# 1039| r6_0(glval<int>) = VariableAddress[#return] :
# 1039| r6_1(int) = Constant[0] :
# 1039| m6_2(int) = Store : r6_0, r6_1
#-----| Goto -> Block 1
# 1042| Block 7
# 1042| r7_0(glval<int>) = VariableAddress[#return] :
# 1042| r7_1(int) = Constant[1] :
# 1042| m7_2(int) = Store : r7_0, r7_1
#-----| Goto -> Block 1