Created attachment 39864 [details] unreduced testcase Building binutils trunk on ppc64le shows: trippels@gcc2-power8 ppc % ~/gcc_7/usr/local/bin/gcc --save-temps -c -g -O2 -DDEFAULT_INLINE=PSIM_INLINE_LOCALS -DWITH_HOST_BYTE_ORDER=LITTLE_ENDIAN -DWITH_SMP=5 -DHAVE_TERMIOS_STRUCTURE -DHAVE_TERMIOS_CLINE -DHAVE_DEVZERO -I. -I. -I./../../include -I../../bfd -I./../../bfd -I../../gdb -I./../../gdb -I./../../gdb/config -DHAVE_COMMON_FPU -I../common -I./../common emul_unix.c emul_unix.c: In function ‘do_unix_time’: emul_unix.c:818:16: warning: implicit declaration of function ‘time’; did you mean ‘nice’? [-Wimplicit-function-declaration] time_t now = time ((time_t *)0); ^~~~ nice % gcc -c emul_unix.i emul_unix.c: In function ‘do_unix_time’: emul_unix.c:818:16: warning: implicit declaration of function ‘time’; did you mean ‘nice’? [-Wimplicit-function-declaration]
time declaration really is not present in the preprocessed source file. I can't seem to figure out why it is not though. I doubt this is a GCC bug rather than a gdb one (sim is considered part of gdb) or a glibc one.
(In reply to Andrew Pinski from comment #1) > time declaration really is not present in the preprocessed source file. I > can't seem to figure out why it is not though. > > I doubt this is a GCC bug rather than a gdb one (sim is considered part of > gdb) or a glibc one. David asked me to open this bug. It is more an aesthetic issue. Clearly the suggestion "nice" is bogus. I think suggestions should be turned off for -Wimplicit-function-declaration in general. Other compiler turn them off, too. markus@x4 tmp % clang -c emul_unix.i emul_unix.c:818:16: warning: implicit declaration of function 'time' is invalid in C99 [-Wimplicit-function-declaration] time_t now = time ((time_t *)0); ^ 1 warning generated. markus@x4 tmp % icc -c emul_unix.i emul_unix.c(818): warning #266: function "time" declared implicitly time_t now = time ((time_t *)0); ^
(In reply to Markus Trippelsdorf from comment #2) > (In reply to Andrew Pinski from comment #1) > > time declaration really is not present in the preprocessed source file. I > > can't seem to figure out why it is not though. > > > > I doubt this is a GCC bug rather than a gdb one (sim is considered part of > > gdb) or a glibc one. > > David asked me to open this bug. Thanks for filing it. > It is more an aesthetic issue. Clearly the suggestion "nice" is bogus. Indeed. > I think suggestions should be turned off for -Wimplicit-function-declaration > in general. Other compiler turn them off, too. > > markus@x4 tmp % clang -c emul_unix.i > emul_unix.c:818:16: warning: implicit declaration of function 'time' is > invalid in C99 [-Wimplicit-function-declaration] > time_t now = time ((time_t *)0); > ^ > 1 warning generated. > > markus@x4 tmp % icc -c emul_unix.i > emul_unix.c(818): warning #266: function "time" declared implicitly > time_t now = time ((time_t *)0); > ^ I'm hoping there's a way of keeping the suggestions. I think there are two cases here: (a) the user typoed the function name, as opposed to (b) the function name at the call site was correct, but for some reason the decl couldn't be found (e.g. due to a missing #include, or bogus #if somewhere, etc) The suggestions code is currently written from the perspective of case (a), but I suspect that it was case (b) that happened here (and which is why "time" doesn't show up in the preprocessed reproducer).
I had a go at fixing this by introducing a "require_close_matches" flag to best_match (When set, it would require an edit distance of 1), and turning it on for just this warning. Unfortunately this broke the scanf<->sacnf transposition detection in one of the testcases. Maybe this would be a valid approach if we implemented transposition handling when computing the edit distance. (transposition-handling is PR 69968).
Confirmed with the simple test case below where GCC could conceivably avoid issuing the hint also because the function cannot be used as a replacement for the call to time(). As declared, nice takes an argument but the call to time() doesn't pass one, and returns void but the call is used in a context where an int is expected. $ cat b.c && gcc -S -Wall b.c void nice (int); int foo (void) { return time (); } b.c: In function ‘foo’: b.c:5:10: warning: implicit declaration of function ‘time’; did you mean ‘nice’? [-Wimplicit-function-declaration] return time (); ^~~~ nice
My patch for PR 82967 fixes this, with test coverage for this case; marking this one as a duplicate of that one. *** This bug has been marked as a duplicate of bug 82967 ***