File: issue21655.go

package info (click to toggle)
gcc-arm-none-eabi 15%3A14.2.rel1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,099,328 kB
  • sloc: cpp: 3,627,108; ansic: 2,571,498; ada: 834,230; f90: 235,082; makefile: 79,231; asm: 74,984; xml: 51,692; exp: 39,736; sh: 33,298; objc: 15,629; python: 15,069; fortran: 14,429; pascal: 7,003; awk: 5,070; perl: 3,106; ml: 285; lisp: 253; lex: 204; haskell: 135
file content (62 lines) | stat: -rw-r--r-- 1,520 bytes parent folder | download | duplicates (34)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// 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.

func f7(ss []*string, i int) string {
	const offset = 3 << 29 // 3<<29 * 4 = 3<<31 = 1<<31 mod 1<<32.
	if i > offset {
		return *ss[i-offset]
	}
	return ""
}
func f8(ss []*string, i int) string {
	const offset = 3<<29 + 10
	if i > offset {
		return *ss[i-offset]
	}
	return ""
}
func f9(ss []*string, i int) string {
	const offset = 3<<29 - 10
	if i > offset {
		return *ss[i-offset]
	}
	return ""
}