BPFISelDAGToDAG.cpp - don't dereference a dyn_cast<> result. NFCI.
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Sun, 6 Jun 2021 12:24:02 +0000 (13:24 +0100)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Sun, 6 Jun 2021 12:24:29 +0000 (13:24 +0100)
Use cast<> instead which will assert that the cast is correct and not just return null.

Fixes static analysis warnings.

llvm/lib/Target/BPF/BPFISelDAGToDAG.cpp

index f10a0d4..eb506d3 100644 (file)
@@ -100,7 +100,7 @@ private:
 bool BPFDAGToDAGISel::SelectAddr(SDValue Addr, SDValue &Base, SDValue &Offset) {
   // if Address is FI, get the TargetFrameIndex.
   SDLoc DL(Addr);
-  if (FrameIndexSDNode *FIN = dyn_cast<FrameIndexSDNode>(Addr)) {
+  if (auto *FIN = dyn_cast<FrameIndexSDNode>(Addr)) {
     Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), MVT::i64);
     Offset = CurDAG->getTargetConstant(0, DL, MVT::i64);
     return true;
@@ -112,12 +112,10 @@ bool BPFDAGToDAGISel::SelectAddr(SDValue Addr, SDValue &Base, SDValue &Offset) {
 
   // Addresses of the form Addr+const or Addr|const
   if (CurDAG->isBaseWithConstantOffset(Addr)) {
-    ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Addr.getOperand(1));
+    auto *CN = cast<ConstantSDNode>(Addr.getOperand(1));
     if (isInt<16>(CN->getSExtValue())) {
-
       // If the first operand is a FI, get the TargetFI Node
-      if (FrameIndexSDNode *FIN =
-              dyn_cast<FrameIndexSDNode>(Addr.getOperand(0)))
+      if (auto *FIN = dyn_cast<FrameIndexSDNode>(Addr.getOperand(0)))
         Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), MVT::i64);
       else
         Base = Addr.getOperand(0);
@@ -141,11 +139,10 @@ bool BPFDAGToDAGISel::SelectFIAddr(SDValue Addr, SDValue &Base,
     return false;
 
   // Addresses of the form Addr+const or Addr|const
-  ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Addr.getOperand(1));
+  auto *CN = cast<ConstantSDNode>(Addr.getOperand(1));
   if (isInt<16>(CN->getSExtValue())) {
-
     // If the first operand is a FI, get the TargetFI Node
-    if (FrameIndexSDNode *FIN = dyn_cast<FrameIndexSDNode>(Addr.getOperand(0)))
+    if (auto *FIN = dyn_cast<FrameIndexSDNode>(Addr.getOperand(0)))
       Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), MVT::i64);
     else
       return false;