]> granicus.if.org Git - llvm/commitdiff
Prevent vregs leaking into the MC layer via TargetRegisterClass::contains()
authorDaniel Sanders <daniel_l_sanders@apple.com>
Thu, 1 Aug 2019 23:44:42 +0000 (23:44 +0000)
committerDaniel Sanders <daniel_l_sanders@apple.com>
Thu, 1 Aug 2019 23:44:42 +0000 (23:44 +0000)
Summary:
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.

Reviewers: arsenm

Subscribers: wdng, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D65554

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@367636 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/TargetRegisterInfo.h

index dd88f250a21fe816ff80e9fa76cb948dc953a6f4..8c98d626b6d70159ba8e3fb9390b950caa48ee39 100644 (file)
@@ -87,11 +87,20 @@ public:
   /// Return true if the specified register is included in this register class.
   /// This does not include virtual registers.
   bool contains(unsigned Reg) const {
+    /// FIXME: Historically this function has returned false when given vregs
+    ///        but it should probably only receive physical registers
+    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 {
+    /// FIXME: Historically this function has returned false when given a vregs
+    ///        but it should probably only receive physical registers
+    if (!Register::isPhysicalRegister(Reg1) ||
+        !Register::isPhysicalRegister(Reg2))
+      return false;
     return MC->contains(Reg1, Reg2);
   }