Source file test/fixedbugs/issue43480.go

     1  // run
     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  // Issue #43480: ICE on large uint64 constants in switch cases.
     8  
     9  package main
    10  
    11  func isPow10(x uint64) bool {
    12  	switch x {
    13  	case 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9,
    14  		1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19:
    15  		return true
    16  	}
    17  	return false
    18  }
    19  
    20  func main() {
    21  	var x uint64 = 1
    22  
    23  	for {
    24  		if !isPow10(x) || isPow10(x-1) || isPow10(x+1) {
    25  			panic(x)
    26  		}
    27  		next := x * 10
    28  		if next/10 != x {
    29  			break // overflow
    30  		}
    31  		x = next
    32  	}
    33  }
    34  

View as plain text