Skip to content

cmd/compile: 1-sized array's pointer typed element set to nil, after received from channel and print in a loop #22683

@helinwang

Description

@helinwang

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

go version go1.9.2 linux/amd64

Does this issue reproduce with the latest release?

Yes

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/helin/env/gopath"
GORACE=""
GOROOT="/home/helin/env/go"
GOTOOLDIR="/home/helin/env/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build809756853=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
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"
)

const arraySize = 1

// comment above and uncomment below, will work as expected.
// const arraySize = 2

type foo struct {
	bar [arraySize]*int
}

func main() {
	ch := make(chan foo, 2)
	var a int
	var b [arraySize]*int
	b[0] = &a
	ch <- foo{bar: b}
	close(ch)

	for v := range ch {
		// uncomment below, will work as expected.
		// fmt.Println(v.bar[0])
		for i := 0; i < 1; i++ {
			fmt.Println(v.bar[0], b[0])
		}
	}
}

What did you expect to see?

// Output:
// 0x10410020 0x10410020

What did you see instead?

// Output:
// <nil> 0x10410020

Playground link:

https://play.golang.org/p/Qd8fDy-ls3

Metadata

Metadata

Assignees

No one assigned

    Labels

    CherryPickApprovedUsed during the release process for point releasesFrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions