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:
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:
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits