[PATCH] D65678: Register/MCRegister: Add conversion operators to avoid use of implicit convert to unsigned. NFC

Daniel Sanders via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 5 17:55:46 PDT 2019


dsanders marked an inline comment as done.
dsanders added inline comments.


================
Comment at: llvm/include/llvm/CodeGen/Register.h:127-128
+  bool operator!=(unsigned Other) const { return Reg != Other; }
+  bool operator==(int Other) const { return Reg == unsigned(Other); }
+  bool operator!=(int Other) const { return Reg != unsigned(Other); }
 };
----------------
dsanders wrote:
> arsenm wrote:
> > Why are both the signed and unsigned versions necessary?
> For the unsigned case, it's because it can't tell which operator to use for `MCRegister == unsigned`. It can do either:
> * `MCRegister::operator==(*this, MCRegister(Other))`
> * or, `unsigned::operator==(unsigned(*this), Other)`
> 
> For the signed case, it's the same problem but the `operator==(MCRegister, unsigned)` is also a candidate
> 
> https://godbolt.org/z/8JMcTs
It turns out MSVC needed one for unsigned short (MCPhysReg) too. That change has been made in the re-commit (r367965) but I should mention that I also moved MCPhysReg's declaration to MCRegister.h so that it can use the real name.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D65678





More information about the llvm-commits mailing list