Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Assertion in MachineFrameInfo::getObjectOffset() when emitting debug info #11294

Closed Quuxplusone closed 13 years ago

Quuxplusone commented 13 years ago
Bugzilla Link PR11105
Status RESOLVED FIXED
Importance P normal
Reported by Richard Osborne (richard@xmos.com)
Reported on 2011-10-10 11:43:32 -0700
Last modified on 2011-10-11 08:12:06 -0700
Version trunk
Hardware PC Linux
CC richard@xmos.com
Fixed by commit(s)
Attachments bugpoint-reduced-simplified.ll (4960 bytes, application/octet-stream)
Blocks
Blocked by
See also
Created attachment 7434
bugpoint-reduced-simplified.ll

Running llc at -O1 or above with the attached testcase results in the following
assertion:

llc: /homelocal/richard/llvm_svn/include/llvm/CodeGen/MachineFrameInfo.h:378:
int64_t llvm::MachineFrameInfo::getObjectOffset(int) const: Assertion
`unsigned(ObjectIdx+NumFixedObjects) < Objects.size() && "Invalid Object Idx!"'
failed.
Quuxplusone commented 13 years ago

Attached bugpoint-reduced-simplified.ll (4960 bytes, application/octet-stream): bugpoint-reduced-simplified.ll

Quuxplusone commented 13 years ago
The problem is as follows. In XCoreRegisterInfo::eliminateFrameIndex() we
replace the frame index of a dbg_value machine instruction with the frame
register and set the next operand to the offset:

  // Special handling of DBG_VALUE instructions.
  if (MI.isDebugValue()) {
    MI.getOperand(i).ChangeToRegister(FrameReg, false /*isDef*/);
    MI.getOperand(i+1).ChangeToImmediate(Offset);
    return;
  }

This results in the second operand of the dbg_value being set to the byte
offset from the frame register.

However in CompileUnit::constructVariableDIE it seems to expect the second
operand of dbg_value to be the frame index since it passes it to
TargetFrameLowering::getFrameIndexReference:

    if (DVInsn->getNumOperands() == 3) {
      if (DVInsn->getOperand(0).isReg()) {
        const MachineOperand RegOp = DVInsn->getOperand(0);
        const TargetRegisterInfo *TRI = Asm->TM.getRegisterInfo();
        if (DVInsn->getOperand(1).isImm() &&
            TRI->getFrameRegister(*Asm->MF) == RegOp.getReg()) {
          unsigned FrameReg = 0;
          const TargetFrameLowering *TFI = Asm->TM.getFrameLowering();
          int Offset =
            TFI->getFrameIndexReference(*Asm->MF,
                                        DVInsn->getOperand(1).getImm(),
                                        FrameReg);

In the testcase in this bug the byte offset of the variable is larger than
biggest frame index and so MachineFrameInfo::getObjectOffset() asserts.
Quuxplusone commented 13 years ago

Fixed in r141666 by implementing the emitFrameIndexDebugValue() and getDebugValueLocation() hooks.