[llvm] b3f193a - [DivergenceAnalysis] Fix static analyzer warning about dereference of nullptr

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 8 05:57:58 PST 2022


Author: Simon Pilgrim
Date: 2022-01-08T13:57:33Z
New Revision: b3f193a980f2a96aaca92e73067e86197d226d30

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

LOG: [DivergenceAnalysis] Fix static analyzer warning about dereference of nullptr

We're testing that the RegionLoop pointer is null in the first part of the check, so we need to check that its non-null before dereferencing it in a later part of the check.

Added: 
    

Modified: 
    llvm/lib/Analysis/DivergenceAnalysis.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/DivergenceAnalysis.cpp b/llvm/lib/Analysis/DivergenceAnalysis.cpp
index 7426d0c07592c..3a92819b1fc6e 100644
--- a/llvm/lib/Analysis/DivergenceAnalysis.cpp
+++ b/llvm/lib/Analysis/DivergenceAnalysis.cpp
@@ -130,7 +130,8 @@ bool DivergenceAnalysisImpl::inRegion(const Instruction &I) const {
 }
 
 bool DivergenceAnalysisImpl::inRegion(const BasicBlock &BB) const {
-  return (!RegionLoop && BB.getParent() == &F) || RegionLoop->contains(&BB);
+  return (!RegionLoop && BB.getParent() == &F) ||
+         (RegionLoop && RegionLoop->contains(&BB));
 }
 
 void DivergenceAnalysisImpl::pushUsers(const Value &V) {


        


More information about the llvm-commits mailing list