<div dir="ltr">Hi Takumi,<div><br></div><div>Thanks for fixing this! Does this fix your windows regressions due to GlobalsAA, or are there still more to investigate?</div><div><br></div><div>Cheers,</div><div><br></div><div>James</div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, 14 Sep 2015 at 07:18 NAKAMURA Takumi via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: chapuni<br>
Date: Mon Sep 14 01:16:44 2015<br>
New Revision: 247534<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=247534&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=247534&view=rev</a><br>
Log:<br>
GlobalsAAResult: Try to fix crash.<br>
<br>
DeletionCallbackHandle holds GAR in its creation. It assumes;<br>
<br>
  - It is registered as CallbackVH. It should not be moved in its life.<br>
  - Its parent, GAR, may be moved.<br>
<br>
To move list<DeletionCallbackHandle> GlobalsAAResult::Handles,<br>
GAR must be updated with the destination in GlobalsAAResult(&&).<br>
<br>
Modified:<br>
    llvm/trunk/include/llvm/Analysis/GlobalsModRef.h<br>
    llvm/trunk/lib/Analysis/GlobalsModRef.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/Analysis/GlobalsModRef.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/GlobalsModRef.h?rev=247534&r1=247533&r2=247534&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/GlobalsModRef.h?rev=247534&r1=247533&r2=247534&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/Analysis/GlobalsModRef.h (original)<br>
+++ llvm/trunk/include/llvm/Analysis/GlobalsModRef.h Mon Sep 14 01:16:44 2015<br>
@@ -52,11 +52,11 @@ class GlobalsAAResult : public AAResultB<br>
<br>
   /// Handle to clear this analysis on deletion of values.<br>
   struct DeletionCallbackHandle final : CallbackVH {<br>
-    GlobalsAAResult &GAR;<br>
+    GlobalsAAResult *GAR;<br>
     std::list<DeletionCallbackHandle>::iterator I;<br>
<br>
     DeletionCallbackHandle(GlobalsAAResult &GAR, Value *V)<br>
-        : CallbackVH(V), GAR(GAR) {}<br>
+        : CallbackVH(V), GAR(&GAR) {}<br>
<br>
     void deleted() override;<br>
   };<br>
<br>
Modified: llvm/trunk/lib/Analysis/GlobalsModRef.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/GlobalsModRef.cpp?rev=247534&r1=247533&r2=247534&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/GlobalsModRef.cpp?rev=247534&r1=247533&r2=247534&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Analysis/GlobalsModRef.cpp (original)<br>
+++ llvm/trunk/lib/Analysis/GlobalsModRef.cpp Mon Sep 14 01:16:44 2015<br>
@@ -195,34 +195,34 @@ private:<br>
 void GlobalsAAResult::DeletionCallbackHandle::deleted() {<br>
   Value *V = getValPtr();<br>
   if (auto *F = dyn_cast<Function>(V))<br>
-    GAR.FunctionInfos.erase(F);<br>
+    GAR->FunctionInfos.erase(F);<br>
<br>
   if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) {<br>
-    if (GAR.NonAddressTakenGlobals.erase(GV)) {<br>
+    if (GAR->NonAddressTakenGlobals.erase(GV)) {<br>
       // This global might be an indirect global.  If so, remove it and<br>
       // remove any AllocRelatedValues for it.<br>
-      if (GAR.IndirectGlobals.erase(GV)) {<br>
+      if (GAR->IndirectGlobals.erase(GV)) {<br>
         // Remove any entries in AllocsForIndirectGlobals for this global.<br>
-        for (auto I = GAR.AllocsForIndirectGlobals.begin(),<br>
-                  E = GAR.AllocsForIndirectGlobals.end();<br>
+        for (auto I = GAR->AllocsForIndirectGlobals.begin(),<br>
+                  E = GAR->AllocsForIndirectGlobals.end();<br>
              I != E; ++I)<br>
           if (I->second == GV)<br>
-            GAR.AllocsForIndirectGlobals.erase(I);<br>
+            GAR->AllocsForIndirectGlobals.erase(I);<br>
       }<br>
<br>
       // Scan the function info we have collected and remove this global<br>
       // from all of them.<br>
-      for (auto &FIPair : GAR.FunctionInfos)<br>
+      for (auto &FIPair : GAR->FunctionInfos)<br>
         FIPair.second.eraseModRefInfoForGlobal(*GV);<br>
     }<br>
   }<br>
<br>
   // If this is an allocation related to an indirect global, remove it.<br>
-  GAR.AllocsForIndirectGlobals.erase(V);<br>
+  GAR->AllocsForIndirectGlobals.erase(V);<br>
<br>
   // And clear out the handle.<br>
   setValPtr(nullptr);<br>
-  GAR.Handles.erase(I);<br>
+  GAR->Handles.erase(I);<br>
   // This object is now destroyed!<br>
 }<br>
<br>
@@ -794,7 +794,13 @@ GlobalsAAResult::GlobalsAAResult(Globals<br>
       IndirectGlobals(std::move(Arg.IndirectGlobals)),<br>
       AllocsForIndirectGlobals(std::move(Arg.AllocsForIndirectGlobals)),<br>
       FunctionInfos(std::move(Arg.FunctionInfos)),<br>
-      Handles(std::move(Arg.Handles)) {}<br>
+      Handles(std::move(Arg.Handles)) {<br>
+  // Update the parent for each DeletionCallbackHandle.<br>
+  for (auto &H : Handles) {<br>
+    assert(H.GAR == &Arg);<br>
+    H.GAR = this;<br>
+  }<br>
+}<br>
<br>
 /*static*/ GlobalsAAResult<br>
 GlobalsAAResult::analyzeModule(Module &M, const TargetLibraryInfo &TLI,<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>