From b281d47a752dd499bde0ffdde8ed84500828ee94 Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Mon, 27 Feb 2023 01:08:07 -0800 Subject: [PATCH 1/4] Fix va_arg intrinsic --- gen/functions.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gen/functions.cpp b/gen/functions.cpp index a96a49cd508..fdc54582b6b 100644 --- a/gen/functions.cpp +++ b/gen/functions.cpp @@ -1046,6 +1046,8 @@ void DtoDefineFunction(FuncDeclaration *fd, bool linkageAvailableExternally) { } if (fd->ir->isDefined()) { + if (fd->llvmInternal == LLVMva_arg) + return; llvm::Function *func = getIrFunc(fd)->getLLVMFunc(); assert(func); if (!linkageAvailableExternally && From 0e9f03190836063a72aeb4c34dbc55d38e9df0de Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Mon, 27 Feb 2023 01:15:24 -0800 Subject: [PATCH 2/4] Add test case --- tests/compilable/va_arg.d | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 tests/compilable/va_arg.d diff --git a/tests/compilable/va_arg.d b/tests/compilable/va_arg.d new file mode 100644 index 00000000000..05d28952be1 --- /dev/null +++ b/tests/compilable/va_arg.d @@ -0,0 +1,9 @@ +// RUN: %ldc -c %s + +alias va_list = void*; + +pragma(LDC_va_arg) T va_arg(T)(va_list ap); + +int foo(va_list ap) { + return va_arg!(int)(ap); +} From 496e7d91114b2714c264b47ff7b703aa660f0880 Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Mon, 27 Feb 2023 10:13:11 -0800 Subject: [PATCH 3/4] Restrict test further --- tests/compilable/va_arg.d | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/compilable/va_arg.d b/tests/compilable/va_arg.d index 05d28952be1..9f1d73629e7 100644 --- a/tests/compilable/va_arg.d +++ b/tests/compilable/va_arg.d @@ -1,4 +1,7 @@ -// RUN: %ldc -c %s +// REQUIRES: host_X86 + +// RUN: %ldc -mtriple=aarch64-none-elf -c %s +// RUN: %ldc -mtriple=riscv64-none-elf -c %s alias va_list = void*; From 2bafd62662a16824999fc89fed4f9dce4eb2e534 Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Mon, 27 Feb 2023 10:42:04 -0800 Subject: [PATCH 4/4] Update test --- tests/compilable/va_arg.d | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/compilable/va_arg.d b/tests/compilable/va_arg.d index 9f1d73629e7..1d43be44585 100644 --- a/tests/compilable/va_arg.d +++ b/tests/compilable/va_arg.d @@ -1,7 +1,5 @@ -// REQUIRES: host_X86 - // RUN: %ldc -mtriple=aarch64-none-elf -c %s -// RUN: %ldc -mtriple=riscv64-none-elf -c %s +// RUN: %ldc -mtriple=riscv64-unknown-elf -c %s alias va_list = void*;