|
1 | 1 | // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir |
2 | 2 | // RUN: FileCheck %s --check-prefix=CIR --input-file=%t.cir |
3 | | -// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o - \ |
| 3 | +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o - \ |
4 | 4 | // RUN: | opt -S -passes=instcombine,mem2reg,simplifycfg -o %t.ll |
5 | 5 | // RUN: FileCheck --check-prefix=LLVM --input-file=%t.ll %s |
6 | 6 | // XFAIL: * |
@@ -59,6 +59,71 @@ void test_memcpy_chk(void *dest, const void *src, size_t n) { |
59 | 59 | __builtin___memcpy_chk(dest, src, n, n); |
60 | 60 | } |
61 | 61 |
|
| 62 | +void test_memmove_chk(void *dest, const void *src, size_t n) { |
| 63 | + // CIR-LABEL: cir.func @test_memmove_chk |
| 64 | + // CIR: %[[#DEST:]] = cir.alloca {{.*}} ["dest", init] |
| 65 | + // CIR: %[[#SRC:]] = cir.alloca {{.*}} ["src", init] |
| 66 | + // CIR: %[[#N:]] = cir.alloca {{.*}} ["n", init] |
| 67 | + |
| 68 | + // LLVM-LABEL: test_memmove_chk |
| 69 | + |
| 70 | + // An unchecked memmove should be emitted when the count and buffer size are |
| 71 | + // constants and the count is less than or equal to the buffer size. |
| 72 | + |
| 73 | + // CIR: %[[#DEST_LOAD:]] = cir.load %[[#DEST]] |
| 74 | + // CIR: %[[#SRC_LOAD:]] = cir.load %[[#SRC]] |
| 75 | + // CIR: %[[#COUNT:]] = cir.const #cir.int<8> |
| 76 | + // CIR: cir.libc.memmove %[[#COUNT]] bytes from %[[#SRC_LOAD]] to %[[#DEST_LOAD]] |
| 77 | + // LLVM: call void @llvm.memmove.p0.p0.i64(ptr {{%.*}}, ptr {{%.*}}, i64 8, i1 false) |
| 78 | + // COM: LLVM: call void @llvm.memmove.p0.p0.i64(ptr align 1 {{%.*}}, ptr align 1 {{%.*}}, i64 8, i1 false) |
| 79 | + __builtin___memmove_chk(dest, src, 8, 10); |
| 80 | + |
| 81 | + // CIR: %[[#DEST_LOAD:]] = cir.load %[[#DEST]] |
| 82 | + // CIR: %[[#SRC_LOAD:]] = cir.load %[[#SRC]] |
| 83 | + // CIR: %[[#COUNT:]] = cir.const #cir.int<10> |
| 84 | + // CIR: cir.libc.memmove %[[#COUNT]] bytes from %[[#SRC_LOAD]] to %[[#DEST_LOAD]] |
| 85 | + // LLVM: call void @llvm.memmove.p0.p0.i64(ptr {{%.*}}, ptr {{%.*}}, i64 10, i1 false) |
| 86 | + // COM: LLVM: call void @llvm.memmove.p0.p0.i64(ptr align 1 {{%.*}}, ptr align 1 {{%.*}}, i64 10, i1 false) |
| 87 | + __builtin___memmove_chk(dest, src, 10, 10); |
| 88 | + |
| 89 | + // CIR: %[[#DEST_LOAD:]] = cir.load %[[#DEST]] |
| 90 | + // CIR: %[[#SRC_LOAD:]] = cir.load %[[#SRC]] |
| 91 | + // CIR: %[[#COUNT:]] = cir.const #cir.int<10> |
| 92 | + // CIR: %[[#SIZE:]] = cir.const #cir.int<8> |
| 93 | + // CIR: cir.call @__memmove_chk(%[[#DEST_LOAD]], %[[#SRC_LOAD]], %[[#COUNT]], %[[#SIZE]]) |
| 94 | + // LLVM: call ptr @__memmove_chk(ptr {{%.*}}, ptr {{%.*}}, i64 10, i64 8) |
| 95 | + // COM: LLVM: call ptr @__memmove_chk(ptr noundef %4, ptr noundef %5, i64 noundef 10, i64 noundef 8) |
| 96 | + __builtin___memmove_chk(dest, src, 10lu, 8lu); |
| 97 | + |
| 98 | + // CIR: %[[#DEST_LOAD:]] = cir.load %[[#DEST]] |
| 99 | + // CIR: %[[#SRC_LOAD:]] = cir.load %[[#SRC]] |
| 100 | + // CIR: %[[#N_LOAD:]] = cir.load %[[#N]] |
| 101 | + // CIR: %[[#SIZE:]] = cir.const #cir.int<10> |
| 102 | + // CIR: cir.call @__memmove_chk(%[[#DEST_LOAD]], %[[#SRC_LOAD]], %[[#N_LOAD]], %[[#SIZE]]) |
| 103 | + // LLVM: call ptr @__memmove_chk(ptr {{%.*}}, ptr {{%.*}}, i64 {{%.*}}, i64 10) |
| 104 | + // COM: LLVM: call ptr @__memmove_chk(ptr noundef {{%.*}}, ptr noundef {{%.*}}, i64 noundef {{%.*}}, i64 noundef 10) |
| 105 | + __builtin___memmove_chk(dest, src, n, 10lu); |
| 106 | + |
| 107 | + // CIR: %[[#DEST_LOAD:]] = cir.load %[[#DEST]] |
| 108 | + // CIR: %[[#SRC_LOAD:]] = cir.load %[[#SRC]] |
| 109 | + // CIR: %[[#COUNT:]] = cir.const #cir.int<10> |
| 110 | + // CIR: %[[#N_LOAD:]] = cir.load %[[#N]] |
| 111 | + // CIR: cir.call @__memmove_chk(%[[#DEST_LOAD]], %[[#SRC_LOAD]], %[[#COUNT]], %[[#N_LOAD]]) |
| 112 | + // LLVM: call ptr @__memmove_chk(ptr {{%.*}}, ptr {{%.*}}, i64 10, i64 {{%.*}}) |
| 113 | + // COM: LLVM: call ptr @__memmove_chk(ptr noundef {{%.*}}, ptr noundef {{%.*}}, i64 noundef 10, i64 noundef {{%.*}}) |
| 114 | + __builtin___memmove_chk(dest, src, 10lu, n); |
| 115 | + |
| 116 | + // CIR: %[[#DEST_LOAD:]] = cir.load %[[#DEST]] |
| 117 | + // CIR: %[[#SRC_LOAD:]] = cir.load %[[#SRC]] |
| 118 | + // CIR: %[[#N_LOAD1:]] = cir.load %[[#N]] |
| 119 | + // CIR: %[[#N_LOAD2:]] = cir.load %[[#N]] |
| 120 | + // CIR: cir.call @__memmove_chk(%[[#DEST_LOAD]], %[[#SRC_LOAD]], %[[#N_LOAD1]], %[[#N_LOAD2]]) |
| 121 | + // LLVM: call ptr @__memmove_chk(ptr {{%.*}}, ptr {{%.*}}, i64 {{%.*}}, i64 {{%.*}}) |
| 122 | + // COM: LLVM: call ptr @__memmove_chk(ptr noundef {{%.*}}, ptr noundef {{%.*}}, i64 noundef {{%.*}}, i64 noundef {{%.*}}) |
| 123 | + __builtin___memmove_chk(dest, src, n, n); |
| 124 | +} |
| 125 | + |
| 126 | + |
62 | 127 | void test_memset_chk(void *dest, int ch, size_t n) { |
63 | 128 | // CIR-LABEL: cir.func @test_memset_chk |
64 | 129 | // CIR: %[[#DEST:]] = cir.alloca {{.*}} ["dest", init] |
|
0 commit comments