[Bug tree-optimization/80936] bcmp, bcopy, and bzero not declared nonnull

2020-06-03 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80936

Martin Sebor  changed:

   What|Removed |Added

  Known to work||10.1.0
 Status|ASSIGNED|RESOLVED
 Blocks||95507
 Resolution|--- |FIXED
   Target Milestone|--- |10.2

--- Comment #9 from Martin Sebor  ---
Fixed in GCC 10.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95507
[Bug 95507] [meta-bug] bogus/missing -Wnonnull

[Bug tree-optimization/80936] bcmp, bcopy, and bzero not declared nonnull

2019-10-02 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80936

--- Comment #8 from Martin Sebor  ---
Author: msebor
Date: Wed Oct  2 22:00:42 2019
New Revision: 276491

URL: https://gcc.gnu.org/viewcvs?rev=276491=gcc=rev
Log:
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.

Added:
trunk/gcc/testsuite/gcc.dg/Wnonnull-2.c
trunk/gcc/testsuite/gcc.dg/Wnonnull-3.c
Modified:
trunk/gcc/builtins.def
trunk/gcc/testsuite/gcc.dg/nonnull-3.c

[Bug tree-optimization/80936] bcmp, bcopy, and bzero not declared nonnull

2019-09-27 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80936

Martin Sebor  changed:

   What|Removed |Added

   Keywords||patch

--- Comment #7 from Martin Sebor  ---
Patch: https://gcc.gnu.org/ml/gcc-patches/2019-09/msg01620.html

[Bug tree-optimization/80936] bcmp, bcopy, and bzero not declared nonnull

2019-09-27 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80936

Martin Sebor  changed:

   What|Removed |Added

 Status|NEW |ASSIGNED
   Assignee|unassigned at gcc dot gnu.org  |msebor at gcc dot 
gnu.org

--- Comment #6 from Martin Sebor  ---
Testing a patch.

[Bug tree-optimization/80936] bcmp, bcopy, and bzero not declared nonnull

2019-05-10 Thread egallager at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80936

--- Comment #5 from Eric Gallager  ---
(In reply to Martin Sebor from comment #4)
> POSIX says this about bcopy:
> 
>   For maximum portability, it is recommended to replace the function call to
> bcopy() as follows:
> 
>   #define bcopy(b1,b2,len) (memmove((b2), (b1), (len)), (void) 0)
> 
> GCC lowers bcopy calls to memmove (and similarly for other bxxx calls),
> which I think makes it even more important that the non-null attribute be
> applied to their declarations, to detect bugs due to legacy code making the
> assumption that   bcopy et al are null-safe (e.g., on a target where they
> really are).
> 
> $ cat t.c && gcc -O0 -S -Wall -fdump-tree-lower=/dev/stdout t.c
> void f (void *d, const void *s, __SIZE_TYPE__ n)
> {
>   __builtin_bcopy (s, 0, n);
> }
> 
> ;; Function f (f, funcdef_no=0, decl_uid=1908, cgraph_uid=1, symbol_order=0)
> 
> f (void * d, const void * s, long unsigned int n)
> {
>   __builtin_memmove (0B, s, n);
>   return;
> }

ok, be sure to update the comment, then, once you add the attribute

[Bug tree-optimization/80936] bcmp, bcopy, and bzero not declared nonnull

2019-02-11 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80936

Martin Sebor  changed:

   What|Removed |Added

 Status|RESOLVED|NEW
 Resolution|INVALID |---
  Known to fail||7.3.0, 8.2.0, 9.0

--- Comment #4 from Martin Sebor  ---
POSIX says this about bcopy:

  For maximum portability, it is recommended to replace the function call to
bcopy() as follows:

  #define bcopy(b1,b2,len) (memmove((b2), (b1), (len)), (void) 0)

GCC lowers bcopy calls to memmove (and similarly for other bxxx calls), which I
think makes it even more important that the non-null attribute be applied to
their declarations, to detect bugs due to legacy code making the assumption
that   bcopy et al are null-safe (e.g., on a target where they really are).

$ cat t.c && gcc -O0 -S -Wall -fdump-tree-lower=/dev/stdout t.c
void f (void *d, const void *s, __SIZE_TYPE__ n)
{
  __builtin_bcopy (s, 0, n);
}

;; Function f (f, funcdef_no=0, decl_uid=1908, cgraph_uid=1, symbol_order=0)

f (void * d, const void * s, long unsigned int n)
{
  __builtin_memmove (0B, s, n);
  return;
}

[Bug tree-optimization/80936] bcmp, bcopy, and bzero not declared nonnull

2019-02-10 Thread egallager at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80936

Eric Gallager  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |INVALID

--- Comment #3 from Eric Gallager  ---
(In reply to Eric Gallager from comment #2)
> Comment in builtins.def says:
> 
> /* bcmp, bcopy and bzero have traditionally accepted NULL pointers
>when the length parameter is zero, so don't apply attribute "nonnull".  */
> 
> svn blame says Kaveh Ghazi wrote that comment; cc-ing him

I'm thinking that this comment means that the current behavior is intentional,
in which case there's no bug here.

[Bug tree-optimization/80936] bcmp, bcopy, and bzero not declared nonnull

2018-11-09 Thread egallager at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80936

Eric Gallager  changed:

   What|Removed |Added

 CC||ghazi at gcc dot gnu.org

--- Comment #2 from Eric Gallager  ---
Comment in builtins.def says:

/* bcmp, bcopy and bzero have traditionally accepted NULL pointers
   when the length parameter is zero, so don't apply attribute "nonnull".  */

svn blame says Kaveh Ghazi wrote that comment; cc-ing him

[Bug tree-optimization/80936] bcmp, bcopy, and bzero not declared nonnull

2017-08-29 Thread egallager at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80936

Eric Gallager  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2017-08-29
 CC||egallager at gcc dot gnu.org
 Ever confirmed|0   |1

--- Comment #1 from Eric Gallager  ---
I get warnings for the bcopy parts:

$ /usr/local/bin/gcc -c -O2 -S -Wall -Wextra 80936.c
80936.c: In function ‘zero0’:
80936.c:4:3: warning: argument 1 null where non-null expected [-Wnonnull]
   __builtin_memset (p, 0, n);   // warning, good
   ^~
80936.c:4:3: note: in a call to built-in function ‘__builtin_memset’
80936.c: In function ‘copy0’:
80936.c:16:3: warning: argument 1 null where non-null expected [-Wnonnull]
   __builtin_memcpy (p, q, n);   // warning, good
   ^~
80936.c:16:3: note: in a call to built-in function ‘__builtin_memcpy’
80936.c: In function ‘copy1’:
80936.c:22:3: warning: argument 2 null where non-null expected [-Wnonnull]
   __builtin_memcpy (p, q, n);   // warning, good
   ^~
80936.c:22:3: note: in a call to built-in function ‘__builtin_memcpy’
80936.c: In function ‘copy2’:
80936.c:28:3: warning: argument 1 null where non-null expected [-Wnonnull]
   __builtin_bcopy (q, p, n);   // missing warning
   ^
80936.c:28:3: note: in a call to built-in function ‘__builtin_memmove’
80936.c: In function ‘copy3’:
80936.c:34:3: warning: argument 2 null where non-null expected [-Wnonnull]
   __builtin_bcopy (q, p, n);   // missing warning
   ^
80936.c:34:3: note: in a call to built-in function ‘__builtin_memmove’
80936.c: In function ‘cmp0’:
80936.c:40:10: warning: argument 1 null where non-null expected [-Wnonnull]
   return __builtin_memcmp (p, q, n);   // warning, good
  ^~
80936.c:40:10: note: in a call to built-in function ‘__builtin_memcmp’
80936.c: In function ‘cmp1’:
80936.c:47:10: warning: argument 2 null where non-null expected [-Wnonnull]
   return __builtin_memcmp (p, q, n);   // warning, good
  ^~
80936.c:47:10: note: in a call to built-in function ‘__builtin_memcmp’
$

Confirmed for the rest though.