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: bogus warning "control reaches end of non-void function" #22767

Closed
xry111 opened this issue Nov 16, 2017 · 4 comments
Closed

gccgo: bogus warning "control reaches end of non-void function" #22767

xry111 opened this issue Nov 16, 2017 · 4 comments
Milestone

Comments

@xry111
Copy link

xry111 commented Nov 16, 2017

What version of Go are you using (go version)?

go version go1.9 gccgo (GCC) 8.0.0 20171114 (experimental) linux/amd64

Does this issue reproduce with the latest release?

Yes. This is gccgo in gcc trunk.

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/xry111/go"
GORACE=""
GOROOT="/opt/go"
GOTOOLDIR="/usr/lib64/gcc/x86_64-pc-linux-gnu/8.0.0"
GCCGO="/usr/bin/gccgo-8.0"
CC="gcc-8.0"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build037067240=/tmp/go-build -gno-record-gcc-switches -funwind-tables"
CXX="g++-8.0"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

package main

import (
	"fmt"
	"os"
)

func foo() int {
	switch os.Args[0] {
	case "cat":
		return 0
	case "ls":
		return 1
	}
	panic("wtf")
}

func main() {
	fmt.Println(foo())
}

And build it with LC_ALL=C go-8.0 build.

What did you expect to see?

No warnings and no errors.

What did you see instead?

# hw
./main.go: In function 'main.foo':
go1: warning: control reaches end of non-void function [-Wreturn-type]

I think panic() should have something like __attribute__((noreturn)) in GNU C, to suppress the warning.

@gopherbot gopherbot added this to the Gccgo milestone Nov 16, 2017
@xry111
Copy link
Author

xry111 commented Nov 16, 2017

By the way, this bogus warning spamed my terminal while GCC building system was compiling Go standard library with newly built gccgo. And even

func foo(x int) int {
    panic("not implemented")
}

could trigger this.

@xry111
Copy link
Author

xry111 commented Nov 16, 2017

With -gccgoflags "-O" the warning gone.

@ianlancetaylor
Copy link
Contributor

Thanks, I have seen this too. Seems to be an annoying change in the GCC middle-end. Since the Go frontend provides its own "missing return" warning anyhow, the simplest approach may be for the frontend to disable the middle-end warning.

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/80416 mentions this issue: compiler: avoid GCC middle-end control warnings

hubot pushed a commit to gcc-mirror/gcc that referenced this issue Dec 2, 2017
    
    GCC has started emitting "control reaches end of non-void function"
    warnings. Avoid them for Go by 1) marking the builtin function panic
    and the compiler-generated function __go_runtime_error as not
    returning and 2) adding a default case to the switch used for select
    statements that simply calls __builtin_unreachable.
    
    Fixes golang/go#22767
    
    Reviewed-on: https://go-review.googlesource.com/80416

	* go-gcc.cc (Gcc_backend::Gcc_backend): Define
	__builtin_unreachable.
	(Gcc_backend::function): Add does_not_return parameter.


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@255346 138bc75d-0d04-0410-961f-82ee72b054a4
@golang golang locked and limited conversation to collaborators Dec 2, 2018
asiekierka pushed a commit to WonderfulToolchain/gcc-ia16 that referenced this issue May 16, 2022
    
    GCC has started emitting "control reaches end of non-void function"
    warnings. Avoid them for Go by 1) marking the builtin function panic
    and the compiler-generated function __go_runtime_error as not
    returning and 2) adding a default case to the switch used for select
    statements that simply calls __builtin_unreachable.
    
    Fixes golang/go#22767
    
    Reviewed-on: https://go-review.googlesource.com/80416

	* go-gcc.cc (Gcc_backend::Gcc_backend): Define
	__builtin_unreachable.
	(Gcc_backend::function): Add does_not_return parameter.

From-SVN: r255346
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

3 participants