================
@@ -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
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to