[llvm] c096799 - [CodeGen] Prevent nullptr deref in genAlternativeCodeSequence

Felipe de Azevedo Piovezan via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 8 10:41:52 PST 2023


Author: Felipe de Azevedo Piovezan
Date: 2023-03-08T13:41:32-05:00
New Revision: c0967995d254fd2dd24ba74afa46df5f559f11ba

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

LOG: [CodeGen] Prevent nullptr deref in genAlternativeCodeSequence

A pointer dereference was added (D141302) above an assert that checks
whether the pointer is null. This commit moves the assert above the
dereference and transforms it into an llvm_unreachable to better express
the intent that certain switch cases should never be reached.

Differential Revision: https://reviews.llvm.org/D145599

Added: 
    

Modified: 
    llvm/lib/CodeGen/TargetInstrInfo.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/TargetInstrInfo.cpp b/llvm/lib/CodeGen/TargetInstrInfo.cpp
index e86724ad7c0f..1ea5c07c1e29 100644
--- a/llvm/lib/CodeGen/TargetInstrInfo.cpp
+++ b/llvm/lib/CodeGen/TargetInstrInfo.cpp
@@ -1038,15 +1038,13 @@ void TargetInstrInfo::genAlternativeCodeSequence(
     Prev = MRI.getUniqueVRegDef(Root.getOperand(2).getReg());
     break;
   default:
-    break;
+    llvm_unreachable("Unknown pattern for machine combiner");
   }
 
   // Don't reassociate if Prev and Root are in 
diff erent blocks.
   if (Prev->getParent() != Root.getParent())
     return;
 
-  assert(Prev && "Unknown pattern for machine combiner");
-
   reassociateOps(Root, *Prev, Pattern, InsInstrs, DelInstrs, InstIdxForVirtReg);
 }
 


        


More information about the llvm-commits mailing list