Skip to content
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

gccgo: does not see stupidness of shift count #11524

Closed
dvyukov opened this issue Jul 2, 2015 · 8 comments
Closed

gccgo: does not see stupidness of shift count #11524

dvyukov opened this issue Jul 2, 2015 · 8 comments
Milestone

Comments

@dvyukov
Copy link
Member

dvyukov commented Jul 2, 2015

Both gc and go/types reject the following program, but gccgo accepts:

package a
var g = 0>>1080

gccgo should reject it as well.
gcc version 6.0.0 2015070 (experimental) (GCC)

@dvyukov
Copy link
Member Author

dvyukov commented Jul 2, 2015

@paranoiacblack

@rsc
Copy link
Contributor

rsc commented Jul 10, 2015

Not sure why gccgo must reject this.

@ianlancetaylor ianlancetaylor added this to the Gccgo milestone Jul 10, 2015
@ianlancetaylor
Copy link
Contributor

I agree with rsc: the language spec does not require us to reject this program. I think gccgo is fine.

@dvyukov
Copy link
Member Author

dvyukov commented Jul 10, 2015

First, such differences will make porting of large code based between compilers hard (this will actually have to be explicit porting process like in C++). Second, if it is a worthwhile diagnostic then both compilers should do it, otherwise no compiler should bother user.
There is really no objective reasons for differences between compilers in this place. Why do you want to keep this difference?

@paranoiacblack
Copy link
Contributor

If gccgo does reject this program, it isn't clear to me how many shifts would be allowed before it becomes a stupid shift. gc and go/types already disagree on this point, with go1.5 putting the limit on stupidness at 512 bits and go/types limiting it around 1024 bits. It's weird that if the expression was 1 >> 1000, now go/types and gccgo would accept it while gc would not. If we wanted to fix the differences between the compilers, what's the right thing to do here?

@ianlancetaylor
Copy link
Contributor

No real program is going to write this kind of code. So I reject the argument that this will complicate porting of large code bases between compilers.

This is not, in my opinion, a worthwhile diagnostic. The gc compiler implements it to simplify its own internal handling of untyped constants.

The only possible principled approach is for all compilers to implement the complete language described in the spec. The spec permits large shift counts. Therefore the compilers should too. But, again, no actual code is going to use this, so it doesn't matter that gc rejects it.

I don't think there is anything to do here.

@cldorian
Copy link
Contributor

I'd like to disagree with the opinion that, "No real program is going to write this kind of code."

While writing tests on denormals for an fma function, I had to write:
var fmaTests = []struct {
x, y, z, out float64
}{
{1.0 + 1.0/(1<<27), 1.0 - 1.0/(1<<27), -Ldexp(1, -1074), 1.0 - 1.0/(1<<53)}, // 4.9406564584124654418e-324 but 1.0/(1<<1074) => "stupid shift"
}

@griesemer
Copy link
Contributor

@cldorian I tend to agree. It would be nice to set the shift max to a value that permits the direct expression of the extremes of float64. It doesn't cost in the compiler. A tad over 1000 as limit should be ok.

@golang golang locked and limited conversation to collaborators Jul 11, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants