Skip to content

Conversation

MahadMuhammad
Copy link
Contributor

Attempt to pass invalid type variable into a variadic function - E0617

There are some certain rust types must be cast before passing them to a variadic function, because of arcane ABI rules dictated by the C standard. To fix the error, cast the value to the type specified by the error message.


gcc/rust/ChangeLog:

* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Added ErrorCode & more fixit hints.

gcc/testsuite/ChangeLog:

* rust/compile/variadic.rs: Added new checks.

There are some certain rust types must be cast before
passing them to a variadic function, because of arcane
ABI rules dictated by the C standard. To fix the error,
cast the value to the type specified by the error message.

gcc/rust/ChangeLog:

	* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit):
	Added ErrorCode & more fixit hints.

gcc/testsuite/ChangeLog:

	* rust/compile/variadic.rs: Added new checks.

Signed-off-by: Muhammad Mahad <[email protected]>
Comment on lines -187 to +190
rust_error_at (arg_locus,
rich_location richloc (line_table, arg_locus);
richloc.add_fixit_replace (
"cast the value to c_int: as c_int");
rust_error_at (richloc, ErrorCode::E0617,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Combining all of these into one function with different messages might seem like a bit overkill, but if it works better, I'll do that.

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.

LGTM

@philberty philberty added this pull request to the merge queue Sep 17, 2023
@philberty philberty added the diagnostic diagnostic static analysis label Sep 17, 2023
@philberty philberty added this to the GCC 14 Stage 3 milestone Sep 17, 2023
Merged via the queue into Rust-GCC:master with commit a2d5250 Sep 17, 2023
@MahadMuhammad MahadMuhammad deleted the E0617 branch September 18, 2023 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
diagnostic diagnostic static analysis
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants