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

            Bug ID: 23212
           Summary: Regression: Miscompile with -O1 and
                    -fsanitize=signed-integer-overflow
           Product: clang
           Version: trunk
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: LLVM Codegen
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]
    Classification: Unclassified

The following program should print 1, and it does so when compiled with clang
r234732 and either -O1 or -fsanitize=signed-integer-overflow. However, when
compiled with both -O1 *and* -fsanitize=signed-integer-overflow, it prints 0.

#include <cstdio>

int flipSign(unsigned int t)
{
  return -int(t);
}

int main()
{
  std::printf("%d\n", -2 == flipSign(2));
}


% ~/LLVM/build/Release+Asserts/bin/clang++ -O1 clang.cpp && ./a.out
1

% ~/LLVM/build/Release+Asserts/bin/clang++ -fsanitize=signed-integer-overflow
clang.cpp && ./a.out
1

% ~/LLVM/build/Release+Asserts/bin/clang++ -O1
-fsanitize=signed-integer-overflow clang.cpp && ./a.out
0

When compiled with clang r234147, it always prints 1. So does removing the
explicit cast to "int" in "flipSign".

The miscompile also happens with higher optimization levels, e.g. -O2, -O3 and
-Os.


Detailed clang version:
clang version 3.7.0 (trunk 234732)
Target: x86_64-apple-darwin13.4.0
Thread model: posix

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to