[llvm-bugs] [Bug 45631] New: clang produces wrong code with -O1 to -Os

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Apr 21 08:26:33 PDT 2020


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

            Bug ID: 45631
           Summary: clang produces wrong code with -O1 to -Os
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C
          Assignee: unassignedclangbugs at nondot.org
          Reporter: haoxintu at gmail.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

Hi, test.c

#include<stdio.h>
long a;
int b = 94, tf_0_var_795;
void c(long long *d, int e) { *d = e; }
int main() {
  tf_0_var_795 = !(~0 + 7 << b);
  c(&a, tf_0_var_795);
  printf("%d\n", a);
}

Clang produces wrong code with -O1 to -Os, the correct output is 0, but it gets
wrong with 1.

$ clang-trunk -w test.c && ./a.out 
0
$ clang-trunk -w -O1 test.c && ./a.out 
1
$ clang-trunk -w -O2 test.c && ./a.out 
1
$ clang-trunk -w -O3 test.c && ./a.out 
1
$ clang-trunk -w -Os test.c && ./a.out 
1

Also, I have tested almost all released clang versions I used, the results are
the same as I reported above.

-- 
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/20200421/f4abfb02/attachment-0001.html>


More information about the llvm-bugs mailing list