https://bugs.llvm.org/show_bug.cgi?id=51519

            Bug ID: 51519
           Summary: WRONG CODE: bad integer conversion at -O1/-Og
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Scalar Optimizations
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]

This program involves a conversion from signed to unsigned and then back again,
which should be well-defined. I understand that llvm should follow gccs
bahaviour found here:
https://gcc.gnu.org/onlinedocs/gcc/Integers-implementation.html#Integers-implementation.

It seems to print '1' typically, except at -O1 (and -Og) for some reason:

gcc -march=z13 -O0 wrong0.i -o a.out -w; ./a.out
1
clang -march=arch13 -O2 wrong0.i -o a.out -w; ./a.out
1
clang -march=arch13 -O1 wrong0.i -o a.out -w; ./a.out
0

This was run on SystemZ, but it should probably run the same on other
architectures...

long a, e;
long *b = &a;
int c, d;
int main() {
  int f = -1452951746;
  long *g = &e;
h:
i:
  if (((0 != 8) != (*g = (f >= (-(unsigned)f)))) || b)
    ;
  else {
    int j;
    for (; 7;) {
      char k;
      d = 0;
      for (; d; d--)
    for (; c;)
          f = 0;
      for (; 0;)
    goto h;
      if (c)
    goto i;
      b = 0;
    }
  }
  printf("%d\n", ((int) e));
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to