From: Jan Svoboda Date: Thu, 3 Feb 2022 14:59:55 +0000 (+0100) Subject: [clang][CodeGen] Use memory type representation in `va_arg` X-Git-Tag: upstream/15.0.7~17813 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=42afaf7f472ce8ae14f1aa3858f1a8f3abc4ac67;p=platform%2Fupstream%2Fllvm.git [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 --- 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