<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 --- - CloneFunction ovewrites requested replacements - PATCH" href="https://urldefense.proofpoint.com/v2/url?u=https-3A__llvm.org_bugs_show-5Fbug.cgi-3Fid-3D24065&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=ilGVGKAa2T_3Uvmsz2YbYN5FdSCy0f8J0XGSsVuUOBA&s=64NAnwmqsMrrfXweyECAfzvzjO52cTqZaXLNFe6bwqM&e=">24065</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>CloneFunction ovewrites requested replacements - PATCH
          </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>Transformation Utilities
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>pedro.ferreira@imgtec.com
          </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>The utility "CloneFunction" provides a ValueMap to describe requested
replacements of the cloned function's Values. When the cloning process goes
through the functions, it unconditionally adds the cloned instruction as a
replacement to the original.
The attached patch checks that a Value has not yet specified to replace and
instruction before adding such entry to the map.

We are not sure if this was the originally intended behaviour though and
therefore don't know if this is indeed a bug:

$ svn diff lib/Transforms/Utils/CloneFunction.cpp

Index: lib/Transforms/Utils/CloneFunction.cpp
===================================================================
--- lib/Transforms/Utils/CloneFunction.cpp      (revision 241669)
+++ lib/Transforms/Utils/CloneFunction.cpp      (working copy)
@@ -51,7 +51,8 @@
     if (II->hasName())
       NewInst->setName(II->getName()+NameSuffix);
     NewBB->getInstList().push_back(NewInst);
-    VMap[II] = NewInst;                // Add instruction map to value.
+    if (VMap.find(II) == VMap.end())
+      VMap[II] = NewInst;              // Add instruction map to value.

     hasCalls |= (isa<CallInst>(II) && !isa<DbgInfoIntrinsic>(II));
     if (const AllocaInst *AI = dyn_cast<AllocaInst>(II)) {</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>