Commit bead3586 authored by Than McIntosh's avatar Than McIntosh

math/bits: add gccgo-friendly code for compiler bootstrap

When building as part of the bootstrap process, avoid
use of "go:linkname" applied to variables, since this
feature is ill-defined/unsupported for gccgo.

Updates #30771.

Change-Id: Id44d01b5c98d292702e5075674117518cb59e2d0
Reviewed-on: https://go-review.googlesource.com/c/go/+/170737Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
Reviewed-by: default avatarCherry Zhang <cherryyz@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent cf8cc7f6
...@@ -8,8 +8,6 @@ ...@@ -8,8 +8,6 @@
// functions for the predeclared unsigned integer types. // functions for the predeclared unsigned integer types.
package bits package bits
import _ "unsafe" // for go:linkname
const uintSize = 32 << (^uint(0) >> 32 & 1) // 32 or 64 const uintSize = 32 << (^uint(0) >> 32 & 1) // 32 or 64
// UintSize is the size of a uint in bits. // UintSize is the size of a uint in bits.
...@@ -524,9 +522,3 @@ func Div64(hi, lo, y uint64) (quo, rem uint64) { ...@@ -524,9 +522,3 @@ func Div64(hi, lo, y uint64) (quo, rem uint64) {
return q1*two32 + q0, (un21*two32 + un0 - q0*y) >> s return q1*two32 + q0, (un21*two32 + un0 - q0*y) >> s
} }
//go:linkname overflowError runtime.overflowError
var overflowError error
//go:linkname divideError runtime.divideError
var divideError error
// Copyright 2019 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build !compiler_bootstrap
package bits
import _ "unsafe"
//go:linkname overflowError runtime.overflowError
var overflowError error
//go:linkname divideError runtime.divideError
var divideError error
// Copyright 2019 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build compiler_bootstrap
// This version used only for bootstrap (on this path we want
// to avoid use of go:linkname as applied to variables).
package bits
type errorString string
func (e errorString) RuntimeError() {}
func (e errorString) Error() string {
return "runtime error: " + string(e)
}
var overflowError = error(errorString("integer overflow"))
var divideError = error(errorString("integer divide by zero"))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment