Add translation rules for variadic libc calls#159
Open
lucic71 wants to merge 29 commits into
Open
Conversation
65c9c49 to
6e1a7cc
Compare
This allows writing
```cpp
template <typename... Args>
int f1(int a0, int a1, Args... args) {
return fcntl(a0, a1, args...);
}
```
Which becomes `f1: int fcntl(int, int, ...)`
In C++, builtin mul overflow is a variadic function: `bool (...)`. In C is an unprototyped function: `int ()`.
Contributor
Author
|
@joaotgouveia please take a look at the changes in cpp2rust/cpp_rule_preprocessor.cpp |
Contributor
Author
|
@nunoplopes this is ready for review |
Contributor
|
Uhm, this seems like a hack that works for a few unsafe rules, but it's of no use for refcount. Doesn't feel like the solution we need. |
Contributor
Author
It works for all variadic unsafe rules. I designed this only with unsafe in mind. Probably for refcount we will need another solution. Let me think if I can come up with something that would also work for refcount. |
joaotgouveia
reviewed
Jun 5, 2026
| if (llvm::isa<clang::TemplateTypeParmDecl>(param)) { | ||
| if (param->isTemplateParameterPack()) { | ||
| out.emplace_back( | ||
| clang::TemplateArgument::CreatePackCopy(sema_->Context, {})); |
Contributor
There was a problem hiding this comment.
I think that this can be replaced by clang::TemplateArgument::getEmptyPack()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Variadic rules are defined with the following syntax:
and
For the C++ side, use a template argument pack. This makes it clear that the function call is variadic. For the Rust side, use a variadic function inside an extern block, that's the only place Rust allows variadic functions.
I added a new attribute in the IR, called is_extern. It's used by the new
Mapper::IsLibcPassthrough. A libc passthrough is a rule that it's declared in Rust extern block. In the above example ioctl is defined as a passthrough forlibc::ioctl. In the future, we can use this for non-variadic rules as well.