]> Cypherpunks repositories - gostls13.git/commit
cmd/cgo: handle GCC 8 change in errors about constant initializers
authorIan Lance Taylor <iant@golang.org>
Tue, 26 Jun 2018 21:40:51 +0000 (14:40 -0700)
committerIan Lance Taylor <iant@golang.org>
Fri, 29 Jun 2018 23:22:48 +0000 (23:22 +0000)
commitda769814b83c4eb65681dbe682d07d4b902b554a
treea327d64178f1f0782ced67e2ec7dcb4809287b08
parent1b12a2ca21776ced3e9d34e14bb442254e250c14
cmd/cgo: handle GCC 8 change in errors about constant initializers

Before GCC 8 C code like

const unsigned long long int neg = (const unsigned long long) -1;
void f(void) { static const double x = (neg); }

would get an error "initializer element is not constant". In GCC 8 and
later it does not.

Because a value like neg, above, can not be used as a general integer
constant, this causes cgo to conclude that it is a floating point
constant. The way that cgo handles floating point values then causes
it to get the wrong value for it: 18446744073709551615 rather than -1.
These are of course the same value when converted to int64, but Go
does not permit that kind of conversion for an out-of-range constant.

This CL side-steps the problem by treating floating point constants
with integer type as they would up being treated before GCC 8: as
variables rather than constants.

Fixes #26066

Change-Id: I6f2f9ac2fa8a4b8218481b474f0b539758eb3b79
Reviewed-on: https://go-review.googlesource.com/121035
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
misc/cgo/test/cgo_test.go
misc/cgo/test/issue26066.go [new file with mode: 0644]
src/cmd/cgo/gcc.go