[RISCV] Replace untested code with assert
authorFraser Cormack <fraser@codeplay.com>
Tue, 24 May 2022 06:20:55 +0000 (07:20 +0100)
committerFraser Cormack <fraser@codeplay.com>
Wed, 25 May 2022 04:03:53 +0000 (05:03 +0100)
We found untested code where negative frame indices were ostensibly
handled despite it being in a block guarded by !MFI.isFixedObjectIndex.

While the implementation of MachineFrameInfo::isFixedObjectIndex
suggests this is possible (i.e., if a frame index was more negative - less than the
number of fixed objects), I couldn't find any test in tree -- for any
target -- where a negative frame index wasn't also a fixed object
offset. I couldn't find a way of creating such a object with the
public MachineFrameInfo creation APIs. Even
MachineFrameInfo::getObjectIndexBegin starts counting at the negative
number of fixed objects, so such frame indices wouldn't be covered by
loops using the provided begin/end methods.

Given all this, an assert that any object encountered in the block is
non-negative seems reasonable.

Reviewed By: StephenFan, kito-cheng

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

llvm/lib/Target/RISCV/RISCVFrameLowering.cpp

index f774433..5be78a5 100644 (file)
@@ -757,8 +757,7 @@ RISCVFrameLowering::getFrameIndexReference(const MachineFunction &MF, int FI,
     // objects to the required alignment.
     if (MFI.getStackID(FI) == TargetStackID::Default) {
       Offset += StackOffset::getFixed(MFI.getStackSize());
-      if (FI < 0)
-        Offset += StackOffset::getFixed(RVFI->getLibCallStackSize());
+      assert(FI >= 0 && "Unhandled negative frame index");
     } else if (MFI.getStackID(FI) == TargetStackID::ScalableVector) {
       // Ensure the base of the RVV stack is correctly aligned: add on the
       // alignment padding.