-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Closed
Labels
Milestone
Description
When I run this program (reduced from a file generated by test/index.go) package main var aib [100000]int var paib *[100000]int = &aib var i64 int64 = 100023 func main() { _ = paib[i64] } with GOARCH=amd64 I get panic: runtime error: index out of range goroutine 1 [running]: main.main() /home/iant/foo3.go:8 +0x3c goroutine 2 [syscall]: created by runtime.main /home/iant/go2/src/pkg/runtime/proc.c:225 exit status 2 When I run it with GOARCH=386 I get unexpected fault address 0x186b7 throw: fault [signal 0xb code=0x1 addr=0x186b7 pc=0x8048c3d] goroutine 1 [running]: main.main() /home/iant/foo3.go:8 +0x3d goroutine 2 [syscall]: created by runtime.main /home/iant/go2/src/pkg/runtime/proc.c:225 exit status 2 The GOARCH=amd64 panic is correct: this is an "index out of range." It is not an "unexpected fault address." The generated code with GOARCH=386 is --- prog list "main" --- 0000 (/home/iant/foo3.go:7) TEXT main+0(SB),$0-0 0001 (/home/iant/foo3.go:8) MOVL paib+0(SB),BX 0002 (/home/iant/foo3.go:8) MOVL i64+0(SB),BX 0003 (/home/iant/foo3.go:8) MOVL i64+4(SB),DX 0004 (/home/iant/foo3.go:8) MOVL DX,CX 0005 (/home/iant/foo3.go:8) MOVL BX,AX 0006 (/home/iant/foo3.go:8) CMPL DX,$0 0007 (/home/iant/foo3.go:8) JNE $1,13 0008 (/home/iant/foo3.go:8) MOVL BX,BP 0009 (/home/iant/foo3.go:8) LEAL (BX),SI 0010 (/home/iant/foo3.go:8) TESTB $0,(SI) 0011 (/home/iant/foo3.go:8) CMPL BP,$100000 0012 (/home/iant/foo3.go:8) JCS $1,15 0013 (/home/iant/foo3.go:8) CALL ,runtime.panicindex+0(SB) 0014 (/home/iant/foo3.go:8) UNDEF , 0015 (/home/iant/foo3.go:8) LEAL (SI)(BP*4),SI 0016 (/home/iant/foo3.go:8) MOVL (SI),AX 0017 (/home/iant/foo3.go:9) RET , The problem occurs at the start: the value of paib is loaded into bx (0002). Then the low-order 32-bit of i64 is loaded into bx (0003). Then we load the contents of bx into si (0009). That instruction expects bx to hold paib, but instead it holds the low-order 32 bits of i64.