[llvm] 842dc35 - Guard against dereferencing a nullptr
    via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Fri Apr 14 20:31:26 PDT 2023
    
    
  
Author: Akshay Khadse
Date: 2023-04-15T11:30:43+08:00
New Revision: 842dc35fc93203751047490f2989360b15ea67d1
URL: https://github.com/llvm/llvm-project/commit/842dc35fc93203751047490f2989360b15ea67d1
DIFF: https://github.com/llvm/llvm-project/commit/842dc35fc93203751047490f2989360b15ea67d1.diff
LOG: Guard against dereferencing a nullptr
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
Added: 
    
Modified: 
    llvm/lib/Target/AMDGPU/SIFrameLowering.cpp
Removed: 
    
################################################################################
diff  --git a/llvm/lib/Target/AMDGPU/SIFrameLowering.cpp b/llvm/lib/Target/AMDGPU/SIFrameLowering.cpp
index c2bc95930272c..3e45d33fc1189 100644
--- a/llvm/lib/Target/AMDGPU/SIFrameLowering.cpp
+++ b/llvm/lib/Target/AMDGPU/SIFrameLowering.cpp
@@ -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);
        
    
    
More information about the llvm-commits
mailing list