From 2e66405d8d8ed818cb9310b6c33419bd8d803d96 Mon Sep 17 00:00:00 2001 From: Simon Pilgrim Date: Thu, 9 Jan 2020 14:18:58 +0000 Subject: [PATCH] Don't use dyn_cast_or_null if we know the pointer is nonnull. Fix clang static analyzer null dereference warning by using dyn_cast instead. --- llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp index e5f7968..80acab3 100644 --- a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp @@ -1128,8 +1128,7 @@ struct MemorySanitizerVisitor : public InstVisitor { OriginAlignment); } else { Value *ConvertedShadow = convertToShadowTyNoVec(Shadow, IRB); - Constant *ConstantShadow = dyn_cast_or_null(ConvertedShadow); - if (ConstantShadow) { + if (auto *ConstantShadow = dyn_cast(ConvertedShadow)) { if (ClCheckConstantShadow && !ConstantShadow->isZeroValue()) paintOrigin(IRB, updateOrigin(Origin, IRB), OriginPtr, StoreSize, OriginAlignment); @@ -1210,8 +1209,7 @@ struct MemorySanitizerVisitor : public InstVisitor { Value *ConvertedShadow = convertToShadowTyNoVec(Shadow, IRB); LLVM_DEBUG(dbgs() << " SHAD1 : " << *ConvertedShadow << "\n"); - Constant *ConstantShadow = dyn_cast_or_null(ConvertedShadow); - if (ConstantShadow) { + if (auto *ConstantShadow = dyn_cast(ConvertedShadow)) { if (ClCheckConstantShadow && !ConstantShadow->isZeroValue()) { insertWarningFn(IRB, Origin); } -- 2.7.4