From 42afaf7f472ce8ae14f1aa3858f1a8f3abc4ac67 Mon Sep 17 00:00:00 2001 From: Jan Svoboda Date: Thu, 3 Feb 2022 15:59:55 +0100 Subject: [PATCH] [clang][CodeGen] Use memory type representation in `va_arg` Some types (e.g. `_Bool`) have different scalar and memory representations. CodeGen for `va_arg` didn't take this into account, leading to an assertion failures with different types. This patch makes sure we use memory representation for `va_arg`. Reviewed By: ahatanak Differential Revision: https://reviews.llvm.org/D118904 --- clang/lib/CodeGen/TargetInfo.cpp | 3 ++- clang/test/CodeGen/arm64-arguments.c | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp index 9af3004..1896723 100644 --- a/clang/lib/CodeGen/TargetInfo.cpp +++ b/clang/lib/CodeGen/TargetInfo.cpp @@ -709,7 +709,8 @@ Address EmitVAArgInstr(CodeGenFunction &CGF, Address VAListAddr, QualType Ty, "Unexpected CoerceToType seen in arginfo in generic VAArg emitter!"); Address Temp = CGF.CreateMemTemp(Ty, "varet"); - Val = CGF.Builder.CreateVAArg(VAListAddr.getPointer(), CGF.ConvertType(Ty)); + Val = CGF.Builder.CreateVAArg(VAListAddr.getPointer(), + CGF.ConvertTypeForMem(Ty)); CGF.Builder.CreateStore(Val, Temp); return Temp; } diff --git a/clang/test/CodeGen/arm64-arguments.c b/clang/test/CodeGen/arm64-arguments.c index 9b10462..16997ca 100644 --- a/clang/test/CodeGen/arm64-arguments.c +++ b/clang/test/CodeGen/arm64-arguments.c @@ -196,6 +196,16 @@ double t2(int i, ...) { __builtin_va_end(ap); return ll; } +_Bool t3(int i, ...) { + // CHECK: t3 + __builtin_va_list ap; + __builtin_va_start(ap, i); + // CHECK: %0 = va_arg {{.*}}* %ap, i8 + // CHECK-NEXT: store i8 %0, i8* %varet, align 1 + _Bool b = __builtin_va_arg(ap, _Bool); + __builtin_va_end(ap); + return b; +} #include -- 2.7.4