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

gccrs: feat: Made changes to ensure no wrong assignments are done. #3300

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sriganeshres
Copy link
Contributor

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (lvalue_p): Created a function that checks the lvalue. (CompileExpr::visit): Modified the function to check the lvalue using the above mentioned function and also checks the type of lvalue expression.

gcc/testsuite/ChangeLog:

* rust/compile/issue-3287.rs: New test for testing wrong assignments.

Fixes #3287

Copy link
Member

@philberty philberty left a 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

gcc/rust/backend/rust-compile-expr.cc Outdated Show resolved Hide resolved
gcc/rust/backend/rust-compile-expr.cc Outdated Show resolved Hide resolved
gcc/rust/backend/rust-compile-expr.cc Outdated Show resolved Hide resolved
gcc/rust/backend/rust-compile-expr.cc Outdated Show resolved Hide resolved
gcc/rust/backend/rust-compile-expr.cc Outdated Show resolved Hide resolved
gcc/rust/backend/rust-compile-expr.cc Outdated Show resolved Hide resolved
@philberty philberty added the diagnostic diagnostic static analysis label Dec 11, 2024
@sriganeshres sriganeshres force-pushed the feat-wrong-assignment branch 2 times, most recently from 9bd6356 to 5748d31 Compare December 11, 2024 19:53
@sriganeshres sriganeshres force-pushed the feat-wrong-assignment branch 4 times, most recently from fc569e4 to 2a551f5 Compare December 14, 2024 16:29
@sriganeshres
Copy link
Contributor Author

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

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.

@sriganeshres sriganeshres force-pushed the feat-wrong-assignment branch 4 times, most recently from 1089291 to e6a88dc Compare December 15, 2024 14:40
@powerboat9
Copy link
Contributor

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

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.

You have to adjust the visitor for CompoundAssignmentExpr as well as the visitor for AssignmentExpr

@powerboat9
Copy link
Contributor

Would probably be good to make lvalue_p operate on HIR nodes instead of trees

gcc/testsuite/rust/compile/issue-3297.rs Outdated Show resolved Hide resolved
gcc/rust/backend/rust-compile-base.h Outdated Show resolved Hide resolved
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]>
@sriganeshres sriganeshres force-pushed the feat-wrong-assignment branch from e6a88dc to c9d729f Compare January 7, 2025 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
diagnostic diagnostic static analysis
Projects
None yet
Development

Successfully merging this pull request may close these issues.

gccrs does not check if something is assignable
4 participants