Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

Commit

Permalink
Merge pull request #4 from ericrannaud/incoming
Browse files Browse the repository at this point in the history
Handle va_arg on struct types for the le32 target (PNaCl and Emscripten)
  • Loading branch information
sunfishcode committed Oct 30, 2014
2 parents e75021d + de1f674 commit 7643c5d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/CodeGen/CGExprAgg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,11 @@ void AggExprEmitter::VisitVAArgExpr(VAArgExpr *VE) {
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;
}

Expand Down
28 changes: 28 additions & 0 deletions test/CodeGen/le32-vaarg.c
Original file line number Diff line number Diff line change
@@ -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{{$}}

0 comments on commit 7643c5d

Please sign in to comment.