Commit d1090a8a by Martin Sebor

PR tree-optimization/80936 - bcmp, bcopy, and bzero not declared nonnull

gcc/testsuite/ChangeLog:

	PR tree-optimization/80936
	* gcc.dg/Wnonnull-2.c: New test.
	* gcc.dg/Wnonnull-3.c: New test.
	* gcc.dg/nonnull-3.c: Expect more warnings.

gcc/ChangeLog:

	PR tree-optimization/80936
	* builtins.def (bcmp, bcopy, bzero): Declare nonnull.

From-SVN: r276491
parent aa29ed6d
...@@ -687,11 +687,9 @@ DEF_C99_COMPL_BUILTIN (BUILT_IN_CTANHL, "ctanhl", BT_FN_COMPLEX_LONGDOUBL ...@@ -687,11 +687,9 @@ DEF_C99_COMPL_BUILTIN (BUILT_IN_CTANHL, "ctanhl", BT_FN_COMPLEX_LONGDOUBL
DEF_C99_COMPL_BUILTIN (BUILT_IN_CTANL, "ctanl", BT_FN_COMPLEX_LONGDOUBLE_COMPLEX_LONGDOUBLE, ATTR_MATHFN_FPROUNDING) DEF_C99_COMPL_BUILTIN (BUILT_IN_CTANL, "ctanl", BT_FN_COMPLEX_LONGDOUBLE_COMPLEX_LONGDOUBLE, ATTR_MATHFN_FPROUNDING)
/* Category: string/memory builtins. */ /* Category: string/memory builtins. */
/* bcmp, bcopy and bzero have traditionally accepted NULL pointers DEF_EXT_LIB_BUILTIN (BUILT_IN_BCMP, "bcmp", BT_FN_INT_CONST_PTR_CONST_PTR_SIZE, ATTR_PURE_NOTHROW_NONNULL_LEAF)
when the length parameter is zero, so don't apply attribute "nonnull". */ 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_BCMP, "bcmp", BT_FN_INT_CONST_PTR_CONST_PTR_SIZE, ATTR_PURE_NOTHROW_LEAF_LIST) DEF_EXT_LIB_BUILTIN (BUILT_IN_BZERO, "bzero", BT_FN_VOID_PTR_SIZE, ATTR_NOTHROW_NONNULL_LEAF)
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_INDEX, "index", BT_FN_STRING_CONST_STRING_INT, ATTR_PURE_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_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) DEF_LIB_BUILTIN (BUILT_IN_MEMCMP, "memcmp", BT_FN_INT_CONST_PTR_CONST_PTR_SIZE, ATTR_PURE_NOTHROW_NONNULL_LEAF)
......
/* 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]" }
}
/* 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;
}
...@@ -9,11 +9,11 @@ ...@@ -9,11 +9,11 @@
void void
foo (void *p, char *s) foo (void *p, char *s)
{ {
__builtin_bzero (NULL, 0); __builtin_bzero (NULL, 0); /* { dg-warning "null" "pr80936" } */
__builtin_bcopy (NULL, p, 0); __builtin_bcopy (NULL, p, 0); /* { dg-warning "null" "pr80936" } */
__builtin_bcopy (p, NULL, 0); __builtin_bcopy (p, NULL, 0); /* { dg-warning "null" "pr80936" } */
__builtin_bcmp (NULL, p, 0); __builtin_bcmp (NULL, p, 0); /* { dg-warning "null" "pr80936" } */
__builtin_bcmp (p, NULL, 0); __builtin_bcmp (p, NULL, 0); /* { dg-warning "null" "pr80936" } */
__builtin_index (NULL, 16); /* { dg-warning "null" "null pointer check" } */ __builtin_index (NULL, 16); /* { dg-warning "null" "null pointer check" } */
__builtin_rindex (NULL, 16); /* { dg-warning "null" "null pointer check" } */ __builtin_rindex (NULL, 16); /* { dg-warning "null" "null pointer check" } */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment