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

Handle va_arg on struct types for the le32 target (PNaCl and Emscripten) #4

Merged
merged 1 commit into from
Oct 30, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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{{$}}