-
Notifications
You must be signed in to change notification settings - Fork 189
Fix ICE segfault on empty static loops #3781
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
Conversation
8ae9e0b
to
31f2dba
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.
LGTM but i would slightly tweak this to be:
if (t == NULL_TREE)
return NULL_TREE;
if (CONST_CLASS_P (t))
... <continue on with rest of code>
just means we have an explicit guard against null at the start. Just for reference this ia port from the gcc/cp/constexpr.cc implementation which fits well as it operates on GCC tree's
Also for your commit message please prefix with gccrs: so something like:
"gccrs: fix ICE on empty constexpr loops
Empty loops have no body which means this is a NULL_TREE during const
evaluation which needs a check.
Fixes Rust-GCC # issue number
"8ba1eb8
to
e87446f
Compare
Implemented those changes! |
looks like you have a stray t in your fixes line: "Fixes Rust-GCC #3618t" |
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.
LGTM
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.
Actually sorry you need to add a test case too
it should be enough to add a test case of :
into a file in gcc/testsuite/rust/compile/issue-3618.rs |
Empty loops have no body which means this is a NULL_TREE during const evaluation which needs a check. Fixes Rust-GCC Rust-GCC#3618. gcc/rust/ChangeLog: * backend/rust-constexpr.cc (eval_constant_expression): Check if t is a NULL_TREE gcc/testsuite/ChangeLog: * rust/compile/issue-3618.rs: Test empty loops error properly. Signed-off-by: Tom Schollenberger <[email protected]>
Added in the test. |
Nice work but i just realised yes this need another change sorry. This null_tree check should still stay but you need another check the error should be:
So what you need to do is add a catch here: gccrs/gcc/rust/backend/rust-compile-expr.cc Line 671 in fc6b543
|
Oh that's my bad. I was comparing with a 1.86 |
Oh good point whats really funny is if you test 1.45 you get loop is not allowed but in 1.49 you get the exceeded limit error. uughh.. I think we should go both of these fixes in one commit. So we emit that error and if we need to we can remove it. |
@flip1995 @CohenArthur @P-E-P this was interesting patch because the rustc behaviour has changed so much here. later versions seem to fall back to a const eval limit like we have hit here but earlier versions of rust disable loop being allowed in const/static context. |
Hmm maybe we should just open up an issue relating the what behaviour we want since your current PR is more like the latest rustc I bet they let loops return values using break etc now so yeah.. lets go with your patch then. |
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.
LGTM
Yeah, even on 1.49, this compiles fine actually: static _X: () = loop {
break;
}; |
This PR addresses #3618. With this change, the expected error of reaching the iteration limit is reported:
My handling of
t
being aNULL_TREE
may not be appropriate ineval_constant_expression
, seeking guidance there.Fixes #3618