InstrEmitter.cpp - don't dereference a dyn_cast<>.
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Tue, 8 Jun 2021 15:42:28 +0000 (16:42 +0100)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Tue, 8 Jun 2021 16:59:04 +0000 (17:59 +0100)
dyn_cast<> can return nullptr which we would then dereference - use cast<> which will assert that the type is correct.

llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp

index 691cdc9..017231c 100644 (file)
@@ -1144,10 +1144,10 @@ EmitSpecialNode(SDNode *Node, bool IsClone, bool IsCloned,
 
   case ISD::LIFETIME_START:
   case ISD::LIFETIME_END: {
-    unsigned TarOp = (Node->getOpcode() == ISD::LIFETIME_START) ?
-    TargetOpcode::LIFETIME_START : TargetOpcode::LIFETIME_END;
-
-    FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(Node->getOperand(1));
+    unsigned TarOp = (Node->getOpcode() == ISD::LIFETIME_START)
+                         ? TargetOpcode::LIFETIME_START
+                         : TargetOpcode::LIFETIME_END;
+    auto *FI = cast<FrameIndexSDNode>(Node->getOperand(1));
     BuildMI(*MBB, InsertPos, Node->getDebugLoc(), TII->get(TarOp))
     .addFrameIndex(FI->getIndex());
     break;