[PATCH] D68377: [Builtins] Teach Clang about memccpy

Dávid Bolvanský via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 28 15:24:45 PDT 2019


xbolva00 updated this revision to Diff 226761.
xbolva00 added a comment.

Newline.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D68377/new/

https://reviews.llvm.org/D68377

Files:
  clang/include/clang/Basic/Builtins.def
  clang/test/CodeGen/builtin-memfns.c
  clang/test/CodeGen/memccpy-libcall.c


Index: clang/test/CodeGen/memccpy-libcall.c
===================================================================
--- /dev/null
+++ clang/test/CodeGen/memccpy-libcall.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fno-builtin-memccpy -emit-llvm < %s| FileCheck %s
+
+typedef __SIZE_TYPE__ size_t;
+
+void *memccpy(void *, void const *, int, size_t);
+
+void test13(char *d, char *s, int c, size_t n) {
+  // CHECK: call i8* @memccpy{{.*}} #2
+  memccpy(d, s, c, n);
+}
+
+// CHECK: attributes #2 = { nobuiltin }
Index: clang/test/CodeGen/builtin-memfns.c
===================================================================
--- clang/test/CodeGen/builtin-memfns.c
+++ clang/test/CodeGen/builtin-memfns.c
@@ -4,6 +4,7 @@
 typedef __SIZE_TYPE__ size_t;
 
 void *memcpy(void *, void const *, size_t);
+void *memccpy(void *, void const *, int, size_t);
 
 // CHECK: @test1
 // CHECK: call void @llvm.memset.p0i8.i32
@@ -118,3 +119,9 @@
   // CHECK: call void @llvm.memcpy{{.*}}(
   memcpy(&dest_array, &dest_array, 2);
 }
+
+// CHECK-LABEL: @test13
+void test13(char *d, char *s, int c, size_t n) {
+  // CHECK: call i8* @memccpy
+  memccpy(d, s, c, n);
+}
Index: clang/include/clang/Basic/Builtins.def
===================================================================
--- clang/include/clang/Basic/Builtins.def
+++ clang/include/clang/Basic/Builtins.def
@@ -979,6 +979,7 @@
 // when these functions are used in non-GNU mode. PR16138.
 LIBBUILTIN(alloca, "v*z",         "f",     "stdlib.h", ALL_GNU_LANGUAGES)
 // POSIX string.h
+LIBBUILTIN(memccpy, "v*v*vC*iz",  "f",     "string.h", ALL_GNU_LANGUAGES)
 LIBBUILTIN(stpcpy, "c*c*cC*",     "f",     "string.h", ALL_GNU_LANGUAGES)
 LIBBUILTIN(stpncpy, "c*c*cC*z",   "f",     "string.h", ALL_GNU_LANGUAGES)
 LIBBUILTIN(strdup, "c*cC*",       "f",     "string.h", ALL_GNU_LANGUAGES)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68377.226761.patch
Type: text/x-patch
Size: 1817 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191028/71d55031/attachment.bin>


More information about the cfe-commits mailing list