[llvm] 4158746 - [X86] Don't dereference a dyn_cast<> - use a cast<> instead. NFCI.

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Mon May 17 07:58:53 PDT 2021


Author: Simon Pilgrim
Date: 2021-05-17T15:58:32+01:00
New Revision: 41587466aaf239d061ad084114ec749cecbb2966

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

LOG: [X86] Don't dereference a dyn_cast<> - use a cast<> instead. NFCI.

dyn_cast<> can return null if the cast fails, by using cast<> we assert that the cast is correct helping to avoid a potential null dereference.

Added: 
    

Modified: 
    llvm/lib/Target/X86/X86ISelLowering.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 4057e7817fcc..ec7a27b83c00 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -44378,8 +44378,7 @@ static SDValue combineAndLoadToBZHI(SDNode *Node, SelectionDAG &DAG,
           uint64_t ArrayElementCount = Init->getType()->getArrayNumElements();
           bool ConstantsMatch = true;
           for (uint64_t j = 0; j < ArrayElementCount; j++) {
-            ConstantInt *Elem =
-                dyn_cast<ConstantInt>(Init->getAggregateElement(j));
+            auto *Elem = cast<ConstantInt>(Init->getAggregateElement(j));
             if (Elem->getZExtValue() != (((uint64_t)1 << j) - 1)) {
               ConstantsMatch = false;
               break;


        


More information about the llvm-commits mailing list