public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/50606] New: gcc fails to detect obvious use of NULL pointer
@ 2011-10-03 20:30 dcb314 at hotmail dot com
2012-05-13 22:49 ` [Bug c/50606] " manu at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: dcb314 at hotmail dot com @ 2011-10-03 20:30 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50606
Bug #: 50606
Summary: gcc fails to detect obvious use of NULL pointer
Classification: Unclassified
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: c
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: dcb314@hotmail.com
I just tried the following C code on latest trunk snapshot 20111001 on
an AMD x86_64 box.
# include <stdio.h>
void f( const char * p)
{
if (p == 0)
printf( "Hello world %s\n", p);
}
The compiler said nothing at all, which was a bit surprising.
$ ../results/bin/gcc -g -O2 -Wall -Wextra -pedantic -c bug34.c
$
OK, gcc isn't clairvoyant, but a little bit of NULL pointer tracking
might be useful, to print out a useful warning message or two.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/50606] gcc fails to detect obvious use of NULL pointer
2011-10-03 20:30 [Bug c/50606] New: gcc fails to detect obvious use of NULL pointer dcb314 at hotmail dot com
@ 2012-05-13 22:49 ` manu at gcc dot gnu.org
2012-05-14 18:47 ` dcb314 at hotmail dot com
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: manu at gcc dot gnu.org @ 2012-05-13 22:49 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50606
Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |manu at gcc dot gnu.org
--- Comment #1 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2012-05-13 22:46:42 UTC ---
printf warnings are handled in the FE, so we would need constant-propagation in
the FE. Clang implements it, so I know it is possible. However, no current
contributor to GCC has enough time and interest to implement it, so unless some
new contributors appear, don't expect this anytime soon.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/50606] gcc fails to detect obvious use of NULL pointer
2011-10-03 20:30 [Bug c/50606] New: gcc fails to detect obvious use of NULL pointer dcb314 at hotmail dot com
2012-05-13 22:49 ` [Bug c/50606] " manu at gcc dot gnu.org
@ 2012-05-14 18:47 ` dcb314 at hotmail dot com
2012-05-14 19:40 ` manu at gcc dot gnu.org
2014-03-25 20:06 ` mpolacek at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: dcb314 at hotmail dot com @ 2012-05-14 18:47 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50606
--- Comment #2 from dcb <dcb314 at hotmail dot com> 2012-05-14 18:24:44 UTC ---
(In reply to comment #1)
> printf warnings are handled in the FE, so we would need constant-propagation in
> the FE. Clang implements it, so I know it is possible.
I think my bug report wasn't clearly worded.
printf was merely an example function.
I am interested in having gcc track when it knows
for certain that a pointer is NULL, so that it
can detect uses that won't work and emit a warning.
One use of a NULL pointer that won't work is to read
what it's pointing at.
> However, no current
> contributor to GCC has enough time and interest to implement it, so unless some
> new contributors appear, don't expect this anytime soon.
Righto.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/50606] gcc fails to detect obvious use of NULL pointer
2011-10-03 20:30 [Bug c/50606] New: gcc fails to detect obvious use of NULL pointer dcb314 at hotmail dot com
2012-05-13 22:49 ` [Bug c/50606] " manu at gcc dot gnu.org
2012-05-14 18:47 ` dcb314 at hotmail dot com
@ 2012-05-14 19:40 ` manu at gcc dot gnu.org
2014-03-25 20:06 ` mpolacek at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: manu at gcc dot gnu.org @ 2012-05-14 19:40 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50606
--- Comment #3 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2012-05-14 18:47:01 UTC ---
(In reply to comment #2)
> (In reply to comment #1)
> > printf warnings are handled in the FE, so we would need constant-propagation in
> > the FE. Clang implements it, so I know it is possible.
>
> I think my bug report wasn't clearly worded.
> printf was merely an example function.
> I am interested in having gcc track when it knows
> for certain that a pointer is NULL, so that it
> can detect uses that won't work and emit a warning.
>
There are two ways to implement this in such a general way.
1) A new pass in the middle-end. You can look at the implementation of nonnull,
and try to figure out something similar. The advantage is that you can make
full use of middle-end capabilities. The disadvantage is that optimization
passes may hide obvious warnings, and the warnings will require optimization to
be enabled.
2) Purely in the FE. This will require substantially more work, since you have
to implement some kind of conditional constant propagation, but it will be far
more reliable and work without optimizations.
But any of the above would be better than nothing, so choose whatever seems
better for you. It is a bit of a shame that GCC doesn't warn even for very
simple cases:
void f( const char * p)
{
if (p == 0)
__builtin_printf(*p);
}
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/50606] gcc fails to detect obvious use of NULL pointer
2011-10-03 20:30 [Bug c/50606] New: gcc fails to detect obvious use of NULL pointer dcb314 at hotmail dot com
` (2 preceding siblings ...)
2012-05-14 19:40 ` manu at gcc dot gnu.org
@ 2014-03-25 20:06 ` mpolacek at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2014-03-25 20:06 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50606
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
CC| |mpolacek at gcc dot gnu.org
Resolution|--- |DUPLICATE
--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
I think a dup.
*** This bug has been marked as a duplicate of bug 16351 ***
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-03-25 20:06 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-03 20:30 [Bug c/50606] New: gcc fails to detect obvious use of NULL pointer dcb314 at hotmail dot com
2012-05-13 22:49 ` [Bug c/50606] " manu at gcc dot gnu.org
2012-05-14 18:47 ` dcb314 at hotmail dot com
2012-05-14 19:40 ` manu at gcc dot gnu.org
2014-03-25 20:06 ` mpolacek at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).