Skip to content

cmd/compile: strings only partially overwritten on arm64 #75365

@randall77

Description

@randall77
package main

import (
	"fmt"
	"unsafe"
)

type S struct {
	p *byte
	a string
	b string
	c int64
	d int64
}

func main() {
	s := &S{p: nil, a: "foo", b: "foo", c: 0, d: 0}
	s.a = ""
	s.b = "bar"
	s.c = 33

	z := (*[2]uintptr)(unsafe.Pointer(&s.a))
	fmt.Printf("%x %x\n", z[0], z[1])
}

This prints 0 3 at tip, which is bad. That shows there is a string with a nil pointer but a nonzero length. Something is wrong with how stores are resolved when there are multiple stores to the same location (in this case, one in the struct literal, one explicit). At s.a = "", the store of s.a.ptr = nil is happening but the store of s.a.len = 0 is not.

I think this starts with CL 698097. I will revert that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.NeedsFixThe path to resolution is known, but the work has not been done.compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions