[PATCH] D118904: [clang][CodeGen] Use memory type representation in `va_arg`

Jan Svoboda via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 3 07:03:18 PST 2022


jansvoboda11 created this revision.
jansvoboda11 added a reviewer: t.p.northover.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118904

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/arm64-arguments.c


Index: clang/test/CodeGen/arm64-arguments.c
===================================================================
--- clang/test/CodeGen/arm64-arguments.c
+++ clang/test/CodeGen/arm64-arguments.c
@@ -196,6 +196,15 @@
     __builtin_va_end(ap);
     return ll;
 }
+_Bool t3(int i, ...) {
+  // CHECK: t3
+  __builtin_va_list ap;
+  __builtin_va_start(ap, i);
+  // TODO: Add proper checks here.
+  _Bool b = __builtin_va_arg(ap, _Bool);
+  __builtin_va_end(ap);
+  return b;
+}
 
 #include <arm_neon.h>
 
Index: clang/lib/CodeGen/TargetInfo.cpp
===================================================================
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -709,7 +709,8 @@
            "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;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118904.405629.patch
Type: text/x-patch
Size: 1109 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220203/428279b6/attachment.bin>


More information about the cfe-commits mailing list