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

gccgo: does not detect missing return #11591

Closed
dvyukov opened this issue Jul 4, 2015 · 6 comments
Closed

gccgo: does not detect missing return #11591

dvyukov opened this issue Jul 4, 2015 · 6 comments
Milestone

Comments

@dvyukov
Copy link
Member

dvyukov commented Jul 4, 2015

gccgo successfully compiles the following program:

package a
func f() int { for{}; _:}

while both gc and go/types reject it with missing return.
gcc version 6.0.0 2015070 (experimental) (GCC)

@dvyukov
Copy link
Member Author

dvyukov commented Jul 4, 2015

@griesemer

@ianlancetaylor ianlancetaylor added this to the Gccgo milestone Jul 10, 2015
@ianlancetaylor
Copy link
Contributor

CC @paranoiacblack

This is happening because Gogo::add_label_definition just returns if the label name is "_".

@paranoiacblack
Copy link
Contributor

Hmm, I'm missing some subtlety here. The reason why this program isn't rejected is because f is treated as if it were defined as func f() int { for{}; }. I agree that this does not have a return statement and an error should be returned. However, gc accepts the above simplification. Is the above program valid? If it is, why does it matter if we completely ignore sink labels?

@ianlancetaylor
Copy link
Contributor

The rule in the spec is that it's OK to omit a return statement if the last statement in the function is a terminating statement. "for{}" is a terminating statement--execution will never proceed past that point. "_:" is not a terminating statement--it's a label, and in principle somebody might goto that label, even though obviously that can't happen in this case.

Does that answer the question?

@griesemer
Copy link
Contributor

@paranoiacblack It's a "Labeled Statement" where the statement is the empty statement. So there's actually a non-terminating (empty statement) at the end.

@gopherbot
Copy link
Contributor

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

hubot pushed a commit to gcc-mirror/gcc that referenced this issue Jul 20, 2015
    
    Fixes golang/go#11591.
    
    Reviewed-on: https://go-review.googlesource.com/12043


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@226009 138bc75d-0d04-0410-961f-82ee72b054a4
@golang golang locked and limited conversation to collaborators Jul 20, 2016
asiekierka pushed a commit to WonderfulToolchain/gcc-ia16 that referenced this issue May 16, 2022
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

5 participants