Don't use dyn_cast_or_null if we know the pointer is nonnull.
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Thu, 9 Jan 2020 14:18:58 +0000 (14:18 +0000)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Fri, 10 Jan 2020 10:32:36 +0000 (10:32 +0000)
Fix clang static analyzer null dereference warning by using dyn_cast instead.

llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp

index e5f7968..80acab3 100644 (file)
@@ -1128,8 +1128,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
                   OriginAlignment);
     } else {
       Value *ConvertedShadow = convertToShadowTyNoVec(Shadow, IRB);
-      Constant *ConstantShadow = dyn_cast_or_null<Constant>(ConvertedShadow);
-      if (ConstantShadow) {
+      if (auto *ConstantShadow = dyn_cast<Constant>(ConvertedShadow)) {
         if (ClCheckConstantShadow && !ConstantShadow->isZeroValue())
           paintOrigin(IRB, updateOrigin(Origin, IRB), OriginPtr, StoreSize,
                       OriginAlignment);
@@ -1210,8 +1209,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
     Value *ConvertedShadow = convertToShadowTyNoVec(Shadow, IRB);
     LLVM_DEBUG(dbgs() << "  SHAD1 : " << *ConvertedShadow << "\n");
 
-    Constant *ConstantShadow = dyn_cast_or_null<Constant>(ConvertedShadow);
-    if (ConstantShadow) {
+    if (auto *ConstantShadow = dyn_cast<Constant>(ConvertedShadow)) {
       if (ClCheckConstantShadow && !ConstantShadow->isZeroValue()) {
         insertWarningFn(IRB, Origin);
       }