Skip to content

libcore: Implement VaList::arg in pure rust #56489

Open
@dlrobertson

Description

@dlrobertson

Summary

Implement VaList::arg in pure rust, similar to va_list-rs.

Details

We currently expose the va_arg intrinsic which should emit the correct LLVM for va_arg for the given architecture and OS. We currently use the LLVM va_arg instruction, but it doesn't emit the correct code for some common OSes and architectures causing us to implement the instruction manually (See [src/librustc_codegen_llvm/va_arg.rs] for details). Since we do not support calling VaList::arg on arbitrary types, we might be able to implement something similar to va_list-rs in pure rust for most architectures, falling back to the LLVM va_arg instruction only when a pure rust implementation does not exist.

Original issue

Note this issue has been changed following #56489 (comment). The original issue is as follows:

codegen: Move custom va_arg logic to librustc_codegen_ssa

The LLVM va_arg intrinsic is far from a complete implementation. As a result, we have started to manually implement va_arg (like clang does) with the Builder in src/librustc_codegen_llvm/va_arg.rs. This logic should be moved to librustc_codegen_ssa in BuilderMethods::va_arg.

BuilderMethods::va_arg needs to fall back to LLVM's va_arg intrinsic when there isn't an custom implementation available, so we'll need to add a new trait method backend_va_arg (please suggest a better name 😄) that exposes the backend specific implementation of va_arg.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-FFIArea: Foreign function interface (FFI)C-enhancementCategory: An issue proposing an enhancement or a PR with one.F-c_variadic`#![feature(c_variadic)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions