Skip to content

Commit

Permalink
Fix goto SW_GENERATED_LABEL_x jumps over declaration of variable
Browse files Browse the repository at this point in the history
  • Loading branch information
kamphaus authored and christophe-kamphaus-jemmic committed May 14, 2018
1 parent c53eb6b commit 5b59f0a
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion tests/code_quality/for.expected.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Package main - transpiled by c2go version: v0.22.4 Aluminium 2018-04-24
Package main - transpiled by c2go version: v0.23.0 Berkelium 2018-04-27
If you have found any issues, please raise an issue at:
https://github.com/elliotchance/c2go/
Expand Down
2 changes: 1 addition & 1 deletion tests/code_quality/if.expected.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Package main - transpiled by c2go version: v0.22.4 Aluminium 2018-04-24
Package main - transpiled by c2go version: v0.23.0 Berkelium 2018-04-27
If you have found any issues, please raise an issue at:
https://github.com/elliotchance/c2go/
Expand Down
2 changes: 1 addition & 1 deletion tests/code_quality/operators.expected.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Package main - transpiled by c2go version: v0.22.4 Aluminium 2018-04-24
Package main - transpiled by c2go version: v0.23.0 Berkelium 2018-04-27
If you have found any issues, please raise an issue at:
https://github.com/elliotchance/c2go/
Expand Down
6 changes: 5 additions & 1 deletion tests/code_quality/switch.expected.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Package main - transpiled by c2go version: v0.22.4 Aluminium 2018-04-24
Package main - transpiled by c2go version: v0.23.0 Berkelium 2018-04-27
If you have found any issues, please raise an issue at:
https://github.com/elliotchance/c2go/
Expand Down Expand Up @@ -28,7 +28,11 @@ func switch_function() {
return
}
case int32(4):
{
}
case int32(5):
{
}
case int32(6):
fallthrough
case int32(7):
Expand Down
7 changes: 5 additions & 2 deletions tests/switch.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ void scoped_fallthrough_several_midway_default()
}
}


void scoped_goto_label(bool use_goto)
{
for (;;) {
Expand Down Expand Up @@ -352,7 +351,11 @@ void scoped_goto_label(bool use_goto)
break;
}
case 2:
{}
{
int x = 0;
printf("%d", x);
break;
}
LABELX: {}
default:
{
Expand Down
3 changes: 2 additions & 1 deletion transpiler/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ func transpileSwitchStmt(n *ast.SwitchStmt, p *program.Program) (
if vv, ok := v.List[len(v.List)-1].(*goast.BranchStmt); ok {
if vv.Tok == token.BREAK {
if isFallThrough {
cs.Body = append(v.List[:len(v.List)-1])
v.List = v.List[:len(v.List)-1]
cs.Body = body[:len(body)-1]
continue
}
}
Expand Down

0 comments on commit 5b59f0a

Please sign in to comment.