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);
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
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
));
29 // CHECK: call void @llvm.memcpy.p0.p0.i32
30 char* test2(char* a
, char* b
) {
31 return __builtin_memcpy(a
, b
, 4);
35 // CHECK: call void @llvm.memset
37 __builtin___memset_chk(P
, 42, 128, 128);
41 // CHECK: call void @llvm.memcpy
42 void test4(char *P
, char *Q
) {
43 __builtin___memcpy_chk(P
, Q
, 128, 128);
47 // CHECK: call void @llvm.memmove
48 void test5(char *P
, char *Q
) {
49 __builtin___memmove_chk(P
, Q
, 128, 128);
53 // CHECK: call void @llvm.memcpy
55 return __builtin___memcpy_chk(X
, X
, 42, 42) != 0;
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
78 } __attribute__((packed
));
80 void test8(int *arg
) {
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];
89 // CHECK: call void @llvm.memcpy{{.*}} align 16 {{.*}} align 16 {{.*}} 16, i1 false)
90 __builtin_memcpy(x
, y
, sizeof(y
));
96 // CHECK-LABEL: @test10
97 // FIXME: Consider lowering these to llvm.memcpy / llvm.memmove.
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
108 typedef struct { int a
; } b
;
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
[];
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