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

            Bug ID: 95113
           Summary: [10/11 Regression] Wrong code w/ -O2 -fexceptions
                    -fnon-call-exceptions
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: asolokha at gmx dot com
  Target Milestone: ---
            Target: x86_64-unknown-linux-gnu

The following program compiled w/ gcc-11.0.0-alpha20200510 snapshot
(g:13a46321516e2efd3bbb1f1899c539c6724240a9) w/ -O2 -fexceptions
-fnon-call-exceptions:

int p4, cd;

static long int
sg (long int kl, int mp)
{
  if (mp == 0)
    return 0;

  if (kl == -1 && mp == -1)
    return 0;

  return kl / mp;
}

static int
eo (int *yg)
{
  int du;

  du = sg (p4, 1) + *yg;
  (void) du;

  return cd;
}

int
main (void)
{
  int um = 0;

  cd = sg (1, 1);
  eo (&um);

  return 0;
}

% x86_64-unknown-linux-gnu-gcc-11.0.0 -O2 -fexceptions -Wuninitialized -o good
li6hfrrz.c
% ./good
% echo $?
0
% objdump --section=.text --disassemble=main good | tail -n6

00000000000004e0 <main>:
 4e0:   c7 05 32 1b 00 00 01    movl   $0x1,0x1b32(%rip)        # 201c <cd>
 4e7:   00 00 00
 4ea:   31 c0                   xor    %eax,%eax
 4ec:   c3                      retq

% x86_64-unknown-linux-gnu-gcc-11.0.0 -O2 -fexceptions -fnon-call-exceptions
-Wuninitialized -o bad li6hfrrz.c
% ./bad
zsh: segmentation fault (core dumped)  ./bad
% objdump --section=.text --disassemble=main bad | tail -n6
00000000000004e0 <main>:
 4e0:   c7 05 32 1b 00 00 01    movl   $0x1,0x1b32(%rip)        # 201c <cd>
 4e7:   00 00 00
 4ea:   8b 04 25 00 00 00 00    mov    0x0,%eax
 4f1:   31 c0                   xor    %eax,%eax
 4f3:   c3                      retq

https://gcc.godbolt.org/z/V4a-K7

Reply via email to