[X86] Fix variadic argument handling for x32
authorHarald van Dijk <harald@gigawatt.nl>
Mon, 14 Dec 2020 23:47:27 +0000 (23:47 +0000)
committerHarald van Dijk <harald@gigawatt.nl>
Mon, 14 Dec 2020 23:47:27 +0000 (23:47 +0000)
commit9eac818370fe4b50a167627593bfe53e61c216bc
treee77a04e85692d5f9a9bda225c6be9593aba64e5b
parentd058b69b1cd3d71b9bcb45011f5f3ef3a576a5e2
[X86] Fix variadic argument handling for x32

The X86-64 ABI defines va_list as

  typedef struct {
    unsigned int gp_offset;
    unsigned int fp_offset;
    void *overflow_arg_area;
    void *reg_save_area;
  } va_list[1];

This means the size, alignment, and reg_save_area offset will depend on
whether we are in LP64 or in ILP32 mode, so this commit adds the checks.
Additionally, the VAARG_64 pseudo-instruction assumed 64-bit pointers, so
this commit adds a VAARG_X32 pseudo-instruction that behaves just like
VAARG_64, except for assuming 32-bit pointers.

Some of these changes were originally done by
Michael Liao <michael.hliao@gmail.com>.

Fixes https://bugs.llvm.org/show_bug.cgi?id=48428.

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D93160
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/lib/Target/X86/X86ISelLowering.h
llvm/lib/Target/X86/X86InstrCompiler.td
llvm/lib/Target/X86/X86InstrInfo.td
llvm/test/CodeGen/X86/x86-64-varargs.ll