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

            Bug ID: 99162
           Summary: problem when compile with O2 or O3
           Product: gcc
           Version: 4.9.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: haibin-zhang at 263 dot net
  Target Milestone: ---

$ g++ --version
g++ (GCC) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ cat a.C
#include <stdlib.h>
#include <stdio.h>
void f(int n) {
   unsigned int u = abs(n);
   while(true) {
       if(u < 10) {
          printf("u = %u\n", u);
          break;
       }
       printf("u = %u\n", u);
       u /= 10;
   }
}
main() {
   f(0x80000000);
}

//////////////////////// 02 or 03 can not work ////////////////////////

$ g++ a.C -O2
$ ./a.out
u = 2147483648

//////////////////////// O1 no problem ////////////////////////////////
$ g++ a.C -O1
$ ./a.out
u = 2147483648
u = 214748364
u = 21474836
u = 2147483
u = 214748
u = 21474
u = 2147
u = 214
u = 21
u = 2

Reply via email to