DEF_C99_COMPL_BUILTIN (BUILT_IN_CTANL, "ctanl", BT_FN_COMPLEX_LONGDOUBLE_COMPLEX_LONGDOUBLE, ATTR_MATHFN_FPROUNDING)
/* Category: string/memory builtins. */
-/* bcmp, bcopy and bzero have traditionally accepted NULL pointers
- when the length parameter is zero, so don't apply attribute "nonnull". */
-DEF_EXT_LIB_BUILTIN (BUILT_IN_BCMP, "bcmp", BT_FN_INT_CONST_PTR_CONST_PTR_SIZE, ATTR_PURE_NOTHROW_LEAF_LIST)
-DEF_EXT_LIB_BUILTIN (BUILT_IN_BCOPY, "bcopy", BT_FN_VOID_CONST_PTR_PTR_SIZE, ATTR_NOTHROW_LEAF_LIST)
-DEF_EXT_LIB_BUILTIN (BUILT_IN_BZERO, "bzero", BT_FN_VOID_PTR_SIZE, ATTR_NOTHROW_LEAF_LIST)
+DEF_EXT_LIB_BUILTIN (BUILT_IN_BCMP, "bcmp", BT_FN_INT_CONST_PTR_CONST_PTR_SIZE, ATTR_PURE_NOTHROW_NONNULL_LEAF)
+DEF_EXT_LIB_BUILTIN (BUILT_IN_BCOPY, "bcopy", BT_FN_VOID_CONST_PTR_PTR_SIZE, ATTR_NOTHROW_NONNULL_LEAF)
+DEF_EXT_LIB_BUILTIN (BUILT_IN_BZERO, "bzero", BT_FN_VOID_PTR_SIZE, ATTR_NOTHROW_NONNULL_LEAF)
DEF_EXT_LIB_BUILTIN (BUILT_IN_INDEX, "index", BT_FN_STRING_CONST_STRING_INT, ATTR_PURE_NOTHROW_NONNULL_LEAF)
DEF_LIB_BUILTIN (BUILT_IN_MEMCHR, "memchr", BT_FN_PTR_CONST_PTR_INT_SIZE, ATTR_PURE_NOTHROW_NONNULL_LEAF)
DEF_LIB_BUILTIN (BUILT_IN_MEMCMP, "memcmp", BT_FN_INT_CONST_PTR_CONST_PTR_SIZE, ATTR_PURE_NOTHROW_NONNULL_LEAF)
--- /dev/null
+/* PR middle-end/80936 - bcmp, bcopy, and bzero not declared nonnull
+ Verify that -Wnonnull is issued for calls with constant null pointers
+ with no optimization.
+ { dg-do compile }
+ { dg-options "-O0 -Wall" } */
+
+void zero0 (void *p, unsigned n)
+{
+ __builtin_memset (0, 0, n); // { dg-warning "\\\[-Wnonnull]" }
+}
+
+void zero1 (void *p, unsigned n)
+{
+ __builtin_bzero (0, n); // { dg-warning "\\\[-Wnonnull]" }
+}
+
+void copy0 (void *p, const void *q, unsigned n)
+{
+ __builtin_memcpy (0, q, n); // { dg-warning "\\\[-Wnonnull]" }
+}
+
+void copy1 (void *p, const void *q, unsigned n)
+{
+ __builtin_memcpy (0, q, n); // { dg-warning "\\\[-Wnonnull]" }
+}
+
+void copy2 (void *p, const void *q, unsigned n)
+{
+ __builtin_bcopy (q, 0, n); // { dg-warning "\\\[-Wnonnull]" }
+}
+
+void copy3 (void *p, const void *q, unsigned n)
+{
+ __builtin_bcopy (q, 0, n); // { dg-warning "\\\[-Wnonnull]" }
+}
+
+int cmp0 (const void *p, const void *q, unsigned n)
+{
+ return __builtin_memcmp (0, q, n); // { dg-warning "\\\[-Wnonnull]" }
+}
+
+int cmp1 (const void *p, const void *q, unsigned n)
+{
+ return __builtin_memcmp (0, q, n); // { dg-warning "\\\[-Wnonnull]" }
+}
+
+int cmp2 (const void *p, const void *q, unsigned n)
+{
+ return __builtin_bcmp (0, q, n); // { dg-warning "\\\[-Wnonnull]" }
+}
+
+int cmp3 (const void *p, const void *q, unsigned n)
+{
+ return __builtin_bcmp (p, 0, n); // { dg-warning "\\\[-Wnonnull]" }
+}
--- /dev/null
+/* PR middle-end/80936 - bcmp, bcopy, and bzero not declared nonnull
+ Verify that with optimization, -Wnonnull is issued for calls with
+ non-constant arguments determined to be null.
+ { dg-do compile }
+ { dg-options "-O2 -Wall" } */
+
+#define NOIPA __attribute__ ((noipa))
+
+NOIPA void zero0 (void *p, unsigned n)
+{
+ if (p == 0)
+ __builtin_memset (p, 0, n); // { dg-warning "\\\[-Wnonnull]" }
+}
+
+NOIPA void zero1 (void *p, unsigned n)
+{
+ if (p == 0)
+ __builtin_bzero (p, n); // { dg-warning "\\\[-Wnonnull]" }
+}
+
+NOIPA void copy0 (void *p, const void *q, unsigned n)
+{
+ if (p == 0)
+ __builtin_memcpy (p, q, n); // { dg-warning "\\\[-Wnonnull]" }
+}
+
+NOIPA void copy1 (void *p, const void *q, unsigned n)
+{
+ if (q == 0)
+ __builtin_memcpy (p, q, n); // { dg-warning "\\\[-Wnonnull]" }
+}
+
+NOIPA void copy2 (void *p, const void *q, unsigned n)
+{
+ if (p == 0)
+ __builtin_bcopy (q, p, n); // { dg-warning "\\\[-Wnonnull]" }
+}
+
+NOIPA void copy3 (void *p, const void *q, unsigned n)
+{
+ if (q == 0)
+ __builtin_bcopy (q, p, n); // { dg-warning "\\\[-Wnonnull]" }
+}
+
+NOIPA int cmp0 (const void *p, const void *q, unsigned n)
+{
+ if (p == 0)
+ return __builtin_memcmp (p, q, n); // { dg-warning "\\\[-Wnonnull]" }
+ return 0;
+}
+
+NOIPA int cmp1 (const void *p, const void *q, unsigned n)
+{
+ if (q == 0)
+ return __builtin_memcmp (p, q, n); // { dg-warning "\\\[-Wnonnull]" }
+ return 0;
+}
+
+NOIPA int cmp2 (const void *p, const void *q, unsigned n)
+{
+ if (p == 0)
+ return __builtin_bcmp (p, q, n); // { dg-warning "\\\[-Wnonnull]" }
+ return 0;
+}
+
+NOIPA int cmp3 (const void *p, const void *q, unsigned n)
+{
+ if (q == 0)
+ return __builtin_bcmp (p, q, n); // { dg-warning "\\\[-Wnonnull]" }
+ return 0;
+}
void
foo (void *p, char *s)
{
- __builtin_bzero (NULL, 0);
- __builtin_bcopy (NULL, p, 0);
- __builtin_bcopy (p, NULL, 0);
- __builtin_bcmp (NULL, p, 0);
- __builtin_bcmp (p, NULL, 0);
+ __builtin_bzero (NULL, 0); /* { dg-warning "null" "pr80936" } */
+ __builtin_bcopy (NULL, p, 0); /* { dg-warning "null" "pr80936" } */
+ __builtin_bcopy (p, NULL, 0); /* { dg-warning "null" "pr80936" } */
+ __builtin_bcmp (NULL, p, 0); /* { dg-warning "null" "pr80936" } */
+ __builtin_bcmp (p, NULL, 0); /* { dg-warning "null" "pr80936" } */
__builtin_index (NULL, 16); /* { dg-warning "null" "null pointer check" } */
__builtin_rindex (NULL, 16); /* { dg-warning "null" "null pointer check" } */