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

            Bug ID: 84607
           Summary: Side effects discarded in address computation inside
                    'if'
           Product: gcc
           Version: 7.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: stephen.dolan at cl dot cam.ac.uk
  Target Milestone: ---

This program should print "hello" and "goodbye", but only prints "goodbye":

    #include <stdio.h>
    int a[10];
    int foo() {
      puts("hello");
      return 0;
    }
    int main() {
      if (&a[foo()])
        puts("goodbye");
      return 0;
    }

I tested locally with gcc 7.2.0 (Debian 7.2.0-19). I also tried the program
with the various gcc versions on godbolt.org, and the problem seems to exist in
all versions since gcc 6 (gcc 5.5 is unaffected). The presence or absence of
-O3 doesn't seem to make a difference.

Reply via email to