-
Notifications
You must be signed in to change notification settings - Fork 161
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
gccrs: feat: Made changes to ensure no wrong assignments are done. #3300
base: master
Are you sure you want to change the base?
Conversation
41640eb
to
167b909
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.
There are changes required here i think we can get away wit this check but not totally convinced yet
Also it will need to be applied to the other assignments such as:
x +=1 etc
@@ -958,12 +958,71 @@ CompileExpr::visit (HIR::LiteralExpr &expr) | |||
} | |||
} | |||
|
|||
bool | |||
lvalue_p (const_tree ref) |
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.
this should be renamed and moved into rust-compile-base.cc or into rust-tree.cc call it is_lvalue_tree
case COMPONENT_REF: | ||
return lvalue_p (TREE_OPERAND (ref, 0)); | ||
|
||
case C_MAYBE_CONST_EXPR: |
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.
c_ TREE's dont exists here remove this case
case RESULT_DECL: | ||
case ERROR_MARK: | ||
return (TREE_CODE (TREE_TYPE (ref)) != FUNCTION_TYPE | ||
&& TREE_CODE (TREE_TYPE (ref)) != METHOD_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.
iirc METHOD_TYPE might not be a common tree type either
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.
Should i remove that
case TRUNC_DIV_EXPR: | ||
return false; | ||
default: | ||
rust_debug ("unknown"); |
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.
remove this useless debug
void | ||
CompileExpr::visit (HIR::AssignmentExpr &expr) | ||
{ | ||
auto lvalue = CompileExpr::Compile (expr.get_lhs (), ctx); | ||
auto rvalue = CompileExpr::Compile (expr.get_rhs (), ctx); | ||
|
||
if (!lvalue_p (lvalue) |
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 dont like if statements like this its hard to read:
it should be:
bool valid_lvalue = XXX
if (!valid_lvalue) {
-- error diagnostic
}
|| expr.get_lhs ().get_expression_type () | ||
== HIR::Expr::ExprType::Operator) | ||
{ | ||
rust_error_at (expr.get_lhs ().get_locus (), |
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.
you need to add in the rust error code ussing the proper interface
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.
Can you give me more clarity
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.
you need to pass the rust error code into this function like we do in other places take a look through the other parts of the code to check
9bd6356
to
5748d31
Compare
fc569e4
to
2a551f5
Compare
Can you give me more information about the case we are missing as x+= 1 is valid as long as x is mutable in rust. |
944688f
to
1089291
Compare
gcc/rust/ChangeLog: * backend/rust-compile-base.cc (HIRCompileBase::lvalue_p): Created a function that checks for lvalue. * backend/rust-compile-base.h: Created the Signature for above function. * backend/rust-compile-expr.cc (CompileExpr::visit): Made changes to ensure proper readability and checking for wrong assignments. gcc/testsuite/ChangeLog: * rust/compile/issue-3297.rs: New test. Signed-off-by: Sri Ganesh Thota <[email protected]>
1089291
to
e6a88dc
Compare
gcc/rust/ChangeLog:
gcc/testsuite/ChangeLog:
Fixes #3287
make check-rust
passes locallyclang-format
gcc/testsuite/rust/