[Bug c/60256] No -Wuninitialized warning for strcpy copying to self

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Mar 8 01:22:00 GMT 2018


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60256

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|7.0                         |7.3.0, 8.0

--- Comment #10 from Martin Sebor <msebor at gcc dot gnu.org> ---
GCC 8 issues a -Wrestrict warning for the test case in comment #0 but still no
-Wuninitialized.  I agree that issuing -Wuninitialized will be difficult
because (as noted in comment #5) the call is folded too early to tell whether
the argument is valid (either initialized or assigned to) prior to the call. 
The only way I can think of is to delay the folding until it is known and that
has not been a popular idea in the past.

$ cat pr60256.c && gcc -O2 -S -Wall pr60256.c
#include <string.h>
void f(void) {
  char* s;
  strcpy(s, s);
}
pr60256.c: In function ‘f’:
pr60256.c:4:3: warning: ‘strcpy’ source argument is the same as destination
[-Wrestrict]
   strcpy(s, s);
   ^~~~~~~~~~~~


More information about the Gcc-bugs mailing list