Skip to content

compiler: dead code and labels cause compilation failure #66803

Closed
@Bios-Marcel

Description

@Bios-Marcel

Go version

go version go1.22.1 windows/amd64

Output of go env in your module/workspace:

set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\marce\AppData\Local\go-build
set GOENV=C:\Users\marce\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\marce\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\marce\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Users\marce\scoop\apps\go\current
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Users\marce\scoop\apps\go\current\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.22.1
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\Users\marce\code\spoon\compilerbug\go.mod
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\marce\AppData\Local\Temp\go-build2412120114=/tmp/go-build -gno-record-gcc-switches

What did you do?

I created the following main file:

package main

import (
	"fmt"
	"path/filepath"
)

func main() {
	fmt.Println("Start")
	call("")
	fmt.Println("End")
}

func call(parameter string) error {
	return nil

	ext := filepath.Join(parameter, "lol")
	if parameter != "" {
		goto LABEL
	}

LABEL:
	if ext != "" {
		fmt.Println("Label")
	}
	return nil
}

It contains unreachable code, but the compiler does not correctly interpret this and trips up instead.

What did you see happen?

PS C:\Users\marce\code\spoon\compilerbug> go run .
# bug
CLOSURE [C:\Users\marce\code\spoon\compilerbug\main.go:23:5:var ext string]
<unknown line number>: internal compiler error: assertion failed

Please file a bug report including a short program that triggers the error.
https://go.dev/issue/new

What did you expect to see?

Not an internal compiler error, but the normal behaviour.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions