[llvm] 1a94392 - [Utils] stripDebugifyMetadata - use cast<> instead of dyn_cast_or_null<> to avoid dereference of nullptr

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 25 03:32:47 PDT 2022


Author: Simon Pilgrim
Date: 2022-03-25T10:25:04Z
New Revision: 1a943923b8bc000ae03b22a05413918723d2d044

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

LOG: [Utils] stripDebugifyMetadata - use cast<> instead of dyn_cast_or_null<> to avoid dereference of nullptr

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

Added: 
    

Modified: 
    llvm/lib/Transforms/Utils/Debugify.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/Debugify.cpp b/llvm/lib/Transforms/Utils/Debugify.cpp
index d6b1b1bf4b9f1..7448e3e80b465 100644
--- a/llvm/lib/Transforms/Utils/Debugify.cpp
+++ b/llvm/lib/Transforms/Utils/Debugify.cpp
@@ -266,7 +266,7 @@ bool llvm::stripDebugifyMetadata(Module &M) {
   SmallVector<MDNode *, 4> Flags(NMD->operands());
   NMD->clearOperands();
   for (MDNode *Flag : Flags) {
-    MDString *Key = dyn_cast_or_null<MDString>(Flag->getOperand(1));
+    auto *Key = cast<MDString>(Flag->getOperand(1));
     if (Key->getString() == "Debug Info Version") {
       Changed = true;
       continue;


        


More information about the llvm-commits mailing list