Mon P Wang | 3ecd785 | 2010-04-04 03:10:52 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm < %s| FileCheck %s |
Daniel Dunbar | 1caae95 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 2 | |
Chris Lattner | a5e5e0f | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 3 | // CHECK: @test1 |
Mon P Wang | 3ecd785 | 2010-04-04 03:10:52 +0000 | [diff] [blame] | 4 | // CHECK: call void @llvm.memset.p0i8.i32 |
| 5 | // CHECK: call void @llvm.memset.p0i8.i32 |
| 6 | // CHECK: call void @llvm.memcpy.p0i8.p0i8.i32 |
| 7 | // CHECK: call void @llvm.memmove.p0i8.p0i8.i32 |
| 8 | // CHECK-NOT: __builtin |
| 9 | // CHECK: ret |
Chris Lattner | a5e5e0f | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 10 | int test1(int argc, char **argv) { |
Daniel Dunbar | 1caae95 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 11 | unsigned char a = 0x11223344; |
| 12 | unsigned char b = 0x11223344; |
| 13 | __builtin_bzero(&a, sizeof(a)); |
| 14 | __builtin_memset(&a, 0, sizeof(a)); |
| 15 | __builtin_memcpy(&a, &b, sizeof(a)); |
| 16 | __builtin_memmove(&a, &b, sizeof(a)); |
| 17 | return 0; |
| 18 | } |
Chris Lattner | a5e5e0f | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 19 | |
| 20 | // rdar://9289468 |
| 21 | |
| 22 | // CHECK: @test2 |
| 23 | // CHECK: call void @llvm.memcpy.p0i8.p0i8.i32 |
| 24 | char* test2(char* a, char* b) { |
| 25 | return __builtin_memcpy(a, b, 4); |
| 26 | } |
| 27 | |
| 28 | // CHECK: @test3 |
| 29 | // CHECK: call void @llvm.memset |
| 30 | void test3(char *P) { |
| 31 | __builtin___memset_chk(P, 42, 128, 128); |
| 32 | } |
| 33 | |
| 34 | // CHECK: @test4 |
| 35 | // CHECK: call void @llvm.memcpy |
| 36 | void test4(char *P, char *Q) { |
| 37 | __builtin___memcpy_chk(P, Q, 128, 128); |
| 38 | } |
| 39 | |
| 40 | // CHECK: @test5 |
| 41 | // CHECK: call void @llvm.memmove |
| 42 | void test5(char *P, char *Q) { |
| 43 | __builtin___memmove_chk(P, Q, 128, 128); |
| 44 | } |
Chris Lattner | 42f681b | 2011-04-20 23:14:50 +0000 | [diff] [blame] | 45 | |
| 46 | // CHECK: @test6 |
| 47 | // CHECK: call void @llvm.memcpy |
| 48 | int test6(char *X) { |
| 49 | return __builtin___memcpy_chk(X, X, 42, 42) != 0; |
| 50 | } |
Chris Lattner | d6e7356 | 2012-03-04 00:52:12 +0000 | [diff] [blame] | 51 | |
| 52 | // CHECK: @test7 |
| 53 | // PR12094 |
| 54 | int test7(int *p) { |
Chris Lattner | 5bd20ff | 2012-03-04 00:56:24 +0000 | [diff] [blame] | 55 | struct snd_pcm_hw_params_t* hwparams; // incomplete type. |
| 56 | |
Chris Lattner | d6e7356 | 2012-03-04 00:52:12 +0000 | [diff] [blame] | 57 | // CHECK: call void @llvm.memset{{.*}}256, i32 4, i1 false) |
| 58 | __builtin_memset(p, 0, 256); // Should be alignment = 4 |
Chris Lattner | 5bd20ff | 2012-03-04 00:56:24 +0000 | [diff] [blame] | 59 | |
| 60 | // CHECK: call void @llvm.memset{{.*}}256, i32 1, i1 false) |
| 61 | __builtin_memset((char*)p, 0, 256); // Should be alignment = 1 |
Chris Lattner | d6e7356 | 2012-03-04 00:52:12 +0000 | [diff] [blame] | 62 | |
| 63 | __builtin_memset(hwparams, 0, 256); // No crash alignment = 1 |
| 64 | // CHECK: call void @llvm.memset{{.*}}256, i32 1, i1 false) |
| 65 | } |
Eli Friedman | ea93e40 | 2012-08-23 03:10:17 +0000 | [diff] [blame^] | 66 | |
| 67 | // <rdar://problem/11314941> |
| 68 | // Make sure we don't over-estimate the alignment of fields of |
| 69 | // packed structs. |
| 70 | struct PS { |
| 71 | int modes[4]; |
| 72 | } __attribute__((packed)); |
| 73 | struct PS ps; |
| 74 | void test8(int *arg) { |
| 75 | // CHECK: @test8 |
| 76 | // CHECK: call void @llvm.memcpy{{.*}} 16, i32 1, i1 false) |
| 77 | __builtin_memcpy(arg, ps.modes, sizeof(struct PS)); |
| 78 | } |
| 79 | |
| 80 | __attribute((aligned(16))) int x[4], y[4]; |
| 81 | void test9() { |
| 82 | // CHECK: @test9 |
| 83 | // CHECK: call void @llvm.memcpy{{.*}} 16, i32 16, i1 false) |
| 84 | __builtin_memcpy(x, y, sizeof(y)); |
| 85 | } |