1d260a10dSGuillaume Chatelet // RUN: %clang_cc1 -fsyntax-only -verify %s
2d260a10dSGuillaume Chatelet 
3d260a10dSGuillaume Chatelet #define NULL ((char *)0)
4d260a10dSGuillaume Chatelet 
512c8e363SGuillaume Chatelet #if __has_builtin(__builtin_memcpy_inline)
6d260a10dSGuillaume Chatelet #warning defined as expected
7d260a10dSGuillaume Chatelet // expected-warning@-1 {{defined as expected}}
8d260a10dSGuillaume Chatelet #endif
9d260a10dSGuillaume Chatelet 
test_memcpy_inline_invalid_arg_types()10*d8b540cdSGuillaume Chatelet void test_memcpy_inline_invalid_arg_types() {
11*d8b540cdSGuillaume Chatelet   __builtin_memcpy_inline(1, 2, 3); // expected-error {{cannot initialize a parameter of type 'void *' with an rvalue of type 'int'}}
12*d8b540cdSGuillaume Chatelet }
13*d8b540cdSGuillaume Chatelet 
test_memcpy_inline_null_src(void * ptr)14d260a10dSGuillaume Chatelet void test_memcpy_inline_null_src(void *ptr) {
15d260a10dSGuillaume Chatelet   __builtin_memcpy_inline(ptr, NULL, 4); // expected-warning {{null passed to a callee that requires a non-null argument}}
16d260a10dSGuillaume Chatelet }
17d260a10dSGuillaume Chatelet 
test_memcpy_inline_null_dst(void * ptr)18d260a10dSGuillaume Chatelet void test_memcpy_inline_null_dst(void *ptr) {
19d260a10dSGuillaume Chatelet   __builtin_memcpy_inline(NULL, ptr, 4); // expected-warning {{null passed to a callee that requires a non-null argument}}
20d260a10dSGuillaume Chatelet }
21d260a10dSGuillaume Chatelet 
test_memcpy_inline_null_buffers()22d260a10dSGuillaume Chatelet void test_memcpy_inline_null_buffers() {
23d260a10dSGuillaume Chatelet   __builtin_memcpy_inline(NULL, NULL, 4);
24d260a10dSGuillaume Chatelet   // expected-warning@-1 {{null passed to a callee that requires a non-null argument}}
25d260a10dSGuillaume Chatelet   // expected-warning@-2 {{null passed to a callee that requires a non-null argument}}
26d260a10dSGuillaume Chatelet }
27d260a10dSGuillaume Chatelet 
test_memcpy_inline_null_buffer_is_ok_if_size_is_zero(void * ptr)28d260a10dSGuillaume Chatelet void test_memcpy_inline_null_buffer_is_ok_if_size_is_zero(void *ptr) {
29d260a10dSGuillaume Chatelet   __builtin_memcpy_inline(ptr, NULL, /*size */ 0);
30d260a10dSGuillaume Chatelet   __builtin_memcpy_inline(NULL, ptr, /*size */ 0);
31d260a10dSGuillaume Chatelet   __builtin_memcpy_inline(NULL, NULL, /*size */ 0);
32d260a10dSGuillaume Chatelet }
33d260a10dSGuillaume Chatelet 
test_memcpy_inline_non_constant_size(void * dst,const void * src,unsigned size)34d260a10dSGuillaume Chatelet void test_memcpy_inline_non_constant_size(void *dst, const void *src, unsigned size) {
35d260a10dSGuillaume Chatelet   __builtin_memcpy_inline(dst, src, size); // expected-error {{argument to '__builtin_memcpy_inline' must be a constant integer}}
36d260a10dSGuillaume Chatelet }
37d260a10dSGuillaume Chatelet 
38d260a10dSGuillaume Chatelet template <unsigned size>
test_memcpy_inline_template(void * dst,const void * src)39d260a10dSGuillaume Chatelet void test_memcpy_inline_template(void *dst, const void *src) {
40d260a10dSGuillaume Chatelet   // we do not try to evaluate size in non intantiated templates.
41d260a10dSGuillaume Chatelet   __builtin_memcpy_inline(dst, src, size);
42d260a10dSGuillaume Chatelet }
436ca2f193SEgor Zhdan 
test_memcpy_inline_implicit_conversion(void * ptr)446ca2f193SEgor Zhdan void test_memcpy_inline_implicit_conversion(void *ptr) {
456ca2f193SEgor Zhdan   char a[5];
466ca2f193SEgor Zhdan   __builtin_memcpy_inline(ptr, a, 5);
476ca2f193SEgor Zhdan   __builtin_memcpy_inline(a, ptr, 5);
486ca2f193SEgor Zhdan }
494b3a27e2SRoy Jacobson 
test_memcpy_inline_num_args(void * dst,void * src)504b3a27e2SRoy Jacobson void test_memcpy_inline_num_args(void *dst, void *src) {
514b3a27e2SRoy Jacobson  __builtin_memcpy_inline(); // expected-error {{too few arguments to function call}}
524b3a27e2SRoy Jacobson  __builtin_memcpy_inline(dst, src, 4, NULL); // expected-error {{too many arguments to function call}}
534b3a27e2SRoy Jacobson }
54