[PATCH] D140654: [MC] Use MCRegister instead of unsigned in MCInstPrinter (NFC)

Sergei Barannikov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 15 02:01:46 PST 2023


barannikov88 added inline comments.


================
Comment at: llvm/include/llvm/MC/MCInstPrinter.h:12
 
+#include "llvm/MC/MCRegister.h"
 #include "llvm/Support/Format.h"
----------------
craig.topper wrote:
> barannikov88 wrote:
> > craig.topper wrote:
> > > Can this be a forward reference?
> > Nope, it is passed by value in `printRegName` below (and also in generated `getRegisterName`).
> > 
> I thought the forward reference would be ok since only the declaration of printRegName is here. Isn’t it only needed for the definition and the call sites?
> 
> It’s late here so I might not be thinking clearly.
You're right. This code compiles without errors:
```
class MCRegister;

class MCInstPrinter {
public:
  virtual void printRegName(MCRegister Reg);
};

class MCRegister {
public:
  MCRegister(unsigned);
};

int main() {
  MCInstPrinter P;
  P.printRegName(MCRegister(0));
}
```
That's a surprise to me. I thought it is only possible to do this with references and pointers.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140654



More information about the llvm-commits mailing list