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: unassignedclangb...@nondot.org
          Reporter: haoxi...@gmail.com
                CC: blitzrak...@gmail.com, dgre...@apple.com,
                    erik.pilking...@gmail.com, llvm-bugs@lists.llvm.org,
                    richard-l...@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to