[Lldb-commits] [clang] [lldb] [lldb] Analyze enum promotion type during parsing (PR #115005)
Michael Buch via lldb-commits
lldb-commits at lists.llvm.org
Fri Jan 31 12:20:18 PST 2025
================
@@ -2367,11 +2369,36 @@ size_t DWARFASTParserClang::ParseChildEnumerators(
}
if (name && name[0] && got_value) {
- m_ast.AddEnumerationValueToEnumerationType(
+ auto ECD = m_ast.AddEnumerationValueToEnumerationType(
----------------
Michael137 wrote:
Apologies I still don't follow. Why can't `computeEnumBits` just be:
```
template <typename RangeT>
bool computeEnumBits(RangeT EnumConstants, unsigned &NumNegativeBits,
unsigned &NumPositiveBits) {
unsigned NumNegativeBits = 0;
unsigned NumPositiveBits = 0;
bool MembersRepresentableByInt = true;
for (auto * Elem : EnumConstants) {
EnumConstantDecl *ECD =
cast_or_null<EnumConstantDecl>(Elem);
if (!ECD) continue; // Already issued a diagnostic.
llvm::APSInt InitVal = ECD->getInitVal();
if (InitVal.isUnsigned() || InitVal.isNonNegative()) {
// If the enumerator is zero that should still be counted as a positive
// bit since we need a bit to store the value zero.
unsigned ActiveBits = InitVal.getActiveBits();
NumPositiveBits = std::max({NumPositiveBits, ActiveBits, 1u});
} else {
NumNegativeBits =
std::max(NumNegativeBits, (unsigned)InitVal.getSignificantBits());
}
MembersRepresentableByInt &=
isRepresentableIntegerValue(InitVal, IntTy);
}
// If we have an empty set of enumerators we still need one bit.
// From [dcl.enum]p8
// If the enumerator-list is empty, the values of the enumeration are as if
// the enumeration had a single enumerator with value 0
if (!NumPositiveBits && !NumNegativeBits)
NumPositiveBits = 1;
return MembersRepresentableByInt;
}
```
And `SemaDecl.cpp` just does:
```
unsigned NumNegativeBits;
unsigned NumPositiveBits;
bool MembersRepresentableByInt = Context.computeEnumBits(Elements, NumNegativeBits, NumPositiveBits);
```
?
https://github.com/llvm/llvm-project/pull/115005
More information about the lldb-commits
mailing list