[CodeGenPrepare] Report all changes made during instruction sinking
authorBenjamin Kramer <benny.kra@googlemail.com>
Fri, 10 Apr 2015 22:25:36 +0000 (22:25 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Fri, 10 Apr 2015 22:25:36 +0000 (22:25 +0000)
r234638 chained another transform below which was tripping over the
deleted instruction. Use after free found by asan in many regression
tests.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234654 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenPrepare.cpp

index d101f52b6eca5cf1618473b2b7ae39a853296fc7..937b92611203b4562137599f1ad777f729e1db89 100644 (file)
@@ -693,11 +693,11 @@ static bool SinkCast(CastInst *CI) {
       InsertedCast =
         CastInst::Create(CI->getOpcode(), CI->getOperand(0), CI->getType(), "",
                          InsertPt);
-      MadeChange = true;
     }
 
     // Replace a use of the cast with a use of the new cast.
     TheUse = InsertedCast;
+    MadeChange = true;
     ++NumCastUses;
   }
 
@@ -834,17 +834,19 @@ static bool SinkCmpExpression(CmpInst *CI) {
         CmpInst::Create(CI->getOpcode(),
                         CI->getPredicate(),  CI->getOperand(0),
                         CI->getOperand(1), "", InsertPt);
-      MadeChange = true;
     }
 
     // Replace a use of the cmp with a use of the new cmp.
     TheUse = InsertedCmp;
+    MadeChange = true;
     ++NumCmpUses;
   }
 
   // If we removed all uses, nuke the cmp.
-  if (CI->use_empty())
+  if (CI->use_empty()) {
     CI->eraseFromParent();
+    MadeChange = true;
+  }
 
   return MadeChange;
 }