modernc.org/gc@v1.0.1-0.20240304020402-f0dba7c97c2b/testdata/errchk/test/fixedbugs/issue8325.go (about)

     1  // run
     2  
     3  // Copyright 2014 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  // Issue 8325: corrupted byte operations during optimization
     8  // pass.
     9  
    10  package main
    11  
    12  const alphanum = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    13  
    14  func main() {
    15  	var bytes = []byte{10, 20, 30, 40, 50}
    16  
    17  	for i, b := range bytes {
    18  		bytes[i] = alphanum[b%byte(len(alphanum))]
    19  	}
    20  
    21  	for _, b := range bytes {
    22  		switch {
    23  		case '0' <= b && b <= '9',
    24  			'A' <= b && b <= 'Z':
    25  		default:
    26  			println("found a bad character", string(b))
    27  			panic("BUG")
    28  		}
    29  
    30  	}
    31  }