[Lldb-commits] [lldb] 927def4 - Revert "[lldb] Print empty enums as if they were unrecognised normal enums (#97553)"

David Spickett via lldb-commits lldb-commits at lists.llvm.org
Thu Jul 4 00:51:15 PDT 2024


Author: David Spickett
Date: 2024-07-04T07:49:36Z
New Revision: 927def49728371d746476e79a6570cd93a4d335c

URL: https://github.com/llvm/llvm-project/commit/927def49728371d746476e79a6570cd93a4d335c
DIFF: https://github.com/llvm/llvm-project/commit/927def49728371d746476e79a6570cd93a4d335c.diff

LOG: Revert "[lldb] Print empty enums as if they were unrecognised normal enums (#97553)"

This reverts commit 41fddc4ec3302f125a5b84ae86c8027dedc89984.

Due to build errors with gcc passing signed ints to unsigned ints.

Added: 
    

Modified: 
    lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
    lldb/test/Shell/SymbolFile/DWARF/x86/debug-types-missing-signature.test
    lldb/unittests/ValueObject/DumpValueObjectOptionsTests.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index f70efe5ed57e4..9c77a5d6e66ee 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -8656,25 +8656,20 @@ static bool DumpEnumValue(const clang::QualType &qual_type, Stream &s,
   // every enumerator is either a one bit value or a superset of the previous
   // enumerators. Also 0 doesn't make sense when the enumerators are used as
   // flags.
-  clang::EnumDecl::enumerator_range enumerators = enum_decl->enumerators();
-  if (enumerators.empty())
-    can_be_bitfield = false;
-  else {
-    for (auto *enumerator : enumerators) {
-      llvm::APSInt init_val = enumerator->getInitVal();
-      uint64_t val = qual_type_is_signed ? init_val.getSExtValue()
-                                         : init_val.getZExtValue();
-      if (qual_type_is_signed)
-        val = llvm::SignExtend64(val, 8 * byte_size);
-      if (llvm::popcount(val) != 1 && (val & ~covered_bits) != 0)
-        can_be_bitfield = false;
-      covered_bits |= val;
-      ++num_enumerators;
-      if (val == enum_svalue) {
-        // Found an exact match, that's all we need to do.
-        s.PutCString(enumerator->getNameAsString());
-        return true;
-      }
+  for (auto *enumerator : enum_decl->enumerators()) {
+    llvm::APSInt init_val = enumerator->getInitVal();
+    uint64_t val =
+        qual_type_is_signed ? init_val.getSExtValue() : init_val.getZExtValue();
+    if (qual_type_is_signed)
+      val = llvm::SignExtend64(val, 8 * byte_size);
+    if (llvm::popcount(val) != 1 && (val & ~covered_bits) != 0)
+      can_be_bitfield = false;
+    covered_bits |= val;
+    ++num_enumerators;
+    if (val == enum_svalue) {
+      // Found an exact match, that's all we need to do.
+      s.PutCString(enumerator->getNameAsString());
+      return true;
     }
   }
 

diff  --git a/lldb/test/Shell/SymbolFile/DWARF/x86/debug-types-missing-signature.test b/lldb/test/Shell/SymbolFile/DWARF/x86/debug-types-missing-signature.test
index b2c792ed6003e..548dd6cdbc275 100644
--- a/lldb/test/Shell/SymbolFile/DWARF/x86/debug-types-missing-signature.test
+++ b/lldb/test/Shell/SymbolFile/DWARF/x86/debug-types-missing-signature.test
@@ -22,5 +22,5 @@ PRINTEC: use of undeclared identifier 'EC'
 
 RUN: %lldb %t -b -o "target variable a e ec" | FileCheck --check-prefix=VARS %s
 VARS: (const (unnamed struct)) a = <incomplete type "const (unnamed struct)">
-VARS: (const (unnamed enum)) e = 1
-VARS: (const (unnamed enum)) ec = 1
+VARS: (const (unnamed enum)) e = 0x1
+VARS: (const (unnamed enum)) ec = 0x1

diff  --git a/lldb/unittests/ValueObject/DumpValueObjectOptionsTests.cpp b/lldb/unittests/ValueObject/DumpValueObjectOptionsTests.cpp
index af6fa55bab171..a7ccd74721f66 100644
--- a/lldb/unittests/ValueObject/DumpValueObjectOptionsTests.cpp
+++ b/lldb/unittests/ValueObject/DumpValueObjectOptionsTests.cpp
@@ -71,13 +71,12 @@ class ValueObjectMockProcessTest : public ::testing::Test {
   }
 
   CompilerType
-  MakeEnumType(const std::vector<std::pair<const char *, int>> enumerators,
-               bool is_signed) {
-    CompilerType int_type = m_type_system->GetBuiltinTypeForEncodingAndBitSize(
-        is_signed ? lldb::eEncodingSint : lldb::eEncodingUint, 32);
+  MakeEnumType(const std::vector<std::pair<const char *, int>> enumerators) {
+    CompilerType uint_type = m_type_system->GetBuiltinTypeForEncodingAndBitSize(
+        lldb::eEncodingUint, 32);
     CompilerType enum_type = m_type_system->CreateEnumerationType(
         "TestEnum", m_type_system->GetTranslationUnitDecl(),
-        OptionalClangModuleID(), Declaration(), int_type, false);
+        OptionalClangModuleID(), Declaration(), uint_type, false);
 
     m_type_system->StartTagDeclarationDefinition(enum_type);
     Declaration decl;
@@ -124,27 +123,12 @@ class ValueObjectMockProcessTest : public ::testing::Test {
   lldb::ProcessSP m_process_sp;
 };
 
-TEST_F(ValueObjectMockProcessTest, EmptyEnum) {
-  // All values of an empty enum should be shown as plain numbers.
-  TestDumpValueObject(MakeEnumType({}, false),
-                      {{0, {}, "(TestEnum) test_var = 0\n"},
-                       {1, {}, "(TestEnum) test_var = 1\n"},
-                       {2, {}, "(TestEnum) test_var = 2\n"}});
-
-  TestDumpValueObject(MakeEnumType({}, true),
-                      {{-2, {}, "(TestEnum) test_var = -2\n"},
-                       {-1, {}, "(TestEnum) test_var = -1\n"},
-                       {0, {}, "(TestEnum) test_var = 0\n"},
-                       {1, {}, "(TestEnum) test_var = 1\n"},
-                       {2, {}, "(TestEnum) test_var = 2\n"}});
-}
-
 TEST_F(ValueObjectMockProcessTest, Enum) {
   // This is not a bitfield-like enum, so values are printed as decimal by
   // default. Also we only show the enumerator name if the value is an
   // exact match.
   TestDumpValueObject(
-      MakeEnumType({{"test_2", 2}, {"test_3", 3}}, false),
+      MakeEnumType({{"test_2", 2}, {"test_3", 3}}),
       {{0, {}, "(TestEnum) test_var = 0\n"},
        {1, {}, "(TestEnum) test_var = 1\n"},
        {2, {}, "(TestEnum) test_var = test_2\n"},
@@ -168,7 +152,7 @@ TEST_F(ValueObjectMockProcessTest, BitFieldLikeEnum) {
   // as hex, and values without exact matches are shown as a combination of
   // enumerators and any remaining value left over.
   TestDumpValueObject(
-      MakeEnumType({{"test_2", 2}, {"test_4", 4}}, false),
+      MakeEnumType({{"test_2", 2}, {"test_4", 4}}),
       {
           {0, {}, "(TestEnum) test_var = 0x0\n"},
           {1, {}, "(TestEnum) test_var = 0x1\n"},


        


More information about the lldb-commits mailing list