[PATCH] D32868: [globalisel][tablegen] Fix nullptr dereferences when getVRegDef() is called on a phys reg.

Quentin Colombet via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 12 13:59:36 PDT 2017


qcolombet added inline comments.


================
Comment at: test/TableGen/GlobalISelEmitter.td:141-142
 // CHECK-NEXT:      return false;
-// CHECK-NEXT:    MachineInstr &MI1 = *MRI.getVRegDef(MI0.getOperand(1).getReg());
-// CHECK-NEXT:    if (MI1.getNumOperands() < 3)
+// CHECK-NEXT:    MachineInstr *MI1 = MRI.getVRegDef(MI0->getOperand(1).getReg());
+// CHECK-NEXT:    if (!MI1 || MI1->getNumOperands() < 3)
 // CHECK-NEXT:      return false;
----------------
dsanders wrote:
> There's only a couple of them in the test at the moment but here's one of the getVRegDef's.
> 
> getVRegDef() returns a pointer to the MI that def's the register or nullptr otherwise. Previously, we unconditionally dereferenced it which caused a nullptr dereference when the register was live-in but now we check for the nullptr first.
Here is it, I missed it with my previous search :).

I would rather have a check before the getVRegDef whether the register is a vreg or not.
I know getVRegDef works with PhysReg, but in practice we try not to call it on then, because it is strange :).


https://reviews.llvm.org/D32868





More information about the llvm-commits mailing list