-
-
Notifications
You must be signed in to change notification settings - Fork 606
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
Fix Issue 23173 - "Error: signed integer overflow" for compiler gener… #14218
Conversation
Thanks for your pull request and interest in making D better, @dkorpel! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla references
Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#14218" |
mir-algorithm wants to be able to parse the result of enum m = T.min + 0;
str = m.stringof;
assert(parse(str, val));
val.should == T.min; |
Perhaps the lexer should just allow |
Can we not just make the lexer more lenient? |
Yes, but that would also allow: long x = 9223372036854775808L; // will overflow |
Move the check into the semantic analysis. Doing it in the lexer in the first place is silly for this reason |
What will |
An error. The semantics don't have to change it's just that doing the check in the lexer is completely wrong |
not that this needs to take it into account but (when) is cent becoming a thing? Will we have the same problems there? |
Then |
Walter thinks it should stay a library type, because its usage is not common and it would complicate the compiler / make dmd use more memory.
If it's implemented in the same way as |
src/dmd/hdrgen.d
Outdated
if (v == long.min) | ||
{ | ||
// https://issues.dlang.org/show_bug.cgi?id=23173 | ||
// This is a special case because - is not part of the | ||
// integer literal and 9223372036854775808L overflows a long | ||
buf.writestring("cast(long)-9223372036854775808"); | ||
} | ||
else | ||
{ | ||
buf.printf("%lldL", v); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (v == long.min) | |
{ | |
// https://issues.dlang.org/show_bug.cgi?id=23173 | |
// This is a special case because - is not part of the | |
// integer literal and 9223372036854775808L overflows a long | |
buf.writestring("cast(long)-9223372036854775808"); | |
} | |
else | |
{ | |
buf.printf("%lldL", v); | |
} | |
buf.printf("cast(long)%lldL", v); |
Is there any reason why we can't just throw in the cast implicitly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only just noticing the other discussion.
AFAIK, most of these overflow checks are being made in the lexer. The lexer token has a special case for integers. Which I don't think it should be the way to do it, unless there's any performance benefits that overcome the complexity of adding such special case. |
Dependant PR merged |
…ated string of `long.min`
auto-test failure looks unrelated
|
@RazvanN7 this is ready for review |
…ated string of
long.min
I don't know of a clean way to write
-9223372036854775808
typed as along
, so it's a bit ugly.