[llvm] r266565 - ValueMapper: Don't allow explicit null mappings of Values, NFC

Duncan P. N. Exon Smith via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 17 11:53:28 PDT 2016


Author: dexonsmith
Date: Sun Apr 17 13:53:24 2016
New Revision: 266565

URL: http://llvm.org/viewvc/llvm-project?rev=266565&view=rev
Log:
ValueMapper: Don't allow explicit null mappings of Values, NFC

As a follow-up to r123058, assert that there are no null mappings in the
ValueMap instead of just ignoring them when they are there.  There were
a couple of accidental insertions in CloneFunction so I cleaned those up
(caught by testcases).

Modified:
    llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp
    llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp

Modified: llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp?rev=266565&r1=266564&r2=266565&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp Sun Apr 17 13:53:24 2016
@@ -346,7 +346,7 @@ void PruningFunctionCloner::CloneBlock(c
       ConstantInt *Cond = dyn_cast<ConstantInt>(BI->getCondition());
       // Or is a known constant in the caller...
       if (!Cond) {
-        Value *V = VMap[BI->getCondition()];
+        Value *V = VMap.lookup(BI->getCondition());
         Cond = dyn_cast_or_null<ConstantInt>(V);
       }
 
@@ -449,7 +449,7 @@ void llvm::CloneAndPruneIntoFromInst(Fun
   // Defer PHI resolution until rest of function is resolved.
   SmallVector<const PHINode*, 16> PHIToResolve;
   for (const BasicBlock &BI : *OldFunc) {
-    Value *V = VMap[&BI];
+    Value *V = VMap.lookup(&BI);
     BasicBlock *NewBB = cast_or_null<BasicBlock>(V);
     if (!NewBB) continue;  // Dead block.
 

Modified: llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp?rev=266565&r1=266564&r2=266565&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp Sun Apr 17 13:53:24 2016
@@ -341,8 +341,10 @@ Value *Mapper::mapValue(const Value *V)
   ValueToValueMapTy::iterator I = getVM().find(V);
 
   // If the value already exists in the map, use it.
-  if (I != getVM().end() && I->second)
+  if (I != getVM().end()) {
+    assert(I->second && "Unexpected null mapping");
     return I->second;
+  }
 
   // If we have a materializer and it can materialize a value, use that.
   if (auto *Materializer = getMaterializer()) {




More information about the llvm-commits mailing list