-
Notifications
You must be signed in to change notification settings - Fork 189
Emit error on array size overflow #4131
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
base: master
Are you sure you want to change the base?
Conversation
8dbcf21
to
455cf4c
Compare
f860507
to
ad2b82c
Compare
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.
Nice one didnt know you can do that
ad2b82c
to
c9af76e
Compare
= wi::ext (max - min + 1, precision, sign).to_uhwi (); | ||
|
||
unsigned int res; | ||
if (__builtin_umul_overflow (TREE_INT_CST_ELT (TYPE_SIZE_UNIT (array_type), |
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.
looks like there is a regression here on running on 32 bit platforms. So this __builtin wont work.
Its definetlyy worth checking this in C/C++ on compiler explorer and if they make the same error and work back from that error message.
I think your Fix is partly right there are two parts to fix this properly.
So 1, I think you need to add a check like you have or you could put it into typechecking over in
But maybe its enough to leave it wher you have it. You should be able to do:
We track the capacity expr as part of the Array type now. PArt 2: detect the HUGE array
Or also put in a new constant for 2gb maybe make it a new option in lang.opts so it can be changed but it defaults to 2gb as the final check. I think should do this. |
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.
I added some suggestions to try in the comments
Also debug_tree is super useful here |
When the byte size required for an array overflow we should emit an error. gcc/rust/ChangeLog: * backend/rust-compile-expr.cc (CompileExpr::array_copied_expr): Check for overflow on array memory size and emit an error. gcc/testsuite/ChangeLog: * rust/compile/issue-3962.rs: New test. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
c9af76e
to
573c26a
Compare
I think this is a good sign your getting:
|
not100% sure whats the best way to add tests for errors on m32 vs m64 here @dkm might know better |
Are you sure about that ? https://godbolt.org/z/Mr684qqsT rustc does not throw an error message when the allocation is too big. EDIT: It does since rustc 1.55 although I can't find anything about a 2Gb limit. |
When the byte size required for an array overflow we should emit an error.
Fixes #3962