Skip to content

gccgo: runtime panic with slice trick "delete" #23433

Closed
@quasilyte

Description

@quasilyte
$ go version 
go version go1.8.1 linux/amd64

$ gccgo --version
gccgo (GCC) 7.2.0

Given the code slice_delete.go:

package main

import "fmt"

func main() {
    xs := []int{0,1,2,3,4}
    i := 2
    xs, xs[len(xs)-1] = append(xs[:i], xs[i+1:]...), 0
    fmt.Println(xs)
}

Run with 6g/GC:

$ go run slice_delete.go
[0 1 3 4]

Run with GCCGO:

$ go run -compiler gccgo slice_delete.go
panic: runtime error: index out of range

goroutine 16 [running]:
runtime.gopanic
	../../../src/libgo/go/runtime/panic.go:493
runtime_panicstring
	../../../src/libgo/runtime/panic.c:34
main.main
	/home/quasilyte/CODE/go/gccgo/slice_delete.go:8
runtime_main
	../../../src/libgo/runtime/proc.c:606
exit status 2

Also reproducible in this way:

$ gccgo slice_delete.go -o bin && ./bin

Found on stack overflow: delete-element-from-slice-difference-gccgo-vs-gc.

Most likely evaluation order mismatches here.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions