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

Check fixed args number for variadic function #4122

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

tiif
Copy link
Contributor

@tiif tiif commented Jan 4, 2025

cc #4013

@rustbot ready

@rustbot rustbot added the S-waiting-on-review Status: Waiting for a review to complete label Jan 4, 2025
Copy link
Contributor

@oli-obk oli-obk left a comment

Choose a reason for hiding this comment

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

Please squash

@@ -236,6 +237,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
"open" | "open64" => {
// `open` is variadic, the third argument is only present when the second argument has O_CREAT (or on linux O_TMPFILE, but miri doesn't support that) set
this.check_abi_and_shim_symbol_clash(abi, Conv::C , link_name)?;
this.check_fixed_args_count("open/open64", abi, 2)?;
Copy link
Member

@RalfJung RalfJung Jan 7, 2025

Choose a reason for hiding this comment

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

Now it's still fairly easy to forget to call check_fixed_args_count.

So instead, please add a new this.check_shim_variadic that is a lot like check_shim but returns something like (&'a [OpTy<'tcx>; N], &'a [OpTy<'tcx>]) where the "fixed" arguments are mapped to the array and the variadic ones are returned in the slice.

When this is all done, check_abi_and_shim_symbol_clash should never be called in a shim; each shim should call check_shim or check_shim_variadic.

) -> InterpResult<'tcx> {
if abi.fixed_count != expected_count {
throw_ub_format!(
"incorrect number of fixed args for `{name}`: got {}, expected {expected_count}",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"incorrect number of fixed args for `{name}`: got {}, expected {expected_count}",
"incorrect number of fixed arguments for variadic function `{name}`: got {}, expected {expected_count}",

@tiif
Copy link
Contributor Author

tiif commented Jan 7, 2025

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: Waiting for the PR author to address review comments and removed S-waiting-on-review Status: Waiting for a review to complete labels Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: Waiting for the PR author to address review comments
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants