| 1 |
// REQUIRES: xcore-registered-target |
| 2 |
// RUN: %clang_cc1 -triple xcore -verify %s |
| 3 |
_Static_assert(sizeof(long long) == 8, "sizeof long long is wrong"); |
| 4 |
_Static_assert(_Alignof(long long) == 4, "alignof long long is wrong"); |
| 5 |
|
| 6 |
_Static_assert(sizeof(double) == 8, "sizeof double is wrong"); |
| 7 |
_Static_assert(_Alignof(double) == 4, "alignof double is wrong"); |
| 8 |
|
| 9 |
// RUN: %clang_cc1 -triple xcore-unknown-unknown -fno-signed-char -fno-common -emit-llvm -o - %s | FileCheck %s |
| 10 |
|
| 11 |
// CHECK: target triple = "xcore-unknown-unknown" |
| 12 |
|
| 13 |
// CHECK: @cgx = external constant i32, section ".cp.rodata" |
| 14 |
extern const int cgx; |
| 15 |
int fcgx() { return cgx;} |
| 16 |
// CHECK: @g1 ={{.*}} global i32 0, align 4 |
| 17 |
int g1; |
| 18 |
// CHECK: @cg1 ={{.*}} constant i32 0, section ".cp.rodata", align 4 |
| 19 |
const int cg1; |
| 20 |
|
| 21 |
#include <stdarg.h> |
| 22 |
struct x { int a[5]; }; |
| 23 |
void f(void*); |
| 24 |
void testva (int n, ...) { |
| 25 |
// CHECK-LABEL: testva |
| 26 |
va_list ap; |
| 27 |
va_start(ap,n); |
| 28 |
// CHECK: [[AP:%[a-z0-9]+]] = alloca ptr, align 4 |
| 29 |
// CHECK: [[V5:%[a-z0-9]+]] = alloca %struct.x, align 4 |
| 30 |
// CHECK: [[TMP:%[a-z0-9.]+]] = alloca [4 x i32], align 4 |
| 31 |
// CHECK: call void @llvm.va_start.p0(ptr [[AP]]) |
| 32 |
|
| 33 |
char* v1 = va_arg (ap, char*); |
| 34 |
f(v1); |
| 35 |
// CHECK: [[I:%[a-z0-9]+]] = load ptr, ptr [[AP]] |
| 36 |
// CHECK: [[IN:%[a-z0-9]+]] = getelementptr inbounds i8, ptr [[I]], i32 4 |
| 37 |
// CHECK: store ptr [[IN]], ptr [[AP]] |
| 38 |
// CHECK: [[V1:%[a-z0-9]+]] = load ptr, ptr [[I]] |
| 39 |
// CHECK: store ptr [[V1]], ptr [[V:%[a-z0-9]+]], align 4 |
| 40 |
// CHECK: [[V2:%[a-z0-9]+]] = load ptr, ptr [[V]], align 4 |
| 41 |
// CHECK: call void @f(ptr noundef [[V2]]) |
| 42 |
|
| 43 |
char v2 = va_arg (ap, char); // expected-warning{{second argument to 'va_arg' is of promotable type 'char'}} |
| 44 |
f(&v2); |
| 45 |
// CHECK: [[I:%[a-z0-9]+]] = load ptr, ptr [[AP]] |
| 46 |
// CHECK: [[IN:%[a-z0-9]+]] = getelementptr inbounds i8, ptr [[I]], i32 4 |
| 47 |
// CHECK: store ptr [[IN]], ptr [[AP]] |
| 48 |
// CHECK: [[V1:%[a-z0-9]+]] = load i8, ptr [[I]] |
| 49 |
// CHECK: store i8 [[V1]], ptr [[V:%[a-z0-9]+]], align 1 |
| 50 |
// CHECK: call void @f(ptr noundef [[V]]) |
| 51 |
|
| 52 |
int v3 = va_arg (ap, int); |
| 53 |
f(&v3); |
| 54 |
// CHECK: [[I:%[a-z0-9]+]] = load ptr, ptr [[AP]] |
| 55 |
// CHECK: [[IN:%[a-z0-9]+]] = getelementptr inbounds i8, ptr [[I]], i32 4 |
| 56 |
// CHECK: store ptr [[IN]], ptr [[AP]] |
| 57 |
// CHECK: [[V1:%[a-z0-9]+]] = load i32, ptr [[I]] |
| 58 |
// CHECK: store i32 [[V1]], ptr [[V:%[a-z0-9]+]], align 4 |
| 59 |
// CHECK: call void @f(ptr noundef [[V]]) |
| 60 |
|
| 61 |
long long int v4 = va_arg (ap, long long int); |
| 62 |
f(&v4); |
| 63 |
// CHECK: [[I:%[a-z0-9]+]] = load ptr, ptr [[AP]] |
| 64 |
// CHECK: [[IN:%[a-z0-9]+]] = getelementptr inbounds i8, ptr [[I]], i32 8 |
| 65 |
// CHECK: store ptr [[IN]], ptr [[AP]] |
| 66 |
// CHECK: [[V1:%[a-z0-9]+]] = load i64, ptr [[I]] |
| 67 |
// CHECK: store i64 [[V1]], ptr [[V:%[a-z0-9]+]], align 4 |
| 68 |
// CHECK: call void @f(ptr noundef [[V]]) |
| 69 |
|
| 70 |
struct x v5 = va_arg (ap, struct x); // typical aggregate type |
| 71 |
f(&v5); |
| 72 |
// CHECK: [[I:%[a-z0-9]+]] = load ptr, ptr [[AP]] |
| 73 |
// CHECK: [[P:%[a-z0-9]+]] = load ptr, ptr [[I]] |
| 74 |
// CHECK: [[IN:%[a-z0-9]+]] = getelementptr inbounds i8, ptr [[I]], i32 4 |
| 75 |
// CHECK: store ptr [[IN]], ptr [[AP]] |
| 76 |
// CHECK: call void @llvm.memcpy.p0.p0.i32(ptr align 4 [[V5]], ptr align 4 [[P]], i32 20, i1 false) |
| 77 |
// CHECK: call void @f(ptr noundef [[V5]]) |
| 78 |
|
| 79 |
// an unusual aggregate type |
| 80 |
int* v6 = va_arg (ap, int[4]); // expected-warning{{second argument to 'va_arg' is of array type 'int[4]'}} |
| 81 |
f(v6); |
| 82 |
// CHECK: [[I:%[a-z0-9]+]] = load ptr, ptr [[AP]] |
| 83 |
// CHECK: [[P:%[a-z0-9]+]] = load ptr, ptr [[I]] |
| 84 |
// CHECK: [[IN:%[a-z0-9]+]] = getelementptr inbounds i8, ptr [[I]], i32 4 |
| 85 |
// CHECK: store ptr [[IN]], ptr [[AP]] |
| 86 |
// CHECK: call void @llvm.memcpy.p0.p0.i32(ptr align 4 [[TMP]], ptr align 4 [[P]], i32 16, i1 false) |
| 87 |
// CHECK: [[V2:%[a-z0-9]+]] = getelementptr inbounds [4 x i32], ptr [[TMP]], i32 0, i32 0 |
| 88 |
// CHECK: store ptr [[V2]], ptr [[V:%[a-z0-9]+]], align 4 |
| 89 |
// CHECK: [[V3:%[a-z0-9]+]] = load ptr, ptr [[V]], align 4 |
| 90 |
// CHECK: call void @f(ptr noundef [[V3]]) |
| 91 |
|
| 92 |
double v7 = va_arg (ap, double); |
| 93 |
f(&v7); |
| 94 |
// CHECK: [[I:%[a-z0-9]+]] = load ptr, ptr [[AP]] |
| 95 |
// CHECK: [[IN:%[a-z0-9]+]] = getelementptr inbounds i8, ptr [[I]], i32 8 |
| 96 |
// CHECK: store ptr [[IN]], ptr [[AP]] |
| 97 |
// CHECK: [[V1:%[a-z0-9]+]] = load double, ptr [[I]] |
| 98 |
// CHECK: store double [[V1]], ptr [[V:%[a-z0-9]+]], align 4 |
| 99 |
// CHECK: call void @f(ptr noundef [[V]]) |
| 100 |
} |
| 101 |
|
| 102 |
void testbuiltin (void) { |
| 103 |
// CHECK-LABEL: testbuiltin |
| 104 |
// CHECK: call i32 @llvm.xcore.getid() |
| 105 |
// CHECK: call i32 @llvm.xcore.getps(i32 {{%[a-z0-9]+}}) |
| 106 |
// CHECK: call i32 @llvm.xcore.bitrev(i32 {{%[a-z0-9]+}}) |
| 107 |
// CHECK: call void @llvm.xcore.setps(i32 {{%[a-z0-9]+}}, i32 {{%[a-z0-9]+}}) |
| 108 |
volatile int i = __builtin_getid(); |
| 109 |
volatile unsigned int ui = __builtin_getps(i); |
| 110 |
ui = __builtin_bitrev(ui); |
| 111 |
__builtin_setps(i,ui); |
| 112 |
|
| 113 |
// CHECK: store volatile i32 0, ptr {{%[a-z0-9]+}}, align 4 |
| 114 |
// CHECK: store volatile i32 1, ptr {{%[a-z0-9]+}}, align 4 |
| 115 |
// CHECK: store volatile i32 -1, ptr {{%[a-z0-9]+}}, align 4 |
| 116 |
volatile int res; |
| 117 |
res = __builtin_eh_return_data_regno(0); |
| 118 |
res = __builtin_eh_return_data_regno(1); |
| 119 |
res = __builtin_eh_return_data_regno(2); |
| 120 |
} |
| 121 |
|
| 122 |
// CHECK-LABEL: define{{.*}} zeroext i8 @testchar() |
| 123 |
// CHECK: ret i8 -1 |
| 124 |
char testchar (void) { |
| 125 |
return (char)-1; |
| 126 |
} |
| 127 |
|
| 128 |
// CHECK-NOT: frame-pointer |