mirror of
https://github.com/golang/go
synced 2024-11-24 10:30:10 -07:00
053840dc00
The assembler barfs on large offsets. Make sure that all the instructions that need to have their offsets in an int32 1) check on any rule that computes offsets for such instructions 2) change their aux fields so the check builder checks it. The assembler also silently misassembled offsets between 1<<31 and 1<<32. Add a check in the assembler to barf on those as well. Fixes #21655 Change-Id: Iebf24bf10f9f37b3ea819ceb7d588251c0f46d7d Reviewed-on: https://go-review.googlesource.com/59630 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
// compile
|
|
|
|
// Copyright 2017 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.
|
|
|
|
// Make sure assembly offsets don't get too large.
|
|
|
|
// To trigger issue21655, the index offset needs to be small
|
|
// enough to fit into an int32 (to get rewritten to an ADDQconst)
|
|
// but large enough to overflow an int32 after multiplying by the stride.
|
|
|
|
package main
|
|
|
|
func f1(a []int64, i int64) int64 {
|
|
return a[i+1<<30]
|
|
}
|
|
func f2(a []int32, i int64) int32 {
|
|
return a[i+1<<30]
|
|
}
|
|
func f3(a []int16, i int64) int16 {
|
|
return a[i+1<<30]
|
|
}
|
|
func f4(a []int8, i int64) int8 {
|
|
return a[i+1<<31]
|
|
}
|
|
func f5(a []float64, i int64) float64 {
|
|
return a[i+1<<30]
|
|
}
|
|
func f6(a []float32, i int64) float32 {
|
|
return a[i+1<<30]
|
|
}
|
|
|
|
// Note: Before the fix for issue 21655, f{1,2,5,6} made
|
|
// the compiler crash. f3 silently generated the wrong
|
|
// code, using an offset of -1<<31 instead of 1<<31.
|
|
// (This is due to the assembler accepting offsets
|
|
// like 0x80000000 and silently using them as
|
|
// signed 32 bit offsets.)
|
|
// f4 was ok, but testing it can't hurt.
|