[Lldb-commits] [PATCH] D82772: [lldb] Fix type conversion in the Scalar getters

Pavel Labath via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Jun 29 08:04:04 PDT 2020


labath created this revision.
labath added reviewers: teemperor, JDevlieghere.
Herald added a project: LLDB.

The Scalar class claims to follow the C type conversion rules. This is
true for the Promote function, but it is not true for the implicit
conversions done in the getter methods.

These functions had a subtle bug: when extending the type, they used the
signedness of the *target* type in order to determine whether to do
sign-extension or zero-extension. This is not how things work in C,
which uses the signedness of the *source* type. I.e., C does
(sign-)extension before it does signed->unsigned conversion, and not the
other way around.

This means that: (unsigned long)(int)-1

  is equal to (unsigned long)0xffffffffffffffff
  and not (unsigned long)0x00000000ffffffff

Unsurprisingly, we have accumulated code which depended on this
inconsistent behavior. It mainly manifested itself as code calling
"ULongLong/SLongLong" as a way to get the value of the Scalar object in
a primitive type that is "large enough". Previously, the ULongLong
conversion did not do sign-extension, but now it does.

This patch makes the Scalar getters consistent with the declared
semantics, and fixes the couple of call sites that were using it
incorrectly.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82772

Files:
  lldb/include/lldb/Utility/Scalar.h
  lldb/source/Core/ValueObject.cpp
  lldb/source/Expression/IRInterpreter.cpp
  lldb/source/Utility/Scalar.cpp
  lldb/test/API/commands/expression/ir-interpreter/TestIRInterpreter.py
  lldb/unittests/Utility/ScalarTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82772.274127.patch
Type: text/x-patch
Size: 11963 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20200629/8f3b4315/attachment-0001.bin>


More information about the lldb-commits mailing list