[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / CodeGen / builtin-memfns.c
bloba9f62faff22ade68c1525c16d28103d23b70cf7c
1 // RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm < %s| FileCheck %s
3 typedef __WCHAR_TYPE__ wchar_t;
4 typedef __SIZE_TYPE__ size_t;
6 void *memcpy(void *, void const *, size_t);
7 void *memccpy(void *, void const *, int, size_t);
9 // CHECK: @test1
10 // CHECK: call void @llvm.memset.p0.i32
11 // CHECK: call void @llvm.memset.p0.i32
12 // CHECK: call void @llvm.memcpy.p0.p0.i32
13 // CHECK: call void @llvm.memmove.p0.p0.i32
14 // CHECK-NOT: __builtin
15 // CHECK: ret
16 int test1(int argc, char **argv) {
17 unsigned char a = 0x11223344;
18 unsigned char b = 0x11223344;
19 __builtin_bzero(&a, sizeof(a));
20 __builtin_memset(&a, 0, sizeof(a));
21 __builtin_memcpy(&a, &b, sizeof(a));
22 __builtin_memmove(&a, &b, sizeof(a));
23 return 0;
26 // rdar://9289468
28 // CHECK: @test2
29 // CHECK: call void @llvm.memcpy.p0.p0.i32
30 char* test2(char* a, char* b) {
31 return __builtin_memcpy(a, b, 4);
34 // CHECK: @test3
35 // CHECK: call void @llvm.memset
36 void test3(char *P) {
37 __builtin___memset_chk(P, 42, 128, 128);
40 // CHECK: @test4
41 // CHECK: call void @llvm.memcpy
42 void test4(char *P, char *Q) {
43 __builtin___memcpy_chk(P, Q, 128, 128);
46 // CHECK: @test5
47 // CHECK: call void @llvm.memmove
48 void test5(char *P, char *Q) {
49 __builtin___memmove_chk(P, Q, 128, 128);
52 // CHECK: @test6
53 // CHECK: call void @llvm.memcpy
54 int test6(char *X) {
55 return __builtin___memcpy_chk(X, X, 42, 42) != 0;
58 // CHECK: @test7
59 // PR12094
60 int test7(int *p) {
61 struct snd_pcm_hw_params_t* hwparams; // incomplete type.
63 // CHECK: call void @llvm.memset{{.*}} align 4 {{.*}}256, i1 false)
64 __builtin_memset(p, 0, 256); // Should be alignment = 4
66 // CHECK: call void @llvm.memset{{.*}} align 1 {{.*}}256, i1 false)
67 __builtin_memset((char*)p, 0, 256); // Should be alignment = 1
69 __builtin_memset(hwparams, 0, 256); // No crash alignment = 1
70 // CHECK: call void @llvm.memset{{.*}} align 1{{.*}}256, i1 false)
73 // <rdar://problem/11314941>
74 // Make sure we don't over-estimate the alignment of fields of
75 // packed structs.
76 struct PS {
77 int modes[4];
78 } __attribute__((packed));
79 struct PS ps;
80 void test8(int *arg) {
81 // CHECK: @test8
82 // CHECK: call void @llvm.memcpy{{.*}} align 4 {{.*}} align 1 {{.*}} 16, i1 false)
83 __builtin_memcpy(arg, ps.modes, sizeof(struct PS));
86 __attribute((aligned(16))) int x[4], y[4];
87 void test9(void) {
88 // CHECK: @test9
89 // CHECK: call void @llvm.memcpy{{.*}} align 16 {{.*}} align 16 {{.*}} 16, i1 false)
90 __builtin_memcpy(x, y, sizeof(y));
93 wchar_t dest;
94 wchar_t src;
96 // CHECK-LABEL: @test10
97 // FIXME: Consider lowering these to llvm.memcpy / llvm.memmove.
98 void test10(void) {
99 // CHECK: call ptr @wmemcpy(ptr noundef @dest, ptr noundef @src, i32 noundef 4)
100 __builtin_wmemcpy(&dest, &src, 4);
102 // CHECK: call ptr @wmemmove(ptr noundef @dest, ptr noundef @src, i32 noundef 4)
103 __builtin_wmemmove(&dest, &src, 4);
106 // CHECK-LABEL: @test11
107 void test11(void) {
108 typedef struct { int a; } b;
109 int d;
110 b e;
111 // CHECK: call void @llvm.memcpy{{.*}}(
112 memcpy(&d, (char *)&e.a, sizeof(e));
115 // CHECK-LABEL: @test12
116 extern char dest_array[];
117 extern char src_array[];
118 void test12(void) {
119 // CHECK: call void @llvm.memcpy{{.*}}(
120 memcpy(&dest_array, &dest_array, 2);
123 // CHECK-LABEL: @test13
124 void test13(char *d, char *s, int c, size_t n) {
125 // CHECK: call ptr @memccpy
126 memccpy(d, s, c, n);