-
Notifications
You must be signed in to change notification settings - Fork 243
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
Support va_copy
with a member of a struct pointer
#612
Conversation
va_copy
with a member of a struct pointer
Hi @Hakuyume! Thanks for the help! I haven't looked at this part of the transpiler before, so could you tell me what the previous behavior was (an error, mis-transpilation, etc.)? Also, what exactly was the motivating use case for this? The example you gave, void foo(va_list args) {
struct S *s;
va_copy(s->args, args);
} dereferences an uninitialized pointer. I assume that's just an overly simplified example, but if you could give some more context on what you need this for, that would be great! That said, I'm not sure why the transpiler only works on only pointers and struct members and not just general expressions. Adding more support would be helpful, but ideally, it'd just work on any expression. |
c2rust ignores (skips) the function that contains
Yes. As you mentioned, my example is too simplified. I think my patch is ad-hoc. If there is more general way, it would be nice. |
Thanks for the further context! I'll look into it and see if there's a reason it's not more generic. @thedataking, any thoughts, as it says you wrote most of the |
@thedataking, why not do something like this? Define // Or maybe call this `__builtin_va_copy`.
fn va_copy(dest: &mut VaListImpl, src: &VaListImpl) {
dest.clone_from(src); // or `dest = src.clone();`
} and then transform va_copy(e1, e2) into va_copy(&mut transpile(e1), &transpile(e2)); Why is the specific matching on arguments necessary? Also, I think a mis-translation of invalid C code into similarly invalid Rust code is better than entirely skipping a function, which makes no sense. |
It has been more than three years since I worked on #92 so I'm fuzzy on some of the details. As far as I remember, the challenge is that some uses of
The overall operation of the transpiler is that it either translates the input into Rust that (modulo bugs) is functionally equivalent to the input or bails out with an error. Not doing so could introduce some very subtle and hard to find bugs. A few other notes:
|
Thanks for context, @thedataking! In that case, @Hakuyume, I think an ad-hoc fix like this is okay if we can't easily get a general solution. Please add a test in |
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.
See the comment; just add a va_copy
in the test and then the test should be all good.
tests/items/src/varargs.c
Outdated
va_start(pointer->args, fmt); | ||
vprintf(fmt, pointer->args); | ||
va_end(pointer->args); |
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.
It's not testing va_copy
. That might be handled similarly to va_start
and va_end
, but I think it should still be tested as well. Can you add that? Might as well add the same to the similar valist_struct_member
function above.
@kkysen Thank you for reviewing. I updated test cases. Some of CIs failed but the failure does not seem related to my patch. |
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'm just going to rebase and rename that suggestion commit, but otherwise, it's all good and I'll merge this once CI passes. Thank you!
The CI failure is due to some other flaky tests that we're trying to debug. I re-ran the CI and it should be fine. |
…` function was added (transpiling `graphviz`), similarly to the other similar function. Co-authored-by: Khyber Sen <kkysen@gmail.com>
This PR add support for
va_copy
which argument is a member of a struct point.Example C code.
Emitted Rust code.