[PATCH] D130301: [Clang] Fix how we set the NumPositiveBits on an E numDecl to cover the case of single enumerator with value zero or an empty enum

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 25 07:53:12 PDT 2022


aaron.ballman requested changes to this revision.
aaron.ballman added a comment.
This revision now requires changes to proceed.

Requesting changes until we have an answer for the testing situation.



================
Comment at: clang/lib/Sema/SemaDecl.cpp:18883-18884
+      // If the enumerator is zero that should still be counted as a positive
+      // bit since we need a bit to store the value zero
+      const unsigned ActiveBits = InitVal.getActiveBits();
+      NumPositiveBits = std::max({NumPositiveBits, ActiveBits, 1u});
----------------
Add trailing punctuation, removes top-level `const`.


================
Comment at: clang/lib/Sema/SemaDecl.cpp:18892
 
+  // If we have have a empty set of enumerators we still need one bit.
+  // From [dcl.enum]p8
----------------



================
Comment at: compiler-rt/test/ubsan/TestCases/Misc/enum.cpp:27
+  return ((int)e1 != -1) & ((int)e2 != -1) &
+         // CHECK: error: load of value <unknown>, which is not a valid value for type 'enum EBool'
+         ((int)e3 != -1) & ((int)e4 == 1) &
----------------
erichkeane wrote:
> What does THIS come from?  What value is unknown?  Shouldn't the -1 be fine?
+1, I'm surprised by the `<unknown>` there, but also... neither `e1` nor `e2` are of type `enum EBool`!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130301/new/

https://reviews.llvm.org/D130301



More information about the cfe-commits mailing list