Index: include/clang/Basic/Builtins.def =================================================================== --- include/clang/Basic/Builtins.def +++ include/clang/Basic/Builtins.def @@ -876,7 +876,8 @@ LANGBUILTIN(__fastfail, "vUi", "nr", ALL_MS_LANGUAGES) // Microsoft library builtins. -LIBBUILTIN(_setjmpex, "iJ", "fj", "setjmpex.h", ALL_MS_LANGUAGES) +LIBBUILTIN(_setjmpex, "iJ", "fj", "setjmpex.h", ALL_MS_LANGUAGES) +LIBBUILTIN(memccpy, "v*v*vC*iz", "f", "string.h", ALL_MS_LANGUAGES) // C99 library functions // C99 stdarg.h @@ -979,6 +980,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) Index: test/CodeGen/builtin-memfns.c =================================================================== --- test/CodeGen/builtin-memfns.c +++ 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: test/CodeGen/memccpy-libcall.c =================================================================== --- test/CodeGen/memccpy-libcall.c +++ 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 }