1
0
mirror of https://github.com/golang/go synced 2024-11-06 11:36:16 -07:00
go/misc/cgo
Ian Lance Taylor da769814b8 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>
2018-06-29 23:22:48 +00:00
..
errors cmd/go: accept only limited compiler and linker flags in #cgo directives 2018-02-07 15:35:57 +00:00
fortran *.bash: always use the same string equality operator 2017-03-14 21:46:31 +00:00
gmp
life test: remove rundircmpout and cmpout actions 2018-05-31 17:36:45 +00:00
nocgo
stdio test: remove rundircmpout and cmpout actions 2018-05-31 17:36:45 +00:00
test cmd/cgo: handle GCC 8 change in errors about constant initializers 2018-06-29 23:22:48 +00:00
testasan
testcarchive cmd/cgo: don't use absolute paths in the export header file 2018-04-25 00:36:09 +00:00
testcshared misc/cgo/testcshared: use file descriptor 30 for TestUnexportedSymbols 2018-04-21 04:18:51 +00:00
testgodefs
testplugin runtime: restore r2 when restoring state from gobuf in gogo on ppc64x 2018-06-11 12:13:11 +00:00
testsanitizers cmd/dist: run msan test only in testsanitizer on arm64 2018-06-15 14:04:32 +00:00
testshared cmd/link: never coalesce type descriptors when dynamically linking Go 2018-06-23 00:16:14 +00:00
testsigfwd
testso
testsovar
testtls