-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/cgo: compiler changes in constant warnings may require cgo changes #26066
Comments
Change https://golang.org/cl/121035 mentions this issue: |
I have filed a bug in the gcc bugzilla, thinking it might be a gccgo issue: With gc, I could not reproduce it. However, I realized that it was just becauge gc does not invoke the brand-new gcc in my environment. I have spent quite a bit time on this issue. I am willing to work on this. Regardless of that, here are what I have learnt. Firstly, it looks like gc and gccgo with gcc 7.x was working. However, I am not sure if I could call it really working. The basic idea would be a 64 bit integer "neg" should be regarded as an integral value rather than a floating point value. What had happened is the 64 bit integer was "not-int-const" AND "not-num-const." Here are the code that cgo gives to gcc to figure out "neg":
That is going to be a compile error as underlying enum type is likely 32 bits. However, look another piece of code that cgo generates:
Here, the value for integrals seems long long. Thus, for the first place, I am wondering why neg falls into "not-int-const." Moreover, the reason why neg is "not-num-const" is a bit tricky. C11 standard, as far as I know it, may say that a 'const' variable is not a constant which can be used to initialize a local 'static const' variable. However, it seems that the compiler is allowed to extend the range of constantness in the context. For me, it seems like cgo relies on gcc regarding what gcc is allowed not to be consistent. Therefore, gcc 7.3 says "not-num-const" according to the C11 standard (even though the given flag might be gnu11) but gcc 8+ silently sort of optimized & compiles the same piece of code with the same -std option. |
@kyoukim Thanks. As noted above, I've sent https://golang.org/cl/121035 to fix this issue. Want to take a look at that approach? |
@ianlancetaylor Thank you so much! It makes perfect sense to me. It is blocking 64 bits integers to be regarded as a constant. I am relatively new to the code base, and still wondering why a 64 bits integer is treated differently from a 32 bits integer. |
I'm not sure about 32-bits vs. 64-bits; what difference are you seeing? |
Thanks for looking at the change, by the way. |
I thought a 32 bits int would not fall into not-int-const. It was my bad. An int32 indeed does not look being differently treated. Thank you! |
Test case:
Building that test case with GCC versions before GCC 8 works. With GCC 8 and later, it gets
What has changed is the handling of this C program, similar to that generated by cgo.
Before GCC 8, compiling this program gets
In GCC 8 and later, it gets
In other words,
static const double x = (neg);
is now accepted without warning. This appears to be due to the fix for https://gcc.gnu.org/PR69960. See also https://gcc.gnu.org/PR83222 and https://gcc.gnu.org/PR86289.This effect of this warning change on cgo is that in the original test case
neg
now appears to be a floating point constant. cgo represents this constant as18446744073709551616.000000
. This leads to theinteger constant overflow
error shown above.We're going to need to figure this out.
The text was updated successfully, but these errors were encountered: