[llvm] f55fdde - [MIPS] selectAddrFrameIndexOffset - use cast<> instead of dyn_cast<> to avoid dereference of nullptr

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 5 09:20:52 PDT 2022


Author: Simon Pilgrim
Date: 2022-04-05T17:20:39+01:00
New Revision: f55fdded794344aade9380c2657895a8294b979e

URL: https://github.com/llvm/llvm-project/commit/f55fdded794344aade9380c2657895a8294b979e
DIFF: https://github.com/llvm/llvm-project/commit/f55fdded794344aade9380c2657895a8294b979e.diff

LOG: [MIPS] selectAddrFrameIndexOffset - use cast<> instead of dyn_cast<> to avoid dereference of nullptr

The pointer is used immediately below, so assert the cast is correct instead of returning nullptr

Added: 
    

Modified: 
    llvm/lib/Target/Mips/MipsSEISelDAGToDAG.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/Mips/MipsSEISelDAGToDAG.cpp b/llvm/lib/Target/Mips/MipsSEISelDAGToDAG.cpp
index 03a545605fe16..676f7754322c4 100644
--- a/llvm/lib/Target/Mips/MipsSEISelDAGToDAG.cpp
+++ b/llvm/lib/Target/Mips/MipsSEISelDAGToDAG.cpp
@@ -282,7 +282,7 @@ bool MipsSEDAGToDAGISel::selectAddrFrameIndexOffset(
     SDValue Addr, SDValue &Base, SDValue &Offset, unsigned OffsetBits,
     unsigned ShiftAmount = 0) const {
   if (CurDAG->isBaseWithConstantOffset(Addr)) {
-    ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Addr.getOperand(1));
+    auto *CN = cast<ConstantSDNode>(Addr.getOperand(1));
     if (isIntN(OffsetBits + ShiftAmount, CN->getSExtValue())) {
       EVT ValTy = Addr.getValueType();
 


        


More information about the llvm-commits mailing list