[llvm] r240214 - IndVarSimplify: Avoid UB from binding a reference to a null pointer

Justin Bogner mail at justinbogner.com
Fri Jun 19 23:24:05 PDT 2015

Author: bogner
Date: Sat Jun 20 01:24:05 2015
New Revision: 240214

URL: http://llvm.org/viewvc/llvm-project?rev=240214&view=rev
IndVarSimplify: Avoid UB from binding a reference to a null pointer

Calling operator* on a WeakVH whose Value is null hits undefined
behaviour, since we bind the value to a reference. Instead, go through
`operator Value*` so that we work with the pointer itself.

Found by ubsan.


Modified: llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp?rev=240214&r1=240213&r2=240214&view=diff
--- llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp Sat Jun 20 01:24:05 2015
@@ -2013,10 +2013,11 @@ bool IndVarSimplify::runOnLoop(Loop *L,
   // Now that we're done iterating through lists, clean up any instructions
   // which are now dead.
-  while (!DeadInsts.empty())
-    if (Instruction *Inst =
-          dyn_cast_or_null<Instruction>(&*DeadInsts.pop_back_val()))
+  while (!DeadInsts.empty()) {
+    Value *V = static_cast<Value *>(DeadInsts.pop_back_val());
+    if (Instruction *Inst = dyn_cast_or_null<Instruction>(V))
       RecursivelyDeleteTriviallyDeadInstructions(Inst, TLI);
+  }
   // The Rewriter may not be used from this point on.

More information about the llvm-commits mailing list