2014-03-29 23:09:45 +08:00
|
|
|
// RUN: %clang_cc1 -triple arm64-linux-gnu -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=CHECK-LE %s
|
2014-07-23 20:57:31 +08:00
|
|
|
// RUN: %clang_cc1 -triple aarch64_be-linux-gnu -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=CHECK-BE %s
|
2014-03-14 19:51:06 +08:00
|
|
|
|
2013-01-31 20:13:10 +08:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
// Obviously there's more than one way to implement va_arg. This test should at
|
|
|
|
// least prevent unintentional regressions caused by refactoring.
|
|
|
|
|
|
|
|
va_list the_list;
|
|
|
|
|
|
|
|
int simple_int(void) {
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define i32 @simple_int
|
2013-01-31 20:13:10 +08:00
|
|
|
return va_arg(the_list, int);
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[GR_OFFS:%[a-z_0-9]+]] = load i32, i32* getelementptr inbounds (%struct.__va_list* @the_list, i32 0, i32 3)
|
2013-01-31 20:13:10 +08:00
|
|
|
// CHECK: [[EARLY_ONSTACK:%[a-z_0-9]+]] = icmp sge i32 [[GR_OFFS]], 0
|
|
|
|
// CHECK: br i1 [[EARLY_ONSTACK]], label %[[VAARG_ON_STACK:[a-z_.0-9]+]], label %[[VAARG_MAYBE_REG:[a-z_.0-9]+]]
|
|
|
|
|
|
|
|
// CHECK: [[VAARG_MAYBE_REG]]
|
|
|
|
// CHECK: [[NEW_REG_OFFS:%[a-z_0-9]+]] = add i32 [[GR_OFFS]], 8
|
|
|
|
// CHECK: store i32 [[NEW_REG_OFFS]], i32* getelementptr inbounds (%struct.__va_list* @the_list, i32 0, i32 3)
|
|
|
|
// CHECK: [[INREG:%[a-z_0-9]+]] = icmp sle i32 [[NEW_REG_OFFS]], 0
|
|
|
|
// CHECK: br i1 [[INREG]], label %[[VAARG_IN_REG:[a-z_.0-9]+]], label %[[VAARG_ON_STACK]]
|
|
|
|
|
|
|
|
// CHECK: [[VAARG_IN_REG]]
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[REG_TOP:%[a-z_0-9]+]] = load i8*, i8** getelementptr inbounds (%struct.__va_list* @the_list, i32 0, i32 1)
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK: [[REG_ADDR:%[a-z_0-9]+]] = getelementptr i8, i8* [[REG_TOP]], i32 [[GR_OFFS]]
|
2014-03-14 19:51:06 +08:00
|
|
|
// CHECK-BE: [[REG_ADDR_VAL:%[0-9]+]] = ptrtoint i8* [[REG_ADDR]] to i64
|
2014-03-15 00:30:06 +08:00
|
|
|
// CHECK-BE: [[REG_ADDR_VAL_ALIGNED:%[a-z_0-9]*]] = add i64 [[REG_ADDR_VAL]], 4
|
2014-03-14 19:51:06 +08:00
|
|
|
// CHECK-BE: [[REG_ADDR:%[0-9]+]] = inttoptr i64 [[REG_ADDR_VAL_ALIGNED]] to i8*
|
2013-01-31 20:13:10 +08:00
|
|
|
// CHECK: [[FROMREG_ADDR:%[a-z_0-9]+]] = bitcast i8* [[REG_ADDR]] to i32*
|
|
|
|
// CHECK: br label %[[VAARG_END:[a-z._0-9]+]]
|
|
|
|
|
|
|
|
// CHECK: [[VAARG_ON_STACK]]
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[STACK:%[a-z_0-9]+]] = load i8*, i8** getelementptr inbounds (%struct.__va_list* @the_list, i32 0, i32 0)
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK: [[NEW_STACK:%[a-z_0-9]+]] = getelementptr i8, i8* [[STACK]], i32 8
|
2013-01-31 20:13:10 +08:00
|
|
|
// CHECK: store i8* [[NEW_STACK]], i8** getelementptr inbounds (%struct.__va_list* @the_list, i32 0, i32 0)
|
2014-03-15 00:30:06 +08:00
|
|
|
// CHECK-BE: [[STACK_VAL:%[0-9]+]] = ptrtoint i8* [[STACK]] to i64
|
|
|
|
// CHECK-BE: [[STACK_VAL_ALIGNED:%[a-z_0-9]*]] = add i64 [[STACK_VAL]], 4
|
2014-03-14 19:51:06 +08:00
|
|
|
// CHECK-BE: [[STACK:%[0-9]+]] = inttoptr i64 [[STACK_VAL_ALIGNED]] to i8*
|
2013-01-31 20:13:10 +08:00
|
|
|
// CHECK: [[FROMSTACK_ADDR:%[a-z_0-9]+]] = bitcast i8* [[STACK]] to i32*
|
|
|
|
// CHECK: br label %[[VAARG_END]]
|
|
|
|
|
|
|
|
// CHECK: [[VAARG_END]]
|
|
|
|
// CHECK: [[ADDR:%[a-z._0-9]+]] = phi i32* [ [[FROMREG_ADDR]], %[[VAARG_IN_REG]] ], [ [[FROMSTACK_ADDR]], %[[VAARG_ON_STACK]] ]
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[RESULT:%[a-z_0-9]+]] = load i32, i32* [[ADDR]]
|
2013-01-31 20:13:10 +08:00
|
|
|
// CHECK: ret i32 [[RESULT]]
|
|
|
|
}
|
|
|
|
|
|
|
|
__int128 aligned_int(void) {
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define i128 @aligned_int
|
2013-01-31 20:13:10 +08:00
|
|
|
return va_arg(the_list, __int128);
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[GR_OFFS:%[a-z_0-9]+]] = load i32, i32* getelementptr inbounds (%struct.__va_list* @the_list, i32 0, i32 3)
|
2013-01-31 20:13:10 +08:00
|
|
|
// CHECK: [[EARLY_ONSTACK:%[a-z_0-9]+]] = icmp sge i32 [[GR_OFFS]], 0
|
|
|
|
// CHECK: br i1 [[EARLY_ONSTACK]], label %[[VAARG_ON_STACK:[a-z_.0-9]+]], label %[[VAARG_MAYBE_REG:[a-z_.0-9]+]]
|
|
|
|
|
|
|
|
// CHECK: [[VAARG_MAYBE_REG]]
|
|
|
|
// CHECK: [[ALIGN_REGOFFS:%[a-z_0-9]+]] = add i32 [[GR_OFFS]], 15
|
|
|
|
// CHECK: [[ALIGNED_REGOFFS:%[a-z_0-9]+]] = and i32 [[ALIGN_REGOFFS]], -16
|
|
|
|
// CHECK: [[NEW_REG_OFFS:%[a-z_0-9]+]] = add i32 [[ALIGNED_REGOFFS]], 16
|
|
|
|
// CHECK: store i32 [[NEW_REG_OFFS]], i32* getelementptr inbounds (%struct.__va_list* @the_list, i32 0, i32 3)
|
|
|
|
// CHECK: [[INREG:%[a-z_0-9]+]] = icmp sle i32 [[NEW_REG_OFFS]], 0
|
|
|
|
// CHECK: br i1 [[INREG]], label %[[VAARG_IN_REG:[a-z_.0-9]+]], label %[[VAARG_ON_STACK]]
|
|
|
|
|
|
|
|
// CHECK: [[VAARG_IN_REG]]
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[REG_TOP:%[a-z_0-9]+]] = load i8*, i8** getelementptr inbounds (%struct.__va_list* @the_list, i32 0, i32 1)
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK: [[REG_ADDR:%[a-z_0-9]+]] = getelementptr i8, i8* [[REG_TOP]], i32 [[ALIGNED_REGOFFS]]
|
2013-01-31 20:13:10 +08:00
|
|
|
// CHECK: [[FROMREG_ADDR:%[a-z_0-9]+]] = bitcast i8* [[REG_ADDR]] to i128*
|
|
|
|
// CHECK: br label %[[VAARG_END:[a-z._0-9]+]]
|
|
|
|
|
|
|
|
// CHECK: [[VAARG_ON_STACK]]
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[STACK:%[a-z_0-9]+]] = load i8*, i8** getelementptr inbounds (%struct.__va_list* @the_list, i32 0, i32 0)
|
2013-01-31 20:13:10 +08:00
|
|
|
// CHECK: [[STACKINT:%[a-z_0-9]+]] = ptrtoint i8* [[STACK]] to i64
|
|
|
|
// CHECK: [[ALIGN_STACK:%[a-z_0-9]+]] = add i64 [[STACKINT]], 15
|
|
|
|
// CHECK: [[ALIGNED_STACK_INT:%[a-z_0-9]+]] = and i64 [[ALIGN_STACK]], -16
|
|
|
|
// CHECK: [[ALIGNED_STACK_PTR:%[a-z_0-9]+]] = inttoptr i64 [[ALIGNED_STACK_INT]] to i8*
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK: [[NEW_STACK:%[a-z_0-9]+]] = getelementptr i8, i8* [[ALIGNED_STACK_PTR]], i32 16
|
2013-01-31 20:13:10 +08:00
|
|
|
// CHECK: store i8* [[NEW_STACK]], i8** getelementptr inbounds (%struct.__va_list* @the_list, i32 0, i32 0)
|
|
|
|
// CHECK: [[FROMSTACK_ADDR:%[a-z_0-9]+]] = bitcast i8* [[ALIGNED_STACK_PTR]] to i128*
|
|
|
|
// CHECK: br label %[[VAARG_END]]
|
|
|
|
|
|
|
|
// CHECK: [[VAARG_END]]
|
|
|
|
// CHECK: [[ADDR:%[a-z._0-9]+]] = phi i128* [ [[FROMREG_ADDR]], %[[VAARG_IN_REG]] ], [ [[FROMSTACK_ADDR]], %[[VAARG_ON_STACK]] ]
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[RESULT:%[a-z_0-9]+]] = load i128, i128* [[ADDR]]
|
2013-01-31 20:13:10 +08:00
|
|
|
// CHECK: ret i128 [[RESULT]]
|
|
|
|
}
|
|
|
|
|
|
|
|
struct bigstruct {
|
|
|
|
int a[10];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct bigstruct simple_indirect(void) {
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @simple_indirect
|
2013-01-31 20:13:10 +08:00
|
|
|
return va_arg(the_list, struct bigstruct);
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[GR_OFFS:%[a-z_0-9]+]] = load i32, i32* getelementptr inbounds (%struct.__va_list* @the_list, i32 0, i32 3)
|
2013-01-31 20:13:10 +08:00
|
|
|
// CHECK: [[EARLY_ONSTACK:%[a-z_0-9]+]] = icmp sge i32 [[GR_OFFS]], 0
|
|
|
|
// CHECK: br i1 [[EARLY_ONSTACK]], label %[[VAARG_ON_STACK:[a-z_.0-9]+]], label %[[VAARG_MAYBE_REG:[a-z_.0-9]+]]
|
|
|
|
|
|
|
|
// CHECK: [[VAARG_MAYBE_REG]]
|
|
|
|
// CHECK-NOT: and i32
|
|
|
|
// CHECK: [[NEW_REG_OFFS:%[a-z_0-9]+]] = add i32 [[GR_OFFS]], 8
|
|
|
|
// CHECK: store i32 [[NEW_REG_OFFS]], i32* getelementptr inbounds (%struct.__va_list* @the_list, i32 0, i32 3)
|
|
|
|
// CHECK: [[INREG:%[a-z_0-9]+]] = icmp sle i32 [[NEW_REG_OFFS]], 0
|
|
|
|
// CHECK: br i1 [[INREG]], label %[[VAARG_IN_REG:[a-z_.0-9]+]], label %[[VAARG_ON_STACK]]
|
|
|
|
|
|
|
|
// CHECK: [[VAARG_IN_REG]]
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[REG_TOP:%[a-z_0-9]+]] = load i8*, i8** getelementptr inbounds (%struct.__va_list* @the_list, i32 0, i32 1)
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK: [[REG_ADDR:%[a-z_0-9]+]] = getelementptr i8, i8* [[REG_TOP]], i32 [[GR_OFFS]]
|
2013-01-31 20:13:10 +08:00
|
|
|
// CHECK: [[FROMREG_ADDR:%[a-z_0-9]+]] = bitcast i8* [[REG_ADDR]] to %struct.bigstruct**
|
|
|
|
// CHECK: br label %[[VAARG_END:[a-z._0-9]+]]
|
|
|
|
|
|
|
|
// CHECK: [[VAARG_ON_STACK]]
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[STACK:%[a-z_0-9]+]] = load i8*, i8** getelementptr inbounds (%struct.__va_list* @the_list, i32 0, i32 0)
|
2013-01-31 20:13:10 +08:00
|
|
|
// CHECK-NOT: and i64
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK: [[NEW_STACK:%[a-z_0-9]+]] = getelementptr i8, i8* [[STACK]], i32 8
|
2013-01-31 20:13:10 +08:00
|
|
|
// CHECK: store i8* [[NEW_STACK]], i8** getelementptr inbounds (%struct.__va_list* @the_list, i32 0, i32 0)
|
|
|
|
// CHECK: [[FROMSTACK_ADDR:%[a-z_0-9]+]] = bitcast i8* [[STACK]] to %struct.bigstruct**
|
|
|
|
// CHECK: br label %[[VAARG_END]]
|
|
|
|
|
|
|
|
// CHECK: [[VAARG_END]]
|
|
|
|
// CHECK: [[ADDR:%[a-z._0-9]+]] = phi %struct.bigstruct** [ [[FROMREG_ADDR]], %[[VAARG_IN_REG]] ], [ [[FROMSTACK_ADDR]], %[[VAARG_ON_STACK]] ]
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: load %struct.bigstruct*, %struct.bigstruct** [[ADDR]]
|
2013-01-31 20:13:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
struct aligned_bigstruct {
|
|
|
|
float a;
|
|
|
|
long double b;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct aligned_bigstruct simple_aligned_indirect(void) {
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @simple_aligned_indirect
|
2013-01-31 20:13:10 +08:00
|
|
|
return va_arg(the_list, struct aligned_bigstruct);
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[GR_OFFS:%[a-z_0-9]+]] = load i32, i32* getelementptr inbounds (%struct.__va_list* @the_list, i32 0, i32 3)
|
2013-01-31 20:13:10 +08:00
|
|
|
// CHECK: [[EARLY_ONSTACK:%[a-z_0-9]+]] = icmp sge i32 [[GR_OFFS]], 0
|
|
|
|
// CHECK: br i1 [[EARLY_ONSTACK]], label %[[VAARG_ON_STACK:[a-z_.0-9]+]], label %[[VAARG_MAYBE_REG:[a-z_.0-9]+]]
|
|
|
|
|
|
|
|
// CHECK: [[VAARG_MAYBE_REG]]
|
|
|
|
// CHECK: [[NEW_REG_OFFS:%[a-z_0-9]+]] = add i32 [[GR_OFFS]], 8
|
|
|
|
// CHECK: store i32 [[NEW_REG_OFFS]], i32* getelementptr inbounds (%struct.__va_list* @the_list, i32 0, i32 3)
|
|
|
|
// CHECK: [[INREG:%[a-z_0-9]+]] = icmp sle i32 [[NEW_REG_OFFS]], 0
|
|
|
|
// CHECK: br i1 [[INREG]], label %[[VAARG_IN_REG:[a-z_.0-9]+]], label %[[VAARG_ON_STACK]]
|
|
|
|
|
|
|
|
// CHECK: [[VAARG_IN_REG]]
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[REG_TOP:%[a-z_0-9]+]] = load i8*, i8** getelementptr inbounds (%struct.__va_list* @the_list, i32 0, i32 1)
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK: [[REG_ADDR:%[a-z_0-9]+]] = getelementptr i8, i8* [[REG_TOP]], i32 [[GR_OFFS]]
|
2013-01-31 20:13:10 +08:00
|
|
|
// CHECK: [[FROMREG_ADDR:%[a-z_0-9]+]] = bitcast i8* [[REG_ADDR]] to %struct.aligned_bigstruct**
|
|
|
|
// CHECK: br label %[[VAARG_END:[a-z._0-9]+]]
|
|
|
|
|
|
|
|
// CHECK: [[VAARG_ON_STACK]]
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[STACK:%[a-z_0-9]+]] = load i8*, i8** getelementptr inbounds (%struct.__va_list* @the_list, i32 0, i32 0)
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK: [[NEW_STACK:%[a-z_0-9]+]] = getelementptr i8, i8* [[STACK]], i32 8
|
2013-01-31 20:13:10 +08:00
|
|
|
// CHECK: store i8* [[NEW_STACK]], i8** getelementptr inbounds (%struct.__va_list* @the_list, i32 0, i32 0)
|
|
|
|
// CHECK: [[FROMSTACK_ADDR:%[a-z_0-9]+]] = bitcast i8* [[STACK]] to %struct.aligned_bigstruct**
|
|
|
|
// CHECK: br label %[[VAARG_END]]
|
|
|
|
|
|
|
|
// CHECK: [[VAARG_END]]
|
|
|
|
// CHECK: [[ADDR:%[a-z._0-9]+]] = phi %struct.aligned_bigstruct** [ [[FROMREG_ADDR]], %[[VAARG_IN_REG]] ], [ [[FROMSTACK_ADDR]], %[[VAARG_ON_STACK]] ]
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: load %struct.aligned_bigstruct*, %struct.aligned_bigstruct** [[ADDR]]
|
2013-01-31 20:13:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
double simple_double(void) {
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define double @simple_double
|
2013-01-31 20:13:10 +08:00
|
|
|
return va_arg(the_list, double);
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[VR_OFFS:%[a-z_0-9]+]] = load i32, i32* getelementptr inbounds (%struct.__va_list* @the_list, i32 0, i32 4)
|
2013-01-31 20:13:10 +08:00
|
|
|
// CHECK: [[EARLY_ONSTACK:%[a-z_0-9]+]] = icmp sge i32 [[VR_OFFS]], 0
|
2014-03-15 00:30:06 +08:00
|
|
|
// CHECK: br i1 [[EARLY_ONSTACK]], label %[[VAARG_ON_STACK:[a-z_.0-9]+]], label %[[VAARG_MAYBE_REG]]
|
2013-01-31 20:13:10 +08:00
|
|
|
|
|
|
|
// CHECK: [[VAARG_MAYBE_REG]]
|
|
|
|
// CHECK: [[NEW_REG_OFFS:%[a-z_0-9]+]] = add i32 [[VR_OFFS]], 16
|
|
|
|
// CHECK: store i32 [[NEW_REG_OFFS]], i32* getelementptr inbounds (%struct.__va_list* @the_list, i32 0, i32 4)
|
|
|
|
// CHECK: [[INREG:%[a-z_0-9]+]] = icmp sle i32 [[NEW_REG_OFFS]], 0
|
|
|
|
// CHECK: br i1 [[INREG]], label %[[VAARG_IN_REG:[a-z_.0-9]+]], label %[[VAARG_ON_STACK]]
|
|
|
|
|
|
|
|
// CHECK: [[VAARG_IN_REG]]
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[REG_TOP:%[a-z_0-9]+]] = load i8*, i8** getelementptr inbounds (%struct.__va_list* @the_list, i32 0, i32 2)
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK: [[REG_ADDR:%[a-z_0-9]+]] = getelementptr i8, i8* [[REG_TOP]], i32 [[VR_OFFS]]
|
2014-03-14 19:51:06 +08:00
|
|
|
// CHECK-BE: [[REG_ADDR_VAL:%[0-9]+]] = ptrtoint i8* [[REG_ADDR]] to i64
|
2014-03-15 00:30:06 +08:00
|
|
|
// CHECK-BE: [[REG_ADDR_VAL_ALIGNED:%[a-z_0-9]*]] = add i64 [[REG_ADDR_VAL]], 8
|
2014-03-14 19:51:06 +08:00
|
|
|
// CHECK-BE: [[REG_ADDR:%[0-9]+]] = inttoptr i64 [[REG_ADDR_VAL_ALIGNED]] to i8*
|
2013-01-31 20:13:10 +08:00
|
|
|
// CHECK: [[FROMREG_ADDR:%[a-z_0-9]+]] = bitcast i8* [[REG_ADDR]] to double*
|
2014-03-15 00:30:06 +08:00
|
|
|
// CHECK: br label %[[VAARG_END:[a-z._0-9]+]]
|
2013-01-31 20:13:10 +08:00
|
|
|
|
|
|
|
// CHECK: [[VAARG_ON_STACK]]
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[STACK:%[a-z_0-9]+]] = load i8*, i8** getelementptr inbounds (%struct.__va_list* @the_list, i32 0, i32 0)
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK: [[NEW_STACK:%[a-z_0-9]+]] = getelementptr i8, i8* [[STACK]], i32 8
|
2013-01-31 20:13:10 +08:00
|
|
|
// CHECK: store i8* [[NEW_STACK]], i8** getelementptr inbounds (%struct.__va_list* @the_list, i32 0, i32 0)
|
|
|
|
// CHECK: [[FROMSTACK_ADDR:%[a-z_0-9]+]] = bitcast i8* [[STACK]] to double*
|
|
|
|
// CHECK: br label %[[VAARG_END]]
|
|
|
|
|
|
|
|
// CHECK: [[VAARG_END]]
|
|
|
|
// CHECK: [[ADDR:%[a-z._0-9]+]] = phi double* [ [[FROMREG_ADDR]], %[[VAARG_IN_REG]] ], [ [[FROMSTACK_ADDR]], %[[VAARG_ON_STACK]] ]
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[RESULT:%[a-z_0-9]+]] = load double, double* [[ADDR]]
|
2013-01-31 20:13:10 +08:00
|
|
|
// CHECK: ret double [[RESULT]]
|
|
|
|
}
|
|
|
|
|
|
|
|
struct hfa {
|
|
|
|
float a, b;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct hfa simple_hfa(void) {
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define %struct.hfa @simple_hfa
|
2013-01-31 20:13:10 +08:00
|
|
|
return va_arg(the_list, struct hfa);
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[VR_OFFS:%[a-z_0-9]+]] = load i32, i32* getelementptr inbounds (%struct.__va_list* @the_list, i32 0, i32 4)
|
2013-01-31 20:13:10 +08:00
|
|
|
// CHECK: [[EARLY_ONSTACK:%[a-z_0-9]+]] = icmp sge i32 [[VR_OFFS]], 0
|
|
|
|
// CHECK: br i1 [[EARLY_ONSTACK]], label %[[VAARG_ON_STACK:[a-z_.0-9]+]], label %[[VAARG_MAYBE_REG:[a-z_.0-9]+]]
|
|
|
|
|
|
|
|
// CHECK: [[VAARG_MAYBE_REG]]
|
|
|
|
// CHECK: [[NEW_REG_OFFS:%[a-z_0-9]+]] = add i32 [[VR_OFFS]], 32
|
|
|
|
// CHECK: store i32 [[NEW_REG_OFFS]], i32* getelementptr inbounds (%struct.__va_list* @the_list, i32 0, i32 4)
|
|
|
|
// CHECK: [[INREG:%[a-z_0-9]+]] = icmp sle i32 [[NEW_REG_OFFS]], 0
|
|
|
|
// CHECK: br i1 [[INREG]], label %[[VAARG_IN_REG:[a-z_.0-9]+]], label %[[VAARG_ON_STACK]]
|
|
|
|
|
|
|
|
// CHECK: [[VAARG_IN_REG]]
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[REG_TOP:%[a-z_0-9]+]] = load i8*, i8** getelementptr inbounds (%struct.__va_list* @the_list, i32 0, i32 2)
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK: [[FIRST_REG:%[a-z_0-9]+]] = getelementptr i8, i8* [[REG_TOP]], i32 [[VR_OFFS]]
|
|
|
|
// CHECK-LE: [[EL_ADDR:%[a-z_0-9]+]] = getelementptr i8, i8* [[FIRST_REG]], i32 0
|
|
|
|
// CHECK-BE: [[EL_ADDR:%[a-z_0-9]+]] = getelementptr i8, i8* [[FIRST_REG]], i32 12
|
2013-01-31 20:13:10 +08:00
|
|
|
// CHECK: [[EL_TYPED:%[a-z_0-9]+]] = bitcast i8* [[EL_ADDR]] to float*
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK: [[EL_TMPADDR:%[a-z_0-9]+]] = getelementptr inbounds [2 x float], [2 x float]* %[[TMP_HFA:[a-z_.0-9]+]], i32 0, i32 0
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[EL:%[a-z_0-9]+]] = load float, float* [[EL_TYPED]]
|
2013-01-31 20:13:10 +08:00
|
|
|
// CHECK: store float [[EL]], float* [[EL_TMPADDR]]
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-LE: [[EL_ADDR:%[a-z_0-9]+]] = getelementptr i8, i8* [[FIRST_REG]], i32 16
|
|
|
|
// CHECK-BE: [[EL_ADDR:%[a-z_0-9]+]] = getelementptr i8, i8* [[FIRST_REG]], i32 28
|
2013-01-31 20:13:10 +08:00
|
|
|
// CHECK: [[EL_TYPED:%[a-z_0-9]+]] = bitcast i8* [[EL_ADDR]] to float*
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK: [[EL_TMPADDR:%[a-z_0-9]+]] = getelementptr inbounds [2 x float], [2 x float]* %[[TMP_HFA]], i32 0, i32 1
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[EL:%[a-z_0-9]+]] = load float, float* [[EL_TYPED]]
|
2013-01-31 20:13:10 +08:00
|
|
|
// CHECK: store float [[EL]], float* [[EL_TMPADDR]]
|
|
|
|
// CHECK: [[FROMREG_ADDR:%[a-z_0-9]+]] = bitcast [2 x float]* %[[TMP_HFA]] to %struct.hfa*
|
|
|
|
// CHECK: br label %[[VAARG_END:[a-z_.0-9]+]]
|
|
|
|
|
|
|
|
// CHECK: [[VAARG_ON_STACK]]
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[STACK:%[a-z_0-9]+]] = load i8*, i8** getelementptr inbounds (%struct.__va_list* @the_list, i32 0, i32 0)
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK: [[NEW_STACK:%[a-z_0-9]+]] = getelementptr i8, i8* [[STACK]], i32 8
|
2013-01-31 20:13:10 +08:00
|
|
|
// CHECK: store i8* [[NEW_STACK]], i8** getelementptr inbounds (%struct.__va_list* @the_list, i32 0, i32 0)
|
|
|
|
// CHECK: [[FROMSTACK_ADDR:%[a-z_0-9]+]] = bitcast i8* [[STACK]] to %struct.hfa*
|
|
|
|
// CHECK: br label %[[VAARG_END]]
|
|
|
|
|
|
|
|
// CHECK: [[VAARG_END]]
|
|
|
|
// CHECK: [[ADDR:%[a-z._0-9]+]] = phi %struct.hfa* [ [[FROMREG_ADDR]], %[[VAARG_IN_REG]] ], [ [[FROMSTACK_ADDR]], %[[VAARG_ON_STACK]] ]
|
|
|
|
}
|
|
|
|
|
|
|
|
void check_start(int n, ...) {
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @check_start(i32 %n, ...)
|
2013-01-31 20:13:10 +08:00
|
|
|
|
|
|
|
va_list the_list;
|
|
|
|
va_start(the_list, n);
|
|
|
|
// CHECK: [[THE_LIST:%[a-z_0-9]+]] = alloca %struct.__va_list
|
|
|
|
// CHECK: [[VOIDP_THE_LIST:%[a-z_0-9]+]] = bitcast %struct.__va_list* [[THE_LIST]] to i8*
|
|
|
|
// CHECK: call void @llvm.va_start(i8* [[VOIDP_THE_LIST]])
|
|
|
|
}
|
|
|
|
|
|
|
|
|