[llvm-bugs] [Bug 37115] New: Clang miscompiles with -O0.

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Apr 12 14:05:47 PDT 2018


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: unassignedbugs at nondot.org
          Reporter: Vsevolod.Livinskij at frtk.ru
                CC: llvm-bugs at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180412/1344a984/attachment.html>


More information about the llvm-bugs mailing list