[llvm] [DRAFT][NFC] Make RegState enum class (PR #172441)

Sam Elliott via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 16 10:16:29 PST 2025


================
@@ -138,39 +141,72 @@ class MachineInstrBuilder {
   Register getReg(unsigned Idx) const { return MI->getOperand(Idx).getReg(); }
 
   /// Add a new virtual register operand.
-  const MachineInstrBuilder &addReg(Register RegNo, unsigned flags = 0,
+  const MachineInstrBuilder &addReg(Register RegNo, RegState Flags = RegState::NoFlags,
                                     unsigned SubReg = 0) const {
-    assert((flags & 0x1) == 0 &&
+    assert((Flags & static_cast<RegState>(0x1)) == RegState::NoFlags &&
----------------
lenary wrote:

> Does the use of enum class prevent this kind of bug?

Potentially. There were two uses of `addReg(..., false)` which no longer have the problem.

However, I think if I have implicit casts to/from unsigned, that will cause us to not catch that kind of issue. 

https://github.com/llvm/llvm-project/pull/172441


More information about the llvm-commits mailing list