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

Skip to content

Commit c5f38ee

Browse files
committed
C++: Fix IR generation and accept output
1 parent 051d574 commit c5f38ee

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/internal/TranslatedStmt.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,10 @@ class TranslatedSwitchStmt extends TranslatedStmt {
655655
kind = getCaseEdge(switchCase) and
656656
result = getTranslatedStmt(switchCase).getFirstInstruction()
657657
)
658+
or
659+
not stmt.hasDefaultCase() and
660+
kind instanceof GotoEdge and
661+
result = getParent().getChildSuccessor(this)
658662
}
659663

660664
override Instruction getChildSuccessor(TranslatedElement child) {

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6067,12 +6067,16 @@ ir.cpp:
60676067
# 1175| r1175_2(int) = Load : &:r1175_1, ~mu1173_4
60686068
# 1175| v1175_3(void) = Switch : r1175_2
60696069
#-----| Case[1] -> Block 1
6070+
#-----| Goto -> Block 2
60706071

60716072
# 1176| Block 1
60726073
# 1176| v1176_1(void) = NoOp :
60736074
# 1177| r1177_1(int) = Constant[2] :
60746075
# 1177| r1177_2(glval<int>) = VariableAddress[y] :
60756076
# 1177| mu1177_3(int) = Store : &:r1177_2, r1177_1
6077+
#-----| Goto -> Block 2
6078+
6079+
# 1179| Block 2
60766080
# 1179| r1179_1(glval<int>) = VariableAddress[z] :
60776081
# 1179| r1179_2(glval<int>) = VariableAddress[y] :
60786082
# 1179| r1179_3(int) = Load : &:r1179_2, ~mu1173_4
@@ -6099,6 +6103,7 @@ ir.cpp:
60996103
# 1184| v1184_3(void) = Switch : r1184_2
61006104
#-----| Case[1] -> Block 1
61016105
#-----| Case[2] -> Block 2
6106+
#-----| Goto -> Block 3
61026107

61036108
# 1185| Block 1
61046109
# 1185| v1185_1(void) = NoOp :
@@ -6112,6 +6117,9 @@ ir.cpp:
61126117
# 1188| r1188_1(int) = Constant[3] :
61136118
# 1188| r1188_2(glval<int>) = VariableAddress[y] :
61146119
# 1188| mu1188_3(int) = Store : &:r1188_2, r1188_1
6120+
#-----| Goto -> Block 3
6121+
6122+
# 1190| Block 3
61156123
# 1190| r1190_1(glval<int>) = VariableAddress[z] :
61166124
# 1190| r1190_2(glval<int>) = VariableAddress[y] :
61176125
# 1190| r1190_3(int) = Load : &:r1190_2, ~mu1182_4
@@ -6138,6 +6146,7 @@ ir.cpp:
61386146
# 1195| v1195_3(void) = Switch : r1195_2
61396147
#-----| Case[1] -> Block 1
61406148
#-----| Case[2] -> Block 2
6149+
#-----| Goto -> Block 3
61416150

61426151
# 1196| Block 1
61436152
# 1196| v1196_1(void) = NoOp :

0 commit comments

Comments
 (0)