[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
Fri Sep 23 02:29:04 PDT 2022


Michael137 updated this revision to Diff 462427.
Michael137 added a comment.

- Add API test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D134493/new/

https://reviews.llvm.org/D134493

Files:
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
  lldb/test/API/python_api/sbvalue_unsigned_enum_bitfield_value/TestSBValueUnsignedEnumBitField.py
  lldb/test/API/python_api/sbvalue_unsigned_enum_bitfield_value/main.cpp


Index: lldb/test/API/python_api/sbvalue_unsigned_enum_bitfield_value/main.cpp
===================================================================
--- /dev/null
+++ lldb/test/API/python_api/sbvalue_unsigned_enum_bitfield_value/main.cpp
@@ -0,0 +1,14 @@
+#include <stdint.h>
+
+enum class EnumVals : uint16_t { VAL0 = 0 };
+
+struct Foo {
+  EnumVals b : 4;
+};
+
+int main(int argc, char const *argv[], char const *envp[]) {
+  Foo f{.b = static_cast<EnumVals>(8)};
+  return 0; //% b = self.frame().FindVariable("f").GetChildMemberWithName("b")
+            //% val = b.GetValueAsUnsigned()
+            //% self.assertEqual(val, 8, "Bit-field not correctly extracted")
+}
Index: lldb/test/API/python_api/sbvalue_unsigned_enum_bitfield_value/TestSBValueUnsignedEnumBitField.py
===================================================================
--- /dev/null
+++ lldb/test/API/python_api/sbvalue_unsigned_enum_bitfield_value/TestSBValueUnsignedEnumBitField.py
@@ -0,0 +1,18 @@
+"""
+Test that SBValue doesn't incorrectly sign-extend
+the Scalar value of a bitfield that has an unsigned
+enum type.
+
+This test relies on implementation-defined behaviour
+of initializing a bit-field with an out-of-range value.
+On clang this will do the expected thing of writing
+the full value into the bit-field and the trailing
+padding bits. Then during sign-extension (which
+shouldn't occur for unsigned bit-fields) it would
+left-fill the resulting Scalar with 1s; we test
+for this not to happen.
+"""
+
+import lldbsuite.test.lldbinline as lldbinline
+
+lldbinline.MakeInlineTest(__file__, globals())
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.462427.patch
Type: text/x-patch
Size: 2235 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220923/2a633d45/attachment-0001.bin>


More information about the lldb-commits mailing list