diff options
author | Martin Storsjo <martin@martin.st> | 2017-07-13 17:59:14 +0000 |
---|---|---|
committer | Martin Storsjo <martin@martin.st> | 2017-07-13 17:59:14 +0000 |
commit | 502de22fda27d49c70c6f81dc9ff43c2a1292363 (patch) | |
tree | 92bb1043cb68e42c69934db8be2a3872ac4a36a9 | |
parent | 6c0eeffe71528a3851470ff78e4d3649550a31e5 (diff) | |
download | bcm5719-llvm-502de22fda27d49c70c6f81dc9ff43c2a1292363.tar.gz bcm5719-llvm-502de22fda27d49c70c6f81dc9ff43c2a1292363.zip |
[AArch64] Produce the right kind of va_arg for windows
On windows on arm64, the va_list is a plain pointer.
Differential Revision: https://reviews.llvm.org/D35008
llvm-svn: 307933
-rw-r--r-- | clang/lib/CodeGen/TargetInfo.cpp | 21 | ||||
-rw-r--r-- | clang/test/CodeGen/aarch64-varargs-ms.c | 11 |
2 files changed, 29 insertions, 3 deletions
diff --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp index eeebd60a2d2..c17828974e9 100644 --- a/clang/lib/CodeGen/TargetInfo.cpp +++ b/clang/lib/CodeGen/TargetInfo.cpp @@ -4785,7 +4785,8 @@ class AArch64ABIInfo : public SwiftABIInfo { public: enum ABIKind { AAPCS = 0, - DarwinPCS + DarwinPCS, + Win64 }; private: @@ -4823,10 +4824,14 @@ private: Address EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty) const override { - return isDarwinPCS() ? EmitDarwinVAArg(VAListAddr, Ty, CGF) - : EmitAAPCSVAArg(VAListAddr, Ty, CGF); + return Kind == Win64 ? EmitMSVAArg(CGF, VAListAddr, Ty) + : isDarwinPCS() ? EmitDarwinVAArg(VAListAddr, Ty, CGF) + : EmitAAPCSVAArg(VAListAddr, Ty, CGF); } + Address EmitMSVAArg(CodeGenFunction &CGF, Address VAListAddr, + QualType Ty) const override; + bool shouldPassIndirectlyForSwift(CharUnits totalSize, ArrayRef<llvm::Type*> scalars, bool asReturnValue) const override { @@ -5332,6 +5337,14 @@ Address AArch64ABIInfo::EmitDarwinVAArg(Address VAListAddr, QualType Ty, TyInfo, SlotSize, /*AllowHigherAlign*/ true); } +Address AArch64ABIInfo::EmitMSVAArg(CodeGenFunction &CGF, Address VAListAddr, + QualType Ty) const { + return emitVoidPtrVAArg(CGF, VAListAddr, Ty, /*indirect*/ false, + CGF.getContext().getTypeInfoInChars(Ty), + CharUnits::fromQuantity(8), + /*allowHigherAlign*/ false); +} + //===----------------------------------------------------------------------===// // ARM ABI Implementation //===----------------------------------------------------------------------===// @@ -8494,6 +8507,8 @@ const TargetCodeGenInfo &CodeGenModule::getTargetCodeGenInfo() { AArch64ABIInfo::ABIKind Kind = AArch64ABIInfo::AAPCS; if (getTarget().getABI() == "darwinpcs") Kind = AArch64ABIInfo::DarwinPCS; + else if (Triple.isOSWindows()) + Kind = AArch64ABIInfo::Win64; return SetCGInfo(new AArch64TargetCodeGenInfo(Types, Kind)); } diff --git a/clang/test/CodeGen/aarch64-varargs-ms.c b/clang/test/CodeGen/aarch64-varargs-ms.c new file mode 100644 index 00000000000..f2ba9339e6c --- /dev/null +++ b/clang/test/CodeGen/aarch64-varargs-ms.c @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -triple arm64-windows-msvc -emit-llvm -o - %s | FileCheck --check-prefix=CHECK %s + +#include <stdarg.h> + +int simple_int(va_list ap) { +// CHECK-LABEL: define i32 @simple_int + return va_arg(ap, int); +// CHECK: [[ADDR:%[a-z_0-9]+]] = bitcast i8* %argp.cur to i32* +// CHECK: [[RESULT:%[a-z_0-9]+]] = load i32, i32* [[ADDR]] +// CHECK: ret i32 [[RESULT]] +} |