<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, May 24, 2013 at 10:16 AM, Sebastian Pop <span dir="ltr"><<a href="mailto:spop@codeaurora.org" target="_blank">spop@codeaurora.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: spop<br>
Date: Fri May 24 12:16:02 2013<br>
New Revision: 182655<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=182655&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=182655&view=rev</a><br>
Log:<br>
fix insertion of values in BBMap<br>
<br>
In GDB when "step" through generateScalarLoad and "finish" the call, the<br>
returned value is non NULL, however when printing the value contained in<br>
BBMap[Load] after this stmt:<br>
<br>
  BBMap[Load] = generateScalarLoad(...);<br>
<br>
the value in BBMap[Load] is NULL, and the BBMap.count(Load) is 1.<br>
<br>
The only intuitive idea that I have to explain this behavior is that we are<br>
playing with the undefined behavior of eval order of the params for the function<br>
standing for "BBMap[Load] = generateScalarLoad()". "BBMap[Load] = " may be<br>
executed before generateScalarLoad is called.<br>
<br>
Here are some other possible explanations from Will Dietz <<a href="mailto:w@wdtz.org">w@wdtz.org</a>>:<br>
<br>
The error is likely due to BBMap[Load] being evaluated first (creating<br>
a {Load -> uninitialized } entry in the DenseMap), then<br>
generateScalarLoad eventually accesses the same element and finds it<br>
to be NULL (DenseMap[Old])..  Offhand I'm not sure if this is<br>
guaranteed to be NULL or if it's uninitialized and happens to be NULL.<br></blockquote><div><br></div><div style>These seem like the same explanation, but yes - order of evaluation of the LHS and RHS are unspecified.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
The same issue can also go wrong in an even worse way: the second<br>
DenseMap access can trigger a rehash and *invalidate* the an earlier<br>
evaluated expression (for example LHS of the assignment), leading to a<br>
crash when performing the assignment store.<br>
<br>
Modified:<br>
    polly/trunk/lib/CodeGen/BlockGenerators.cpp<br>
<br>
Modified: polly/trunk/lib/CodeGen/BlockGenerators.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/BlockGenerators.cpp?rev=182655&r1=182654&r2=182655&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/BlockGenerators.cpp?rev=182655&r1=182654&r2=182655&view=diff</a><br>

==============================================================================<br>
--- polly/trunk/lib/CodeGen/BlockGenerators.cpp (original)<br>
+++ polly/trunk/lib/CodeGen/BlockGenerators.cpp Fri May 24 12:16:02 2013<br>
@@ -185,6 +185,7 @@ Value *BlockGenerator::getNewValue(const<br>
   }<br>
<br>
   if (BBMap.count(Old)) {<br>
+    assert(BBMap[Old] && "BBMap[Old] should not be NULL!");<br>
     return BBMap[Old];<br>
   }<br>
<br>
@@ -354,12 +355,14 @@ void BlockGenerator::copyInstruction(con<br>
     return;<br>
<br>
   if (const LoadInst *Load = dyn_cast<LoadInst>(Inst)) {<br>
-    BBMap[Load] = generateScalarLoad(Load, BBMap, GlobalMap, LTS);<br>
+    Value *NewLoad = generateScalarLoad(Load, BBMap, GlobalMap, LTS);<br>
+    BBMap[Load] = NewLoad;<br>
     return;<br>
   }<br>
<br>
   if (const StoreInst *Store = dyn_cast<StoreInst>(Inst)) {<br>
-    BBMap[Store] = generateScalarStore(Store, BBMap, GlobalMap, LTS);<br>
+    Value *NewStore = generateScalarStore(Store, BBMap, GlobalMap, LTS);<br>
+    BBMap[Store] = NewStore;<br></blockquote><div><br></div><div style>Perhaps you could add a comment to these two blocks to explain why there's an extra variable here? Or you could use insert:<br><br>BBMap.insert(std::make_pair(Store, generateScalarStore(...)));<br>
</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
     return;<br>
   }<br>
<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>