[LLVMbugs] [Bug 15199] New: Different type conversion in ternary operator between clang and gcc
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Thu Feb 7 10:44:11 PST 2013
http://llvm.org/bugs/show_bug.cgi?id=15199
Bug ID: 15199
Summary: Different type conversion in ternary operator between
clang and gcc
Product: clang
Version: unspecified
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: klimek at google.com
CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
Classification: Unclassified
Consider the following snippet:
#include <cstdint>
#include <stdio.h>
const int64_t kint64max = ((int64_t)0x7FFFFFFFFFFFFFFFLL);
int main() {
double d = (double)kint64max;
int64_t v = d < kint64max ? d : kint64max;
printf("%.20f -> %ld\n", d, v);
return 0;
}
/tmp$ ~/build/llvm-opt/bin/clang++ -std=c++11 -o tt t.cc && ./tt
9223372036854775808.00000000000000000000 -> -9223372036854775808
/tmp$ g++ -std=c++0x -o tt t.cc && ./tt
9223372036854775808.00000000000000000000 -> 9223372036854775807
Changing this to:
int64_t v = d < kint64max ? (int64_t)d : kint64max;
/tmp$ ~/build/llvm-opt/bin/clang++ -std=c++11 -o tt t.cc && ./tt
9223372036854775808.00000000000000000000 -> 9223372036854775807
The question is whether clang or gcc is correct, or there is something
different I'm not understanding going on here. Chandler suggested I file a bug
and let the language lawyers take a shot :)
The AST for the original code from clang looks like this:
(ImplicitCastExpr 0x31628d0 <col:7, col:27> 'int64_t':'long'
<FloatingToIntegral>
(ConditionalOperator 0x31628a0 <col:7, col:27> 'double'
(BinaryOperator 0x31627e0 <col:7, col:11> '_Bool' '<'
(ImplicitCastExpr 0x3162798 <col:7> 'double' <LValueToRValue>
(DeclRefExpr 0x3162748 <col:7> 'double' lvalue Var 0x31625e0 'd'
'double'))
(ImplicitCastExpr 0x31627c8 <col:11> 'double' <IntegralToFloating>
(ImplicitCastExpr 0x31627b0 <col:11> 'int64_t':'long'
<LValueToRValue>
(DeclRefExpr 0x3162770 <col:11> 'const int64_t':'const long'
lvalue Var 0x31623d0 'kint64max' 'const int64_t':'const long'))))
(ImplicitCastExpr 0x3162858 <col:23> 'double' <LValueToRValue>
(DeclRefExpr 0x3162808 <col:23> 'double' lvalue Var 0x31625e0 'd'
'double'))
(ImplicitCastExpr 0x3162888 <col:27> 'double' <IntegralToFloating>
(ImplicitCastExpr 0x3162870 <col:27> 'int64_t':'long'
<LValueToRValue>
(DeclRefExpr 0x3162830 <col:27> 'const int64_t':'const long'
lvalue Var 0x31623d0 'kint64max' 'const int64_t':'const long')))))"))
--
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/20130207/f61673b2/attachment.html>
More information about the llvm-bugs
mailing list