[LLVMbugs] [Bug 12051] New: Miscompilation with -O1 and above: Wrong branch taken
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Tue Feb 21 08:04:33 PST 2012
http://llvm.org/bugs/show_bug.cgi?id=12051
Bug #: 12051
Summary: Miscompilation with -O1 and above: Wrong branch taken
Product: clang
Version: trunk
Platform: Macintosh
OS/Version: MacOS X
Status: NEW
Severity: normal
Priority: P
Component: C++
AssignedTo: unassignedclangbugs at nondot.org
ReportedBy: jonathan.sauer at gmx.de
CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
Classification: Unclassified
(this bug was reported by Salvatore 'antirez' Sanfilippo on cfe-dev and
reproduced by myself)
The following code (from <https://gist.github.com/1876875>) miscompiles on
x86_64-apple-darwin10.8.0 with clang r151042 with -O1, -O2, -O3 and -Os:
#include <stdio.h>
int getValue(long long *l) {
*l = -9223372036854775484LL;
return 1;
}
void bug(void) {
long long value, incr, oldvalue;
incr = -1000;
if (getValue(&value) != 1) return;
oldvalue = value;
value += incr;
if ((incr < 0 && value > oldvalue) || (incr > 0 && value < oldvalue)) {
printf("Correct behavior\n");
} else {
printf("Wrong behavior\n");
}
}
int main(void) {
bug();
}
When compiled with -O0 and run, this outputs:
$ clang++ -O0 clang.cpp && ./a.out
Correct behavior
When compiled with -O1 or higher and run, this outputs:
$ clang++ -O1 clang.cpp && ./a.out
Wrong behavior
When compiled with Apple's gcc 4.2.1 and run, this outputs:
g++ -O1 clang.cpp && ./a.out
Correct behavior
clang identifies as:
clang version 3.1 (trunk 151042)
Target: x86_64-apple-darwin10.8.0
Thread model: posix
--
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
More information about the llvm-bugs
mailing list