Skip to content

cmd/compile: optimized range memclr doesn't work with pointers to arrays #52635

@josharian

Description

@josharian
package p

type T struct {
	a *[10]int
	b [10]int
}

func (t *T) resetA() {
	for i := range t.a {
		t.a[i] = 0
	}
}

func (t *T) resetB() {
	for i := range t.b {
		t.b[i] = 0
	}
}

resetA compiles to a loop. resetB compiles to a call to runtime.memclrNoHeapPointers. I believe that resetA should also call memclrNoHeapPointers.

This showed up as a hot spot in my code today (with much larger arrays).

cc @randall77 @cuonglm @mdempsky

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