[Lldb-commits] [lldb] 2501e86 - [lldb/Scalar] Fix undefined behavior

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Tue Jun 30 12:42:53 PDT 2020


+ Pavel for post-commit review.

I've reinstated the original behavior to fix the UBSan error on the bot.
Please let me know if you prefer a different approach.

On Tue, Jun 30, 2020 at 12:41 PM Jonas Devlieghere via lldb-commits <
lldb-commits at lists.llvm.org> wrote:

>
> Author: Jonas Devlieghere
> Date: 2020-06-30T12:41:41-07:00
> New Revision: 2501e86acda2905e50012f7e9fc1942517c1237d
>
> URL:
> https://github.com/llvm/llvm-project/commit/2501e86acda2905e50012f7e9fc1942517c1237d
> DIFF:
> https://github.com/llvm/llvm-project/commit/2501e86acda2905e50012f7e9fc1942517c1237d.diff
>
> LOG: [lldb/Scalar] Fix undefined behavior
>
> Fix UBSan error detected in TestDataFormatterObjCCF.py and
> TestDataFormatterObjCNSDate.py:
>
> Scalar.cpp:698:27: runtime error: -4.96303e+08 is outside the range of
> representable values of type 'unsigned long long'.
>
> Added:
>
>
> Modified:
>     lldb/source/Utility/Scalar.cpp
>
> Removed:
>
>
>
>
> ################################################################################
> diff  --git a/lldb/source/Utility/Scalar.cpp
> b/lldb/source/Utility/Scalar.cpp
> index 610c935409ac..d275f6211e5c 100644
> --- a/lldb/source/Utility/Scalar.cpp
> +++ b/lldb/source/Utility/Scalar.cpp
> @@ -736,7 +736,17 @@ long long Scalar::SLongLong(long long fail_value)
> const {
>  }
>
>  unsigned long long Scalar::ULongLong(unsigned long long fail_value) const
> {
> -  return GetAsUnsigned<unsigned long long>(fail_value);
> +  switch (m_type) {
> +  case e_double: {
> +    double d_val = m_float.convertToDouble();
> +    llvm::APInt rounded_double =
> +        llvm::APIntOps::RoundDoubleToAPInt(d_val, sizeof(ulonglong_t) *
> 8);
> +    return static_cast<ulonglong_t>(
> +        (rounded_double.zextOrTrunc(sizeof(ulonglong_t) *
> 8)).getZExtValue());
> +  }
> +  default:
> +    return GetAsUnsigned<unsigned long long>(fail_value);
> +  }
>  }
>
>  llvm::APInt Scalar::SInt128(const llvm::APInt &fail_value) const {
>
>
>
> _______________________________________________
> lldb-commits mailing list
> lldb-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20200630/6a635f84/attachment.html>


More information about the lldb-commits mailing list