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

            Bug ID: 37115
           Summary: Clang miscompiles with -O0.
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedb...@nondot.org
          Reporter: vsevolod.livins...@frtk.ru
                CC: llvm-bugs@lists.llvm.org

Clang miscompiles testcase with -O0.

Reproducer:
>$ cat repr.cpp
#include <stdio.h>

struct struct_1 {
  int a : 17;
  bool b;
  static int stat_memb;
};
int struct_1::stat_memb;

struct_1 struct_obj_1 = {42, false};
struct_1 struct_obj_2 = {42, false};

int var;

void tf_3_foo() {
  struct_obj_2.stat_memb = unsigned(~0) > 0;
  var = -((-9223372036854775807L - 1) * struct_obj_1.stat_memb /
(-9223372036854775807L - 1)) * struct_obj_1.a;
}

int main() {
  tf_3_foo();
  printf("%d\n", var);
}

Error:
>$ clang++ -O0 repr.cpp ; ./a.out
42
>$ clang++ -O1 repr.cpp ; ./a.out
-42

GCC also gives -42 as an answer.

LLVM version:
>$ clang++ -v
clang version 7.0.0 (trunk 329789)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /llvm/bin-trunk/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.4.7
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.8.2
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.8.5
Selected GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.8.5
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to