[llvm] 5bbcff6 - [MemCpyOptimizer] hasUndefContents - only look for underlying object if we've found an alloca

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 6 07:15:17 PST 2022


Author: Simon Pilgrim
Date: 2022-01-06T15:15:03Z
New Revision: 5bbcff61810bf0e688fb2f293fca19fbc2a479e2

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

LOG: [MemCpyOptimizer] hasUndefContents - only look for underlying object if we've found an alloca

Provides an early-out if we fail to find an AllocaInst, and avoids a static analyzer warning about null dereferencing.

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
index 1c1818da0f79..19e2efd4824b 100644
--- a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
+++ b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
@@ -1271,12 +1271,14 @@ static bool hasUndefContents(MemorySSA *MSSA, AliasAnalysis *AA, Value *V,
       // does) and we're querying a pointer based on that alloca, then we know
       // the memory is definitely undef, regardless of how exactly we alias.
       // The size also doesn't matter, as an out-of-bounds access would be UB.
-      auto *Alloca = dyn_cast<AllocaInst>(getUnderlyingObject(V));
-      if (getUnderlyingObject(II->getArgOperand(1)) == Alloca) {
-        const DataLayout &DL = Alloca->getModule()->getDataLayout();
-        if (Optional<TypeSize> AllocaSize = Alloca->getAllocationSizeInBits(DL))
-          if (*AllocaSize == LTSize->getValue() * 8)
-            return true;
+      if (auto *Alloca = dyn_cast<AllocaInst>(getUnderlyingObject(V))) {
+        if (getUnderlyingObject(II->getArgOperand(1)) == Alloca) {
+          const DataLayout &DL = Alloca->getModule()->getDataLayout();
+          if (Optional<TypeSize> AllocaSize =
+                  Alloca->getAllocationSizeInBits(DL))
+            if (*AllocaSize == LTSize->getValue() * 8)
+              return true;
+        }
       }
     }
   }


        


More information about the llvm-commits mailing list