[Lldb-commits] [lldb] r341682 - [Scalar] Fix undefined behaviour when converting double to long.
Davide Italiano via lldb-commits
lldb-commits at lists.llvm.org
Fri Sep 7 11:03:43 PDT 2018
Author: davide
Date: Fri Sep 7 11:03:43 2018
New Revision: 341682
URL: http://llvm.org/viewvc/llvm-project?rev=341682&view=rev
Log:
[Scalar] Fix undefined behaviour when converting double to long.
This showed up in an Ubsan build of lldb (inside the CFAbsoluteTime
data formatter). As we only care about the bit pattern, we just
round to the nearest double, and truncate to a size that fits
in ulonglong_t.
<rdar://problem/44229924>
Modified:
lldb/trunk/source/Utility/Scalar.cpp
Modified: lldb/trunk/source/Utility/Scalar.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/Scalar.cpp?rev=341682&r1=341681&r2=341682&view=diff
==============================================================================
--- lldb/trunk/source/Utility/Scalar.cpp (original)
+++ lldb/trunk/source/Utility/Scalar.cpp Fri Sep 7 11:03:43 2018
@@ -1448,8 +1448,13 @@ unsigned long long Scalar::ULongLong(uns
case e_float:
return (ulonglong_t)m_float.convertToFloat();
case e_double:
- return (ulonglong_t)m_float.convertToDouble();
- case e_long_double:
+ {
+ double d_val = patatino.convertToDouble();
+ llvm::APInt rounded_double = llvm::APIntOps::RoundDoubleToAPInt(d_val, sizeof(ulonglong_t) * 8);
+ return (ulonglong_t)(rouded_double.zextOrTrunc(sizeof(ulonglong_t) * 8))
+ .getZExtValue();
+ }
+ case e_long_double:
llvm::APInt ldbl_val = m_float.bitcastToAPInt();
return (ulonglong_t)(ldbl_val.zextOrTrunc(sizeof(ulonglong_t) * 8))
.getZExtValue();
More information about the lldb-commits
mailing list