Guard against dereferencing a nullptr
authorAkshay Khadse <akshayskhadse@gmail.com>
Sat, 15 Apr 2023 03:28:50 +0000 (11:28 +0800)
committerLuo, Yuanke <yuanke.luo@intel.com>
Sat, 15 Apr 2023 03:30:43 +0000 (11:30 +0800)
In `lib/CodeGen/PrologEpilogInserter.cpp` file, `RS` is assigned via `RS = TRI->requiresRegisterScavenging(MF) ? new RegScavenger() : nullptr;`. This means that `RS` can be `nullptr`. While executing the `TFI->processFunctionBeforeFrameFinalized(MF, RS);`, the `RS` can be dereferenced in the call `RS->enterBasicBlock(MBB);` in file `lib/Target/AMDGPU/SIFrameLowering.cpp`

Reviewed By: skan, arsenm

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

llvm/lib/Target/AMDGPU/SIFrameLowering.cpp

index c2bc959..3e45d33 100644 (file)
@@ -1350,6 +1350,7 @@ void SIFrameLowering::processFunctionBeforeFrameFinalized(
             TII->getNamedOperand(MI, AMDGPU::OpName::vdata)->getReg();
           if (FuncInfo->allocateVGPRSpillToAGPR(MF, FI,
                                                 TRI->isAGPR(MRI, VReg))) {
+            assert(RS != nullptr);
             // FIXME: change to enterBasicBlockEnd()
             RS->enterBasicBlock(MBB);
             TRI->eliminateFrameIndex(MI, 0, FIOp, RS);