]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: error if register is reused when setting edge state
authorMichael Munday <mike.munday@ibm.com>
Tue, 14 Apr 2020 09:12:32 +0000 (10:12 +0100)
committerMichael Munday <mike.munday@ibm.com>
Tue, 14 Apr 2020 19:04:38 +0000 (19:04 +0000)
When setting the edge state in register allocation we should only
be setting each register once. It is not possible for a register
to hold multiple values at once.

This CL converts the runtime error seen in #38195 into an internal
compiler error (ICE). It is better for the compiler to fail than
generate an incorrect program.

The bug reported in #38195 is now exposed as:

./parserc.go:459:11: internal compiler error: 'yaml_parser_parse_node': R5 is already set (v1074/v1241)

[stack trace]

Updates #38195.

Change-Id: Id95842fd850b95494cbd472b6fd5a55513ecacec
Reviewed-on: https://go-review.googlesource.com/c/go/+/228060
Run-TryBot: Michael Munday <mike.munday@ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/ssa/regalloc.go

index 95e732d744e1a46b3a6dbca58e71958af0a5ede2..a2be7bb596279e191abdd01ba647d317697e3683 100644 (file)
@@ -2164,6 +2164,9 @@ func (e *edgeState) set(loc Location, vid ID, c *Value, final bool, pos src.XPos
        a = append(a, c)
        e.cache[vid] = a
        if r, ok := loc.(*Register); ok {
+               if e.usedRegs&(regMask(1)<<uint(r.num)) != 0 {
+                       e.s.f.Fatalf("%v is already set (v%d/%v)", r, vid, c)
+               }
                e.usedRegs |= regMask(1) << uint(r.num)
                if final {
                        e.finalRegs |= regMask(1) << uint(r.num)