<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - GlobalsAAResult possible dangling reference"
   href="https://llvm.org/bugs/show_bug.cgi?id=25217">25217</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>GlobalsAAResult possible dangling reference
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>yaron.keren@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>chandlerc@gmail.com, llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>lib/Analysis/GlobalsModRef.cpp:491 sets FunctionInfo &FI as reference into the
DenseMap FunctionInfos. 

    FunctionInfo &FI = FunctionInfos[SCC[0]->getFunction()];

lib/Analysis/GlobalsModRef.cpp:590 copies FI into all FunctionInfo[SCC
members].

    for (unsigned i = 1, e = SCC.size(); i != e; ++i)
      FunctionInfos[SCC[i]->getFunction()] = FI;

DenseMap iterators are not stable and the loop could potentially invalidate the
reference FI, continuing using the invalidated reference.

Practically, that may be a rare case since 1) FunctionInfos may already have
all the required entries 2) DenseMap iterators are usually stable even when
inserting entry 3) The invalidate reference may still contain the right data.

The issue could be fixed by keeping a local copy of FI

    FunctionInfo StackFI = FI;
    for (unsigned i = 1, e = SCC.size(); i != e; ++i)
      FunctionInfos[SCC[i]->getFunction()] = StackFI;

or not using the unstable reference FI while inserting entries

    for (unsigned i = 1, e = SCC.size(); i != e; ++i)
      FunctionInfos[SCC[i]->getFunction()] =
FunctionInfos[SCC[0]->getFunction()];</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>