Debian Codegraph @

gcc/testsuite/go.test/test/fixedbugs/issue24187.go

raw
1 // +build amd64p32
2 // run
3
4 // Copyright 2018 The Go Authors. All rights reserved.
5 // Use of this source code is governed by a BSD-style
6 // license that can be found in the LICENSE file.
7
8 package main
9
10 import (
11 "bytes"
12 "fmt"
13 "unsafe"
14 )
15
16 func main() {
17 b := make([]byte, 128)
18 for i := range b {
19 b[i] = 1
20 }
21 if bytes.IndexByte(b, 0) != -1 {
22 panic("found 0")
23 }
24 for i := range b {
25 b[i] = 0
26 c := b
27 *(*int)(unsafe.Pointer(uintptr(unsafe.Pointer(&c)) + unsafe.Sizeof(uintptr(0)))) = 1<<31 - 1
28 if bytes.IndexByte(c, 0) != i {
29 panic(fmt.Sprintf("missing 0 at %d\n", i))
30 }
31 b[i] = 1
32 }
33 }