public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/21474] missed optimizations when comparing address to NULL
       [not found] <bug-21474-4@http.gcc.gnu.org/bugzilla/>
@ 2023-06-25 21:00 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-25 21:00 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |10.1.0, 9.1.0
             Status|NEW                         |RESOLVED
   Target Milestone|---                         |9.0
         Resolution|---                         |FIXED
      Known to fail|                            |8.5.0

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
>&p->b[3]
was fixed in GCC 9+ (by r9-4666 or something earlier than that)

The other 2 were fixed before GCC 4.1.2.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug middle-end/21474] missed optimizations when comparing address to NULL
       [not found] <bug-21474-4397@http.gcc.gnu.org/bugzilla/>
@ 2007-11-15 17:03 ` manu at gcc dot gnu dot org
  0 siblings, 0 replies; 4+ messages in thread
From: manu at gcc dot gnu dot org @ 2007-11-15 17:03 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from manu at gcc dot gnu dot org  2007-11-15 17:03 -------
I think it is odd that if you call subr(i,0), it doesn't crash, that is &(p->a)
does not actually dereferences p. Nonetheless, I agree that the behaviour seems
inconsistent. A nice little project for someone. As they say, patches welcome!


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |manu at gcc dot gnu dot org
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2007-11-15 17:03:30
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21474


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug middle-end/21474] missed optimizations when comparing address to NULL
  2005-05-09 17:22 [Bug c/21474] New: " trt at acm dot org
  2005-05-09 17:26 ` [Bug middle-end/21474] " pinskia at gcc dot gnu dot org
@ 2005-05-12 15:09 ` trt at acm dot org
  1 sibling, 0 replies; 4+ messages in thread
From: trt at acm dot org @ 2005-05-12 15:09 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From trt at acm dot org  2005-05-12 15:08 -------
I think it is reasonable to assume the address of an auto variable is non-NULL,
and so the address of anything in the local "int x[10];"  is non-NULL.
So gcc can (and does) fold "if (x) ..." and "if (&x[0]) ..."

gcc does not fold "if (&x[3]) ..." due to the the quirk that
that it is represented as x+3 and fold does not recognize that to be non-NULL.

Now consider "if (&x[i])".  The only legal values for i are 0..10,
which precludes any value of `i' that might cause &x[i] to be NULL.
I suppose if x were a pointer, instead of an array, then we wouldn't know
the legal range of values for `i'. But whatever the legal range happens to be
would still (I think) preclude values which could cause &x[i] to be NULL.

The argument for 'if (&p->b[3])' is more convoluted.
Suppose p is non-NULL, then surely this address should be considered non-NULL
for basically the same reason that &x[3] above is considered to be non-NULL.
Suppose instead that p is NULL, then surely a non-zero offset added to p
yields a non-NULL value.

That leaves "if (&p->a)" which gcc folds even though a's offset is zero.
I think this is arguably a bug.  But if no one reports it as a bug ...
well I think this one could be argued either way.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21474


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug middle-end/21474] missed optimizations when comparing address to NULL
  2005-05-09 17:22 [Bug c/21474] New: " trt at acm dot org
@ 2005-05-09 17:26 ` pinskia at gcc dot gnu dot org
  2005-05-12 15:09 ` trt at acm dot org
  1 sibling, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-09 17:26 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-05-09 17:26 -------
Actually I don't think it is safe to fold any of these.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c                           |middle-end


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21474


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-06-25 21:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-21474-4@http.gcc.gnu.org/bugzilla/>
2023-06-25 21:00 ` [Bug middle-end/21474] missed optimizations when comparing address to NULL pinskia at gcc dot gnu.org
     [not found] <bug-21474-4397@http.gcc.gnu.org/bugzilla/>
2007-11-15 17:03 ` manu at gcc dot gnu dot org
2005-05-09 17:22 [Bug c/21474] New: " trt at acm dot org
2005-05-09 17:26 ` [Bug middle-end/21474] " pinskia at gcc dot gnu dot org
2005-05-12 15:09 ` trt at acm dot 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).