[llvm] ada6bcc - [X86] X86tcret_1reg - use cast<> instead of dyn_cast<> to avoid dereference of nullptr

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 17 03:54:31 PST 2022


Author: Simon Pilgrim
Date: 2022-02-17T11:54:12Z
New Revision: ada6bcc13f0519320c9e5eb1006d5e71beea1cec

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

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

The pointer is always dereferenced, so assert the cast is correct instead of returning nullptr

Added: 
    

Modified: 
    llvm/lib/Target/X86/X86InstrCompiler.td

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/X86/X86InstrCompiler.td b/llvm/lib/Target/X86/X86InstrCompiler.td
index 36f56cfcf1154..fe8126f3dc7d8 100644
--- a/llvm/lib/Target/X86/X86InstrCompiler.td
+++ b/llvm/lib/Target/X86/X86InstrCompiler.td
@@ -1239,8 +1239,7 @@ def X86tcret_1reg : PatFrag<(ops node:$ptr, node:$off),
                              (X86tcret node:$ptr, node:$off), [{
   // X86tcret args: (*chain, ptr, imm, regs..., glue)
   unsigned NumRegs = 1;
-  LoadSDNode* ld = dyn_cast<LoadSDNode>(N->getOperand(1));
-  const SDValue& BasePtr = ld->getBasePtr();
+  const SDValue& BasePtr = cast<LoadSDNode>(N->getOperand(1))->getBasePtr();
   if (isa<FrameIndexSDNode>(BasePtr))
     NumRegs = 3;
   else if (BasePtr->getNumOperands() && isa<GlobalAddressSDNode>(BasePtr->getOperand(0)))


        


More information about the llvm-commits mailing list