Source file test/fixedbugs/issue45242.go

     1  // run
     2  
     3  // Copyright 2021 The Go Authors. All rights reserved.
     4  // Use of this source code is governed by a BSD-style
     5  // license that can be found in the LICENSE file.
     6  
     7  package main
     8  
     9  import "fmt"
    10  
    11  //go:noinline
    12  func repro(b []byte, bit int32) {
    13  	_ = b[3]
    14  	v := uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24 | 1<<(bit&31)
    15  	b[0] = byte(v)
    16  	b[1] = byte(v >> 8)
    17  	b[2] = byte(v >> 16)
    18  	b[3] = byte(v >> 24)
    19  }
    20  
    21  func main() {
    22  	var b [8]byte
    23  	repro(b[:], 32)
    24  	want := [8]byte{1, 0, 0, 0, 0, 0, 0, 0}
    25  	if b != want {
    26  		panic(fmt.Sprintf("got %v, want %v\n", b, want))
    27  	}
    28  }
    29  

View as plain text