]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/6g, cmd/8g: mark used registers in indirect addressing.
authorRémy Oudompheng <oudomphe@phare.normalesup.org>
Wed, 7 Nov 2012 20:36:15 +0000 (21:36 +0100)
committerRémy Oudompheng <oudomphe@phare.normalesup.org>
Wed, 7 Nov 2012 20:36:15 +0000 (21:36 +0100)
Fixes #4094.
Fixes #4353.

R=golang-dev, dave, rsc
CC=golang-dev
https://golang.org/cl/6810090

src/cmd/6g/reg.c
src/cmd/8g/reg.c
test/fixedbugs/issue4353.go [new file with mode: 0644]

index d45c024e7df0fbd7f4d7640c64d1a6b2a6908cf2..f9d0b11aecedb33d9c7294412db335dcd0951594 100644 (file)
@@ -247,6 +247,16 @@ regopt(Prog *firstp)
                        }
                }
 
+               // Addressing makes some registers used.
+               if(p->from.type >= D_INDIR)
+                       r->use1.b[0] |= RtoB(p->from.type-D_INDIR);
+               if(p->from.index != D_NONE)
+                       r->use1.b[0] |= RtoB(p->from.index);
+               if(p->to.type >= D_INDIR)
+                       r->use2.b[0] |= RtoB(p->to.type-D_INDIR);
+               if(p->to.index != D_NONE)
+                       r->use2.b[0] |= RtoB(p->to.index);
+
                bit = mkvar(r, &p->from);
                if(bany(&bit))
                switch(p->as) {
index e32fba6516a227b307e3e3cc012d97af95101e01..1e6178e7e81a02fc99951d3dfb61e7d48e809141 100644 (file)
@@ -212,6 +212,16 @@ regopt(Prog *firstp)
                        }
                }
 
+               // Addressing makes some registers used.
+               if(p->from.type >= D_INDIR)
+                       r->use1.b[0] |= RtoB(p->from.type-D_INDIR);
+               if(p->from.index != D_NONE)
+                       r->use1.b[0] |= RtoB(p->from.index);
+               if(p->to.type >= D_INDIR)
+                       r->use2.b[0] |= RtoB(p->to.type-D_INDIR);
+               if(p->to.index != D_NONE)
+                       r->use2.b[0] |= RtoB(p->to.index);
+
                bit = mkvar(r, &p->from);
                if(bany(&bit))
                switch(p->as) {
diff --git a/test/fixedbugs/issue4353.go b/test/fixedbugs/issue4353.go
new file mode 100644 (file)
index 0000000..defe7c3
--- /dev/null
@@ -0,0 +1,19 @@
+// run
+
+// Copyright 2012 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Issue 4353. An optimizer bug in 8g triggers a runtime fault
+// instead of an out of bounds panic.
+
+package main
+
+var aib [100000]int
+var paib *[100000]int = &aib
+var i64 int64 = 100023
+
+func main() {
+       defer func() { recover() }()
+       _ = paib[i64]
+}