Revert "[llvm] Improve llvm.objectsize computation by computing GEP, alloca and mallo...
[llvm-project.git] / clang / test / CodeGen / builtin-memfns.c
blob23c3c60b779b373213a692ddac0ead9e63f39ba3
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 // CHECK: @test2
27 // CHECK: call void @llvm.memcpy.p0.p0.i32
28 char* test2(char* a, char* b) {
29 return __builtin_memcpy(a, b, 4);
32 // CHECK: @test3
33 // CHECK: call void @llvm.memset
34 void test3(char *P) {
35 __builtin___memset_chk(P, 42, 128, 128);
38 // CHECK: @test4
39 // CHECK: call void @llvm.memcpy
40 void test4(char *P, char *Q) {
41 __builtin___memcpy_chk(P, Q, 128, 128);
44 // CHECK: @test5
45 // CHECK: call void @llvm.memmove
46 void test5(char *P, char *Q) {
47 __builtin___memmove_chk(P, Q, 128, 128);
50 // CHECK: @test6
51 // CHECK: call void @llvm.memcpy
52 int test6(char *X) {
53 return __builtin___memcpy_chk(X, X, 42, 42) != 0;
56 // CHECK: @test7
57 // PR12094
58 int test7(int *p) {
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
72 // packed structs.
73 struct PS {
74 int modes[4];
75 } __attribute__((packed));
76 struct PS ps;
77 void test8(int *arg) {
78 // CHECK: @test8
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];
84 void test9(void) {
85 // CHECK: @test9
86 // CHECK: call void @llvm.memcpy{{.*}} align 16 {{.*}} align 16 {{.*}} 16, i1 false)
87 __builtin_memcpy(x, y, sizeof(y));
90 wchar_t dest;
91 wchar_t src;
93 // CHECK-LABEL: @test10
94 // FIXME: Consider lowering these to llvm.memcpy / llvm.memmove.
95 void test10(void) {
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
104 void test11(void) {
105 typedef struct { int a; } b;
106 int d;
107 b e;
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[];
115 void test12(void) {
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
123 memccpy(d, s, c, n);