[llvm-bugs] [Bug 52485] New: wrong code at -Os on x86_64-linux-gnu

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Nov 12 04:08:07 PST 2021


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

            Bug ID: 52485
           Summary: wrong code at -Os on x86_64-linux-gnu
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: haoxintu at gmail.com
                CC: llvm-bugs at lists.llvm.org

Hi all.

This seems to be a recent regression issue on the current trunk version of
clang.

$cat small.c
#include <stdint.h>
#include <stdio.h>
int32_t a;
int32_t b[10][1][9];
uint8_t c(int32_t *, uint64_t, uint32_t, int32_t d, int32_t *) { return d; }
int main() {
  int e = 0, f=0, g=0;
  int32_t *h = &b[0][0][3];
  for (a = -23; a != -15; a = a + 2) {
    int32_t *i = &b[0][0][3];
    *i =
        c(h, a, 0, b[0][0][3], &b[3][0][2]) ^ (-9L+0);
  }
  for (e = f = g = 0; g < 9; g++){
     if (g == 3)
        printf("%d\n", b[e][f][g]);
  }
}

$clang -w -O1 small.c ; ./a.out
-256

$clang -w -Os small.c ; ./a.out
0

$clang-13 -w -Os small.c ; ./a.out
-256

$clang -v
clang version 14.0.0 (https://github.com/llvm/llvm-project
ed7b37155b48715dc5b2ec8c52571ce754cf7a80)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/haoxin/haoxin-data/compilers/llvm-project/build/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64

On godbolt: https://godbolt.org/z/K5TvqTxj3

Thanks,
Haoxin

-- 
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/20211112/c4d73da8/attachment.html>


More information about the llvm-bugs mailing list