summaryrefslogtreecommitdiffstats
path: root/clang/test/CodeGen/xcore-abi.c
diff options
context:
space:
mode:
authorRobert Lytton <robert@xmos.com>2013-08-19 09:46:39 +0000
committerRobert Lytton <robert@xmos.com>2013-08-19 09:46:39 +0000
commit7d1db15ae14f093216b17877127016db9b04b5c0 (patch)
tree39bc8de345ffefb2622b0a65740bcb0124ad9be8 /clang/test/CodeGen/xcore-abi.c
parenta7d1d865e50a76ebabb3bab61f48b91350470d32 (diff)
downloadbcm5719-llvm-7d1db15ae14f093216b17877127016db9b04b5c0.tar.gz
bcm5719-llvm-7d1db15ae14f093216b17877127016db9b04b5c0.zip
XCore target: Add target specific EmitVAArg
This is so aggregates can be passed as var args too. llvm-svn: 188664
Diffstat (limited to 'clang/test/CodeGen/xcore-abi.c')
-rw-r--r--clang/test/CodeGen/xcore-abi.c80
1 files changed, 72 insertions, 8 deletions
diff --git a/clang/test/CodeGen/xcore-abi.c b/clang/test/CodeGen/xcore-abi.c
index 6c325262dc8..16cf55d170b 100644
--- a/clang/test/CodeGen/xcore-abi.c
+++ b/clang/test/CodeGen/xcore-abi.c
@@ -9,22 +9,86 @@ int g1;
int g2 __attribute__((common));
#include <stdarg.h>
-struct x { int a; };
+struct x { int a[5]; };
+void f(void*);
void testva (int n, ...) {
+ // CHECK-LABEL: testva
va_list ap;
+ va_start(ap,n);
// CHECK: [[AP:%[a-z0-9]+]] = alloca i8*, align 4
+ // CHECK: [[AP1:%[a-z0-9]+]] = bitcast i8** [[AP]] to i8*
+ // CHECK: call void @llvm.va_start(i8* [[AP1]])
char* v1 = va_arg (ap, char*);
- // CHECK: va_arg i8** [[AP]], i8*
+ f(v1);
+ // CHECK: [[I:%[a-z0-9]+]] = load i8** [[AP]]
+ // CHECK: [[IN:%[a-z0-9]+]] = getelementptr i8* [[I]], i32 4
+ // CHECK: store i8* [[IN]], i8** [[AP]]
+ // CHECK: [[P:%[a-z0-9]+]] = bitcast i8* [[I]] to i8**
+ // CHECK: [[V1:%[a-z0-9]+]] = load i8** [[P]]
+ // CHECK: store i8* [[V1]], i8** [[V:%[a-z0-9]+]], align 4
+ // CHECK: [[V2:%[a-z0-9]+]] = load i8** [[V]], align 4
+ // CHECK: call void @f(i8* [[V2]])
- int v2 = va_arg (ap, int);
- // CHECK: va_arg i8** [[AP]], i32
+ char v2 = va_arg (ap, char);
+ f(&v2);
+ // CHECK: [[I:%[a-z0-9]+]] = load i8** [[AP]]
+ // CHECK: [[IN:%[a-z0-9]+]] = getelementptr i8* [[I]], i32 4
+ // CHECK: store i8* [[IN]], i8** [[AP]]
+ // CHECK: [[V1:%[a-z0-9]+]] = load i8* [[I]]
+ // CHECK: store i8 [[V1]], i8* [[V:%[a-z0-9]+]], align 1
+ // CHECK: call void @f(i8* [[V]])
- long long int v3 = va_arg (ap, long long int);
- // CHECK: va_arg i8** [[AP]], i64
+ int v3 = va_arg (ap, int);
+ f(&v3);
+ // CHECK: [[I:%[a-z0-9]+]] = load i8** [[AP]]
+ // CHECK: [[IN:%[a-z0-9]+]] = getelementptr i8* [[I]], i32 4
+ // CHECK: store i8* [[IN]], i8** [[AP]]
+ // CHECK: [[P:%[a-z0-9]+]] = bitcast i8* [[I]] to i32*
+ // CHECK: [[V1:%[a-z0-9]+]] = load i32* [[P]]
+ // CHECK: store i32 [[V1]], i32* [[V:%[a-z0-9]+]], align 4
+ // CHECK: [[V2:%[a-z0-9]+]] = bitcast i32* [[V]] to i8*
+ // CHECK: call void @f(i8* [[V2]])
- //struct x t = va_arg (ap, struct x);
- //cannot compile aggregate va_arg expressions yet
+ long long int v4 = va_arg (ap, long long int);
+ f(&v4);
+ // CHECK: [[I:%[a-z0-9]+]] = load i8** [[AP]]
+ // CHECK: [[IN:%[a-z0-9]+]] = getelementptr i8* [[I]], i32 4
+ // CHECK: store i8* [[IN]], i8** [[AP]]
+ // CHECK: [[P:%[a-z0-9]+]] = bitcast i8* [[I]] to i64*
+ // CHECK: [[V1:%[a-z0-9]+]] = load i64* [[P]]
+ // CHECK: store i64 [[V1]], i64* [[V:%[a-z0-9]+]], align 8
+ // CHECK:[[V2:%[a-z0-9]+]] = bitcast i64* [[V]] to i8*
+ // CHECK: call void @f(i8* [[V2]])
+
+ struct x v5 = va_arg (ap, struct x); // typical agregate type
+ f(&v5);
+ // CHECK: [[I:%[a-z0-9]+]] = load i8** [[AP]]
+ // CHECK: [[IN:%[a-z0-9]+]] = getelementptr i8* [[I]], i32 4
+ // CHECK: store i8* [[IN]], i8** [[AP]]
+ // CHECK: [[I2:%[a-z0-9]+]] = bitcast i8* [[I]] to %struct.x**
+ // CHECK: [[P:%[a-z0-9]+]] = load %struct.x** [[I2]]
+ // CHECK: [[V1:%[a-z0-9]+]] = bitcast %struct.x* [[V:%[a-z0-9]+]] to i8*
+ // CHECK: [[P1:%[a-z0-9]+]] = bitcast %struct.x* [[P]] to i8*
+ // CHECK: call void @llvm.memcpy.p0i8.p0i8.i32(i8* [[V1]], i8* [[P1]], i32 20, i32 4, i1 false)
+ // CHECK: [[V2:%[a-z0-9]+]] = bitcast %struct.x* [[V]] to i8*
+ // CHECK: call void @f(i8* [[V2]])
+
+ int* v6 = va_arg (ap, int[4]); // an unusual agregate type
+ f(v6);
+ // CHECK: [[I:%[a-z0-9]+]] = load i8** [[AP]]
+ // CHECK: [[IN:%[a-z0-9]+]] = getelementptr i8* [[I]], i32 4
+ // CHECK: store i8* [[IN]], i8** [[AP]]
+ // CHECK: [[I2:%[a-z0-9]+]] = bitcast i8* [[I]] to [4 x i32]**
+ // CHECK: [[P:%[a-z0-9]+]] = load [4 x i32]** [[I2]]
+ // CHECK: [[V1:%[a-z0-9]+]] = bitcast [4 x i32]* [[V0:%[a-z0-9]+]] to i8*
+ // CHECK: [[P1:%[a-z0-9]+]] = bitcast [4 x i32]* [[P]] to i8*
+ // CHECK: call void @llvm.memcpy.p0i8.p0i8.i32(i8* [[V1]], i8* [[P1]], i32 16, i32 4, i1 false)
+ // CHECK: [[V2:%[a-z0-9]+]] = getelementptr inbounds [4 x i32]* [[V0]], i32 0, i32 0
+ // CHECK: store i32* [[V2]], i32** [[V:%[a-z0-9]+]], align 4
+ // CHECK: [[V3:%[a-z0-9]+]] = load i32** [[V]], align 4
+ // CHECK: [[V4:%[a-z0-9]+]] = bitcast i32* [[V3]] to i8*
+ // CHECK: call void @f(i8* [[V4]])
}
void testbuiltin (void) {
OpenPOWER on IntegriCloud