Skip to content

Commit 927def4

Browse files
committed
Revert "[lldb] Print empty enums as if they were unrecognised normal enums (#97553)"
This reverts commit 41fddc4. Due to build errors with gcc passing signed ints to unsigned ints.
1 parent ebab105 commit 927def4

File tree

3 files changed

+22
-43
lines changed

3 files changed

+22
-43
lines changed

lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8656,25 +8656,20 @@ static bool DumpEnumValue(const clang::QualType &qual_type, Stream &s,
86568656
// every enumerator is either a one bit value or a superset of the previous
86578657
// enumerators. Also 0 doesn't make sense when the enumerators are used as
86588658
// flags.
8659-
clang::EnumDecl::enumerator_range enumerators = enum_decl->enumerators();
8660-
if (enumerators.empty())
8661-
can_be_bitfield = false;
8662-
else {
8663-
for (auto *enumerator : enumerators) {
8664-
llvm::APSInt init_val = enumerator->getInitVal();
8665-
uint64_t val = qual_type_is_signed ? init_val.getSExtValue()
8666-
: init_val.getZExtValue();
8667-
if (qual_type_is_signed)
8668-
val = llvm::SignExtend64(val, 8 * byte_size);
8669-
if (llvm::popcount(val) != 1 && (val & ~covered_bits) != 0)
8670-
can_be_bitfield = false;
8671-
covered_bits |= val;
8672-
++num_enumerators;
8673-
if (val == enum_svalue) {
8674-
// Found an exact match, that's all we need to do.
8675-
s.PutCString(enumerator->getNameAsString());
8676-
return true;
8677-
}
8659+
for (auto *enumerator : enum_decl->enumerators()) {
8660+
llvm::APSInt init_val = enumerator->getInitVal();
8661+
uint64_t val =
8662+
qual_type_is_signed ? init_val.getSExtValue() : init_val.getZExtValue();
8663+
if (qual_type_is_signed)
8664+
val = llvm::SignExtend64(val, 8 * byte_size);
8665+
if (llvm::popcount(val) != 1 && (val & ~covered_bits) != 0)
8666+
can_be_bitfield = false;
8667+
covered_bits |= val;
8668+
++num_enumerators;
8669+
if (val == enum_svalue) {
8670+
// Found an exact match, that's all we need to do.
8671+
s.PutCString(enumerator->getNameAsString());
8672+
return true;
86788673
}
86798674
}
86808675

lldb/test/Shell/SymbolFile/DWARF/x86/debug-types-missing-signature.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ PRINTEC: use of undeclared identifier 'EC'
2222

2323
RUN: %lldb %t -b -o "target variable a e ec" | FileCheck --check-prefix=VARS %s
2424
VARS: (const (unnamed struct)) a = <incomplete type "const (unnamed struct)">
25-
VARS: (const (unnamed enum)) e = 1
26-
VARS: (const (unnamed enum)) ec = 1
25+
VARS: (const (unnamed enum)) e = 0x1
26+
VARS: (const (unnamed enum)) ec = 0x1

lldb/unittests/ValueObject/DumpValueObjectOptionsTests.cpp

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,12 @@ class ValueObjectMockProcessTest : public ::testing::Test {
7171
}
7272

7373
CompilerType
74-
MakeEnumType(const std::vector<std::pair<const char *, int>> enumerators,
75-
bool is_signed) {
76-
CompilerType int_type = m_type_system->GetBuiltinTypeForEncodingAndBitSize(
77-
is_signed ? lldb::eEncodingSint : lldb::eEncodingUint, 32);
74+
MakeEnumType(const std::vector<std::pair<const char *, int>> enumerators) {
75+
CompilerType uint_type = m_type_system->GetBuiltinTypeForEncodingAndBitSize(
76+
lldb::eEncodingUint, 32);
7877
CompilerType enum_type = m_type_system->CreateEnumerationType(
7978
"TestEnum", m_type_system->GetTranslationUnitDecl(),
80-
OptionalClangModuleID(), Declaration(), int_type, false);
79+
OptionalClangModuleID(), Declaration(), uint_type, false);
8180

8281
m_type_system->StartTagDeclarationDefinition(enum_type);
8382
Declaration decl;
@@ -124,27 +123,12 @@ class ValueObjectMockProcessTest : public ::testing::Test {
124123
lldb::ProcessSP m_process_sp;
125124
};
126125

127-
TEST_F(ValueObjectMockProcessTest, EmptyEnum) {
128-
// All values of an empty enum should be shown as plain numbers.
129-
TestDumpValueObject(MakeEnumType({}, false),
130-
{{0, {}, "(TestEnum) test_var = 0\n"},
131-
{1, {}, "(TestEnum) test_var = 1\n"},
132-
{2, {}, "(TestEnum) test_var = 2\n"}});
133-
134-
TestDumpValueObject(MakeEnumType({}, true),
135-
{{-2, {}, "(TestEnum) test_var = -2\n"},
136-
{-1, {}, "(TestEnum) test_var = -1\n"},
137-
{0, {}, "(TestEnum) test_var = 0\n"},
138-
{1, {}, "(TestEnum) test_var = 1\n"},
139-
{2, {}, "(TestEnum) test_var = 2\n"}});
140-
}
141-
142126
TEST_F(ValueObjectMockProcessTest, Enum) {
143127
// This is not a bitfield-like enum, so values are printed as decimal by
144128
// default. Also we only show the enumerator name if the value is an
145129
// exact match.
146130
TestDumpValueObject(
147-
MakeEnumType({{"test_2", 2}, {"test_3", 3}}, false),
131+
MakeEnumType({{"test_2", 2}, {"test_3", 3}}),
148132
{{0, {}, "(TestEnum) test_var = 0\n"},
149133
{1, {}, "(TestEnum) test_var = 1\n"},
150134
{2, {}, "(TestEnum) test_var = test_2\n"},
@@ -168,7 +152,7 @@ TEST_F(ValueObjectMockProcessTest, BitFieldLikeEnum) {
168152
// as hex, and values without exact matches are shown as a combination of
169153
// enumerators and any remaining value left over.
170154
TestDumpValueObject(
171-
MakeEnumType({{"test_2", 2}, {"test_4", 4}}, false),
155+
MakeEnumType({{"test_2", 2}, {"test_4", 4}}),
172156
{
173157
{0, {}, "(TestEnum) test_var = 0x0\n"},
174158
{1, {}, "(TestEnum) test_var = 0x1\n"},

0 commit comments

Comments
 (0)