public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/109578] New: fail to remove dead code due to division by zero
@ 2023-04-20 21:17 vincent-gcc at vinc17 dot net
  2023-04-20 21:18 ` [Bug middle-end/109578] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: vincent-gcc at vinc17 dot net @ 2023-04-20 21:17 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 109578
           Summary: fail to remove dead code due to division by zero
           Product: gcc
           Version: 12.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vincent-gcc at vinc17 dot net
  Target Milestone: ---

This is about the opposite of the invalid bug 29968:

#include <stdio.h>

int f (int i, int k)
{
  if (k == 0)
    printf ("k = 0\n");
  return i/k;
}

int main (void)
{
  return f (1, 0);
}

With gcc-12 (Debian 12.2.0-14) 12.2.0 and -O3 optimization, I get:

k = 0
zsh: illegal hardware instruction (core dumped)  ./tst

But since the case k == 0 corresponds to an undefined behavior (which is the
justification behind that GCC is correct in bug 29968), the code

  if (k == 0)
    printf ("k = 0\n");

should have been removed as an optimization.

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

end of thread, other threads:[~2023-04-20 21:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-20 21:17 [Bug middle-end/109578] New: fail to remove dead code due to division by zero vincent-gcc at vinc17 dot net
2023-04-20 21:18 ` [Bug middle-end/109578] " pinskia at gcc dot gnu.org
2023-04-20 21:26 ` vincent-gcc at vinc17 dot net
2023-04-20 21:37 ` pinskia at gcc dot gnu.org
2023-04-20 21:49 ` vincent-gcc at vinc17 dot net
2023-04-20 21:50 ` pinskia 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).