i386: Take the va_arg by-reference decision from the va_list type
Ensures `va_arg` correctly handles arguments passed by reference based on the `va_list`'s ABI.
This commit refactors how GCC’s i386 backend determines if a va_arg should be treated as passed by reference. Previously, the ix86_pass_by_reference hook often defaulted to the system’s default ABI (SysV on Linux), leading to incorrect handling of arguments passed by reference in functions using other ABIs (like the MS ABI). The change splits the ABI-specific logic into a new function ix86_pass_by_reference_abi, allowing ix86_gimplify_va_arg to correctly read indirect MS ABI arguments as pointers and use the explicit SysV ABI for SysV va_lists.
In Details
The ix86_gimplify_va_arg function's handling of arguments passed by reference was problematic, especially with the MS ABI. The pass_by_reference hook was being used, but it often defaulted to the SysV ABI's behavior. This commit introduces ix86_pass_by_reference_abi to correctly determine the argument passing mechanism based on the va_list's actual ABI. For MS ABI va_lists, it now dereferences the pointer obtained via std_gimplify_va_arg_expr, mimicking ia64_gimplify_va_arg, and uses the SysV ABI logic for SysV va_lists to handle mismatches correctly.
- va_arg
- A macro in C used to retrieve arguments from a variable argument list (
va_list). - va_list
- A type in C used to hold information about a variable argument list.
- ABI
- Application Binary Interface. Defines how low-level code, such as compiled object files and libraries, interact with each other.
- i386
- The Intel 80386 microprocessor architecture, commonly referred to as x86.
- MS ABI
- Microsoft's Application Binary Interface, used on Windows systems.
- SysV ABI
- System V Application Binary Interface, a standard convention for how functions are called and how data is passed between them on Unix-like systems.