<html>
    <head>
      <base href="http://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 --- - GlobalOpt::CleanupPointerRootUsers could pass nullptr to dyn_cast"
   href="http://llvm.org/bugs/show_bug.cgi?id=21592">21592</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>GlobalOpt::CleanupPointerRootUsers could pass nullptr to dyn_cast
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>Linux
          </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>Interprocedural Optimizations
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>vedun@ispras.ru
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=13358" name="attach_13358" title="Proposed patch">attachment 13358</a> <a href="attachment.cgi?id=13358&action=edit" title="Proposed patch">[details]</a></span>
Proposed patch

<a href="https://github.com/llvm-mirror/llvm/blob/master/lib/Transforms/IPO/GlobalOpt.cpp#L222">https://github.com/llvm-mirror/llvm/blob/master/lib/Transforms/IPO/GlobalOpt.cpp#L222</a>
:

222: GlobalVariable *MemSrc = dyn_cast<GlobalVariable>(MTI->getSource());
223: if (MemSrc && MemSrc->isConstant()) {
224:     Changed = true;
225:     MTI->eraseFromParent();
226: } else if (Instruction *I = dyn_cast<Instruction>(MemSrc)) {
227:     if (I->hasOneUse())
228:     Dead.push_back(std::make_pair(I, MTI));
229: }

if MTI->getSource() is an Instruction, dyn_cast(222) returns nullptr, so  the
condition (223) would be false, and dyn_cast (226) would fail due to MemSrc
being null. 

Probably, the author meant that dyn_cast (226) should use the return of
MTI->getSource(). In this case, the attached patch fixes the issue.</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>