[PATCH] D12912: ScalarEvolution: added tmp to avoid use-after-dtor in for loop.

Naomi Musgrave via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 16 14:16:34 PDT 2015


nmusgrave created this revision.
nmusgrave added a reviewer: eugenis.
nmusgrave added a subscriber: llvm-commits.
Herald added a subscriber: sanjoy.

For loop destroyed current instance before invoking next.
Temporary variable added to prevent use-after-dtor when invoke
destructor on current instance.

http://reviews.llvm.org/D12912

Files:
  lib/Analysis/ScalarEvolution.cpp

Index: lib/Analysis/ScalarEvolution.cpp
===================================================================
--- lib/Analysis/ScalarEvolution.cpp
+++ lib/Analysis/ScalarEvolution.cpp
@@ -8394,8 +8394,11 @@
 ScalarEvolution::~ScalarEvolution() {
   // Iterate through all the SCEVUnknown instances and call their
   // destructors, so that they release their references to their values.
-  for (SCEVUnknown *U = FirstUnknown; U; U = U->Next)
-    U->~SCEVUnknown();
+  for (SCEVUnknown *U = FirstUnknown; U;) {
+    SCEVUnknown *tmp = U;
+    U = U->Next;
+    tmp->~SCEVUnknown();
+  }
   FirstUnknown = nullptr;
 
   ValueExprMap.clear();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12912.34924.patch
Type: text/x-patch
Size: 639 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150916/7cf0aa0c/attachment.bin>


More information about the llvm-commits mailing list