[llvm] r232525 - Add assertion to detect invalid registers in the PowerPC MC instruction lowering.

Samuel Antao sfantao at us.ibm.com
Tue Mar 17 12:31:19 PDT 2015

Author: sfantao
Date: Tue Mar 17 14:31:19 2015
New Revision: 232525

URL: http://llvm.org/viewvc/llvm-project?rev=232525&view=rev
Add assertion to detect invalid registers in the PowerPC MC instruction lowering.

We have observed that noreg was being generated due to a bug in FastIsel and was not being detected during emission. It happens that in the Asm emission there is an assertion that detects this in getRegisterName() from the tbl-generated file PPCGenAsmWriter.inc. However, when emitting an Obj file, invalid registers can be emitted given that no check are made in getBinaryCodeFromInstr() from PPCGenMCCodeEmitter.inc. In order to cover all cases this adds an assertion for reg operands in LowerPPCMachineInstrToMCInst.


Modified: llvm/trunk/lib/Target/PowerPC/PPCMCInstLower.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCMCInstLower.cpp?rev=232525&r1=232524&r2=232525&view=diff
--- llvm/trunk/lib/Target/PowerPC/PPCMCInstLower.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/PPCMCInstLower.cpp Tue Mar 17 14:31:19 2015
@@ -184,6 +184,9 @@ void llvm::LowerPPCMachineInstrToMCInst(
       llvm_unreachable("unknown operand type");
     case MachineOperand::MO_Register:
       assert(!MO.getSubReg() && "Subregs should be eliminated!");
+      assert(MO.getReg() > PPC::NoRegister &&
+             MO.getReg() < PPC::NUM_TARGET_REGS &&
+             "Invalid register for this target!");
       MCOp = MCOperand::CreateReg(MO.getReg());
     case MachineOperand::MO_Immediate:

More information about the llvm-commits mailing list