[PATCH] D65554: Prevent vregs leaking into the MC layer via TargetRegisterClass::contains()

Daniel Sanders via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 31 20:44:41 PDT 2019


dsanders created this revision.
dsanders added a reviewer: arsenm.
Herald added a subscriber: wdng.
Herald added a project: LLVM.

The MC layer doesn't expect to deal with vregs but
TargetRegisterClass::contains() forwards into MCRegisterClass::contains()
and this can cause vregs to turn up in the MC layer APIs. Add guards
against this to prevent this becoming a problem as we replace unsigned
with a new MCRegister object for improved type safety.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65554

Files:
  llvm/include/llvm/CodeGen/TargetRegisterInfo.h


Index: llvm/include/llvm/CodeGen/TargetRegisterInfo.h
===================================================================
--- llvm/include/llvm/CodeGen/TargetRegisterInfo.h
+++ llvm/include/llvm/CodeGen/TargetRegisterInfo.h
@@ -87,11 +87,16 @@
   /// Return true if the specified register is included in this register class.
   /// This does not include virtual registers.
   bool contains(unsigned Reg) const {
+    if (!Register::isPhysicalRegister(Reg))
+      return false;
     return MC->contains(Reg);
   }
 
   /// Return true if both registers are in this class.
   bool contains(unsigned Reg1, unsigned Reg2) const {
+    if (!Register::isPhysicalRegister(Reg1) ||
+        !Register::isPhysicalRegister(Reg2))
+      return false;
     return MC->contains(Reg1, Reg2);
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65554.212717.patch
Type: text/x-patch
Size: 787 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190801/e99fe262/attachment.bin>


More information about the llvm-commits mailing list