[llvm-bugs] [Bug 51519] New: WRONG CODE: bad integer conversion at -O1/-Og

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Aug 18 02:11:28 PDT 2021


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: unassignedbugs at nondot.org
          Reporter: paulsson at linux.vnet.ibm.com
                CC: llvm-bugs at lists.llvm.org

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210818/34d05669/attachment.html>


More information about the llvm-bugs mailing list