1// compile
2
3// Copyright 2020 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// Check to make sure we don't try to constant fold a divide by zero.
8// This is a tricky test, as we need a value that's not recognized as 0
9// until lowering (otherwise it gets handled in a different path).
10
11package p
12
13func f() {
14	var i int
15	var s string
16	for i > 0 {
17		_ = s[0]
18		i++
19	}
20
21	var c chan int
22	c <- 1 % i
23}
24
25func f32() uint32 {
26	s := "\x00\x00\x00\x00"
27	c := uint32(s[0]) | uint32(s[1])<<8 | uint32(s[2])<<16 | uint32(s[3])<<24
28	return 1 / c
29}
30func f64() uint64 {
31	s := "\x00\x00\x00\x00\x00\x00\x00\x00"
32	c := uint64(s[0]) | uint64(s[1])<<8 | uint64(s[2])<<16 | uint64(s[3])<<24 | uint64(s[4])<<32 | uint64(s[5])<<40 | uint64(s[6])<<48 | uint64(s[7])<<56
33	return 1 / c
34}
35