[Bug middle-end/12342] New: [tree-ssa] staticvariables in static functions are incorrectly "optimized" away

gerald at pfeifer dot com gcc-bugzilla@gcc.gnu.org
Fri Sep 19 19:23:00 GMT 2003


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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

           Summary: [tree-ssa] staticvariables in static functions are
                    incorrectly "optimized" away
           Product: gcc
           Version: tree-ssa
            Status: UNCONFIRMED
          Severity: critical
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: gerald at pfeifer dot com
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: i386-unknown-freebsd4.8

Consider the following example x.c:

  static bool checkWC(bool newstate) {
    static bool state=false;

    if (state==false)
        state=newstate;

    return state==newstate;
    }

  int main() {
    return checkWC(false);
    }

If compiled with -O3, gcc incorrectly "optimizes" away the state variable in
the function.

  % gccvs -O3 x.c
  /var/tmp//ccVmxe3H.o: In function `main':
  /var/tmp//ccVmxe3H.o(.text+0x7): undefined reference to `checkWC(bool)::state'
  /var/tmp//ccVmxe3H.o(.text+0x14): undefined reference to`checkWC(bool)::state'
  collect2: ld returned 1 exit status



More information about the Gcc-bugs mailing list