[Lldb-commits] [PATCH] D134493: [lldb][TypeSystemClang] Deduce lldb::eEncodingUint for unsigned enum types
Michael Buch via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Thu Sep 22 15:41:13 PDT 2022
Michael137 created this revision.
Michael137 added reviewers: aprantl, jingham.
Herald added a project: All.
Michael137 requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.
The motivating issue was the following:
$ cat main.cpp
enum class EnumVals : uint16_t {
VAL1 = 0
};
struct Foo {
EnumVals b1 : 8;
};
int main() {
Foo f{.b1 = (EnumVals)8};
return 0; // Break here
}
(lldb) script
>>> lldb.frame.FindVariable("f").GetChildMemberWithName("b1").GetValueAsUnsigned()
4294967288
In the above example we observe a unsigned integer wrap-around
because we sign-extended the bit-fields underlying Scalar value
before casting it to an unsigned. The sign extension occurs because
we don't mark `APSInt::IsUnsigned == true` correctly when extracting
the value from memory (in Value::ResolveValue).
This patch corrects `GetEncoding` to account for unsigned enum types.
With this change the Scalar would be zero-extended instead.
This is mainly a convenience fix which well-formed code wouldn't
encounter.
rdar://99785324
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D134493
Files:
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
===================================================================
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -5097,7 +5097,9 @@
case clang::Type::Record:
break;
case clang::Type::Enum:
- return lldb::eEncodingSint;
+ return qual_type->isUnsignedIntegerOrEnumerationType()
+ ? lldb::eEncodingUint
+ : lldb::eEncodingSint;
case clang::Type::DependentSizedArray:
case clang::Type::DependentSizedExtVector:
case clang::Type::UnresolvedUsing:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134493.462337.patch
Type: text/x-patch
Size: 640 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220922/8f7d0fdc/attachment.bin>
More information about the lldb-commits
mailing list