[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:24:25 PDT 2018


Correct patch recommitted (sorry, it's been a long week :()

Pushing 1 commit:
  5789b904aa5 [Scalar] Commit the correct patch, forgot `git add`.
Sending        lldb/trunk/source/Utility/Scalar.cpp
Transmitting file data .done
Committing transaction...
Committed revision 341685.
Committed 5789b904aa5 to svn.

On Fri, Sep 7, 2018 at 11:12 AM Davide Italiano <dccitaliano at gmail.com> wrote:
>
> Note that we already have tests for this (that were failing [and
> hopefully they're not anymore])
> On Fri, Sep 7, 2018 at 11:04 AM Davide Italiano via lldb-commits
> <lldb-commits at lists.llvm.org> wrote:
> >
> > 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();
> >
> >
> > _______________________________________________
> > lldb-commits mailing list
> > lldb-commits at lists.llvm.org
> > http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


More information about the lldb-commits mailing list