[llvm] r372429 - [AddressSanitizer] Don't dereference dyn_cast<ConstantInt> results. NFCI.

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 20 13:52:21 PDT 2019


Author: rksimon
Date: Fri Sep 20 13:52:21 2019
New Revision: 372429

URL: http://llvm.org/viewvc/llvm-project?rev=372429&view=rev
Log:
[AddressSanitizer] Don't dereference dyn_cast<ConstantInt> results. NFCI.

The static analyzer is warning about potential null dereference, but we can use cast<ConstantInt> directly and if not assert will fire for us.

Modified:
    llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Modified: llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp?rev=372429&r1=372428&r2=372429&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp Fri Sep 20 13:52:21 2019
@@ -1048,7 +1048,7 @@ struct FunctionStackPoisoner : public In
     if (!II.isLifetimeStartOrEnd())
       return;
     // Found lifetime intrinsic, add ASan instrumentation if necessary.
-    ConstantInt *Size = dyn_cast<ConstantInt>(II.getArgOperand(0));
+    auto *Size = cast<ConstantInt>(II.getArgOperand(0));
     // If size argument is undefined, don't do anything.
     if (Size->isMinusOne()) return;
     // Check that size doesn't saturate uint64_t and can
@@ -1790,7 +1790,7 @@ void ModuleAddressSanitizer::createIniti
     // Must have a function or null ptr.
     if (Function *F = dyn_cast<Function>(CS->getOperand(1))) {
       if (F->getName() == kAsanModuleCtorName) continue;
-      ConstantInt *Priority = dyn_cast<ConstantInt>(CS->getOperand(0));
+      auto *Priority = cast<ConstantInt>(CS->getOperand(0));
       // Don't instrument CTORs that will run before asan.module_ctor.
       if (Priority->getLimitedValue() <= GetCtorAndDtorPriority(TargetTriple))
         continue;




More information about the llvm-commits mailing list