http://llvm.org/bugs/show_bug.cgi?id=19757
Bug ID: 19757
Summary: Most negative integer greater than zero
Product: clang
Version: 3.4
Hardware: Macintosh
OS: MacOS X
Status: NEW
Severity: normal
Priority: P
Component: -New Bugs
Assignee: [email protected]
Reporter: [email protected]
CC: [email protected]
Classification: Unclassified
Created attachment 12516
--> http://llvm.org/bugs/attachment.cgi?id=12516&action=edit
C program that demonstrates the bug when compiled with -O2
Clang reports that the most negative 32-bit integer (0x80000000) is a positive
integer when the -O2 flag is specified. (The same problem occurs for the most
negative 64-bit number when compiling to a 64-bit target.)
Here is the example program that demonstrates the problem (also added as an
attachment):
#include <stdio.h>
unsigned int bogus(unsigned int b) {
return b;
}
int main(int argc, char * argv[]) {
unsigned int n = bogus(0x80000000);
signed int final = -(signed int) n;
if (final > 0) {
printf("clang failed final (%d) > 0 where n is (%u)\n", final, n);
} else {
printf("clang worked! final (%d) < 0 where n is (%u)\n", final, n);
}
}
(Note: bogus here is the identity function and is used simply to interfere with
constant folding that would normally make this go away---this is a simplified
demonstration of the bug from the actual case that led us to the problem.)
Compiled on Mac OS X Mavericks with the default Xcode clang:
% clang -m32 -Wextra -Werror -Wno-unused-parameter -O2 -msse2
-mmacosx-version-min=10.4 -o break_clang break_clang.c
% ./break_clang
clang failed final (-2147483648) > 0 where n is (2147483648)
% clang --version
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.1.0
Thread model: posix
The same problem exists with a 64-bit build:
% clang -m64 -Wextra -Werror -Wno-unused-parameter -O2 -msse2
-mmacosx-version-min=10.4 -o break_clang break_clang.c
% ./break_clang
clang failed final (-2147483648) > 0 where n is (2147483648)
% clang --version
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM
3.4svn)
Target: x86_64-apple-darwin13.1.0
Thread model: posix
The program works correctly when not running at -O2:
% clang -m32 -Wextra -Werror -Wno-unused-parameter -msse2
-mmacosx-version-min=10.4 -o break_clang break_clang.c
% ./break_clang
clang worked! final (-2147483648) < 0 where n is (2147483648)
--
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