r199830 - Handle va_arg on struct types for the le32 target (PNaCl and Emscripten)

Mark Seaborn mseaborn at chromium.org
Wed Jan 22 12:11:01 PST 2014


Author: mseaborn
Date: Wed Jan 22 14:11:01 2014
New Revision: 199830

URL: http://llvm.org/viewvc/llvm-project?rev=199830&view=rev
Log:
Handle va_arg on struct types for the le32 target (PNaCl and Emscripten)

PNaCl and Emscripten can both handle va_arg IR instructions with
struct type.

Also add a test to cover generating a va_arg IR instruction from
va_arg in C on le32 (as already handled by VisitVAArgExpr() in
CGExprScalar.cpp), which was not covered by a test before.

(This fixes https://code.google.com/p/nativeclient/issues/detail?id=2381)

Differential Revision: http://llvm-reviews.chandlerc.com/D2539

Added:
    cfe/trunk/test/CodeGen/le32-vaarg.c   (with props)
Modified:
    cfe/trunk/lib/CodeGen/CGExprAgg.cpp

Modified: cfe/trunk/lib/CodeGen/CGExprAgg.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprAgg.cpp?rev=199830&r1=199829&r2=199830&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprAgg.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprAgg.cpp Wed Jan 22 14:11:01 2014
@@ -935,7 +935,11 @@ void AggExprEmitter::VisitVAArgExpr(VAAr
   llvm::Value *ArgPtr = CGF.EmitVAArg(ArgValue, VE->getType());
 
   if (!ArgPtr) {
-    CGF.ErrorUnsupported(VE, "aggregate va_arg expression");
+    // If EmitVAArg fails, we fall back to the LLVM instruction.
+    llvm::Value *Val =
+        Builder.CreateVAArg(ArgValue, CGF.ConvertType(VE->getType()));
+    if (!Dest.isIgnored())
+      Builder.CreateStore(Val, Dest.getAddr());
     return;
   }
 

Added: cfe/trunk/test/CodeGen/le32-vaarg.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/le32-vaarg.c?rev=199830&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/le32-vaarg.c (added)
+++ cfe/trunk/test/CodeGen/le32-vaarg.c Wed Jan 22 14:11:01 2014
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -triple le32-unknown-nacl -emit-llvm -o - %s | FileCheck %s
+#include <stdarg.h>
+
+int get_int(va_list *args) {
+  return va_arg(*args, int);
+}
+// CHECK: define i32 @get_int
+// CHECK: [[RESULT:%[a-z_0-9]+]] = va_arg {{.*}}, i32{{$}}
+// CHECK: ret i32 [[RESULT]]
+
+struct Foo {
+  int x;
+};
+
+struct Foo dest;
+
+void get_struct(va_list *args) {
+  dest = va_arg(*args, struct Foo);
+}
+// CHECK: define void @get_struct
+// CHECK: [[RESULT:%[a-z_0-9]+]] = va_arg {{.*}}, %struct.Foo{{$}}
+// CHECK: store %struct.Foo [[RESULT]], %struct.Foo* @dest
+
+void skip_struct(va_list *args) {
+  va_arg(*args, struct Foo);
+}
+// CHECK: define void @skip_struct
+// CHECK: va_arg {{.*}}, %struct.Foo{{$}}

Propchange: cfe/trunk/test/CodeGen/le32-vaarg.c
------------------------------------------------------------------------------
    svn:eol-style = LF





More information about the cfe-commits mailing list