Skip to content

Commit f99e6df

Browse files
authored
[lldb][TypeSystemClang] Pass around enum value as uint64_t (#125244)
The `DWARFASTParserClang` reads enum values as `int64_t`s regardless of the enumerators signedness. Then we pass it to `AddEnumerationValueToEnumerationType` and only then do we create an `APSInt` from it. However, there are other places where we read/pass around the enum value as unsigned. This patch makes sure we consistently use the same integer type for the enum value and let `APSInt` take care of signedness. This shouldn't have any observable effect.
1 parent b84f7d1 commit f99e6df

File tree

4 files changed

+9
-13
lines changed

4 files changed

+9
-13
lines changed

lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2321,8 +2321,7 @@ size_t DWARFASTParserClang::ParseChildEnumerators(
23212321
continue;
23222322

23232323
const char *name = nullptr;
2324-
bool got_value = false;
2325-
int64_t enum_value = 0;
2324+
std::optional<uint64_t> enum_value;
23262325
Declaration decl;
23272326

23282327
for (size_t i = 0; i < attributes.Size(); ++i) {
@@ -2331,7 +2330,6 @@ size_t DWARFASTParserClang::ParseChildEnumerators(
23312330
if (attributes.ExtractFormValueAtIndex(i, form_value)) {
23322331
switch (attr) {
23332332
case DW_AT_const_value:
2334-
got_value = true;
23352333
if (is_signed)
23362334
enum_value = form_value.Signed();
23372335
else
@@ -2360,9 +2358,9 @@ size_t DWARFASTParserClang::ParseChildEnumerators(
23602358
}
23612359
}
23622360

2363-
if (name && name[0] && got_value) {
2361+
if (name && name[0] && enum_value) {
23642362
m_ast.AddEnumerationValueToEnumerationType(
2365-
clang_type, decl, name, enum_value, enumerator_byte_size * 8);
2363+
clang_type, decl, name, *enum_value, enumerator_byte_size * 8);
23662364
++enumerators_added;
23672365
}
23682366
}

lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1155,7 +1155,7 @@ bool PDBASTParser::AddEnumValue(CompilerType enum_type,
11551155
Variant v = enum_value.getValue();
11561156
std::string name =
11571157
std::string(MSVCUndecoratedNameParser::DropScope(enum_value.getName()));
1158-
int64_t raw_value;
1158+
uint64_t raw_value;
11591159
switch (v.Type) {
11601160
case PDB_VariantType::Int8:
11611161
raw_value = v.Value.Int8;

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8541,12 +8541,10 @@ clang::EnumConstantDecl *TypeSystemClang::AddEnumerationValueToEnumerationType(
85418541

85428542
clang::EnumConstantDecl *TypeSystemClang::AddEnumerationValueToEnumerationType(
85438543
const CompilerType &enum_type, const Declaration &decl, const char *name,
8544-
int64_t enum_value, uint32_t enum_value_bit_size) {
8545-
CompilerType underlying_type = GetEnumerationIntegerType(enum_type);
8546-
bool is_signed = false;
8547-
underlying_type.IsIntegerType(is_signed);
8548-
8549-
llvm::APSInt value(enum_value_bit_size, !is_signed);
8544+
uint64_t enum_value, uint32_t enum_value_bit_size) {
8545+
assert(enum_type.IsEnumerationType());
8546+
llvm::APSInt value(enum_value_bit_size,
8547+
!enum_type.IsEnumerationIntegerTypeSigned());
85508548
value = enum_value;
85518549

85528550
return AddEnumerationValueToEnumerationType(enum_type, decl, name, value);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,7 @@ class TypeSystemClang : public TypeSystem {
10401040
// Modifying Enumeration types
10411041
clang::EnumConstantDecl *AddEnumerationValueToEnumerationType(
10421042
const CompilerType &enum_type, const Declaration &decl, const char *name,
1043-
int64_t enum_value, uint32_t enum_value_bit_size);
1043+
uint64_t enum_value, uint32_t enum_value_bit_size);
10441044
clang::EnumConstantDecl *AddEnumerationValueToEnumerationType(
10451045
const CompilerType &enum_type, const Declaration &decl, const char *name,
10461046
const llvm::APSInt &value);

0 commit comments

Comments
 (0)