Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: bogus "fallthrough statement out of place" #13262

Closed
dvyukov opened this issue Nov 16, 2015 · 4 comments
Closed

cmd/compile: bogus "fallthrough statement out of place" #13262

dvyukov opened this issue Nov 16, 2015 · 4 comments

Comments

@dvyukov
Copy link
Member

dvyukov commented Nov 16, 2015

cmd/compile fails to compile the following program:

package p

func f() int {
    switch 0 {
    case 0:
        return (int)(""[((func() int)(nil))()])
        fallthrough
    default:
    }
    return 0
}
2.go:7: fallthrough statement out of place

gotype eats it.

go version devel +25a28da Sun Nov 15 23:41:28 2015 +0000 linux/amd64

Found with GoSmith (https://github.com/dvyukov/gosmith).

@ianlancetaylor ianlancetaylor added this to the Go1.6 milestone Nov 16, 2015
@griesemer
Copy link
Contributor

This is a bug with both the existing and the new parser.

@griesemer
Copy link
Contributor

Slightly simpler case:

package p

func f() int {
    switch 0 {
    case 0:
        return (func() int)(nil)()
        fallthrough
    default:
    }
    return 0
}

@rsc rsc modified the milestones: Go1.7, Go1.6 Dec 5, 2015
@gopherbot
Copy link

CL https://golang.org/cl/22921 mentions this issue.

@mdempsky mdempsky modified the milestones: Go1.8Early, Go1.7 May 7, 2016
@ALTree
Copy link
Member

ALTree commented May 8, 2016

Simpler reproducer for posterity in case the patch I mailed won't be merged

package p

func f() int {
    var a int
    switch a {
    case 0:
        return func() int { return 1 }()
        fallthrough
    default:
    }
    return 0
}

anything that creates an autotmp_ in the return line goes. gc compiles

case 0:
        return func() int { return 1 }()
        fallthrough

as

autotmp_0 = (func literal)(); return autotmp_0; fallthrough; <node VARKILL>

The problem is that the casebody function in swt.go, which replaces Op in OXFALL nodes (not-yet-processed fallthrough) with OFALL (processed fallthrough), assumes that the node with the fallthrough statement will always be the last one. In this case, this is false: the last node is the OVARKILL one. For this reason the OXFALL node won't be marked as OFALL, and the fallthrough on the second line ends up being reported as spurious.

@golang golang locked and limited conversation to collaborators Sep 26, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants