Skip to content

cmd/compile: stores in infinite loops disappear #15635

@randall77

Description

@randall77
func f(p *int) {
    _ = *p // nil check
    for i := 0; true; i++ {
        *p = i
    }
}

With SSA, this compiles to:

    0x0000 00000 (infloop.go:4) MOVQ    "".p+8(FP), AX
    0x0005 00005 (infloop.go:4) TESTB   AL, (AX)
    0x0007 00007 (infloop.go:5) JMP 7

There are no reads of memory in the loop, so the entire store chain gets optimized away.

Is this a problem? I'm not sure. It is unexpected (at least, to me) so it may be worth fixing. Opinions? @rsc @josharian @griesemer @mdempsky @dr2chase @ianlancetaylor

This issue may prevent the optimization described in #15631 (treating calls just like stores). We definitely don't want calls vanishing.

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