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
));
27 // CHECK: call void @llvm.memcpy.p0.p0.i32
28 char* test2(char* a
, char* b
) {
29 return __builtin_memcpy(a
, b
, 4);
33 // CHECK: call void @llvm.memset
35 __builtin___memset_chk(P
, 42, 128, 128);
39 // CHECK: call void @llvm.memcpy
40 void test4(char *P
, char *Q
) {
41 __builtin___memcpy_chk(P
, Q
, 128, 128);
45 // CHECK: call void @llvm.memmove
46 void test5(char *P
, char *Q
) {
47 __builtin___memmove_chk(P
, Q
, 128, 128);
51 // CHECK: call void @llvm.memcpy
53 return __builtin___memcpy_chk(X
, X
, 42, 42) != 0;
59 struct snd_pcm_hw_params_t
* hwparams
; // incomplete type.
61 // CHECK: call void @llvm.memset{{.*}} align 4 {{.*}}256, i1 false)
62 __builtin_memset(p
, 0, 256); // Should be alignment = 4
64 // CHECK: call void @llvm.memset{{.*}} align 1 {{.*}}256, i1 false)
65 __builtin_memset((char*)p
, 0, 256); // Should be alignment = 1
67 __builtin_memset(hwparams
, 0, 256); // No crash alignment = 1
68 // CHECK: call void @llvm.memset{{.*}} align 1{{.*}}256, i1 false)
71 // Make sure we don't over-estimate the alignment of fields of
75 } __attribute__((packed
));
77 void test8(int *arg
) {
79 // CHECK: call void @llvm.memcpy{{.*}} align 4 {{.*}} align 1 {{.*}} 16, i1 false)
80 __builtin_memcpy(arg
, ps
.modes
, sizeof(struct PS
));
83 __attribute((aligned(16))) int x
[4], y
[4];
86 // CHECK: call void @llvm.memcpy{{.*}} align 16 {{.*}} align 16 {{.*}} 16, i1 false)
87 __builtin_memcpy(x
, y
, sizeof(y
));
93 // CHECK-LABEL: @test10
94 // FIXME: Consider lowering these to llvm.memcpy / llvm.memmove.
96 // CHECK: call ptr @wmemcpy(ptr noundef @dest, ptr noundef @src, i32 noundef 4)
97 __builtin_wmemcpy(&dest
, &src
, 4);
99 // CHECK: call ptr @wmemmove(ptr noundef @dest, ptr noundef @src, i32 noundef 4)
100 __builtin_wmemmove(&dest
, &src
, 4);
103 // CHECK-LABEL: @test11
105 typedef struct { int a
; } b
;
108 // CHECK: call void @llvm.memcpy{{.*}}(
109 memcpy(&d
, (char *)&e
.a
, sizeof(e
));
112 // CHECK-LABEL: @test12
113 extern char dest_array
[];
114 extern char src_array
[];
116 // CHECK: call void @llvm.memcpy{{.*}}(
117 memcpy(&dest_array
, &dest_array
, 2);
120 // CHECK-LABEL: @test13
121 void test13(char *d
, char *s
, int c
, size_t n
) {
122 // CHECK: call ptr @memccpy