<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - clang generating memcpy with source/destination overlap"
   href="https://bugs.llvm.org/show_bug.cgi?id=31993">31993</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang generating memcpy with source/destination overlap
          </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>Linux
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>enhancement
          </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>mikael.holmen@ericsson.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=18001" name="attach_18001" title="reproducer">attachment 18001</a> <a href="attachment.cgi?id=18001&action=edit" title="reproducer">[details]</a></span>
reproducer

With
clang -S -emit-llvm tr13026.c -o tr13026.ll

we get this memcpy call in the output

  call void @llvm.memcpy.p0i8.p0i8.i64(i8* bitcast (%struct.anon* @s to i8*),
i8* bitcast (%struct.anon* @s to i8*), i64 4, i32 4, i1 false)

where the dest and source arguments are the same, and thus clearly overlap.

However, in the documentation:
<a href="http://llvm.org/docs/LangRef.html#llvm-memcpy-intrinsic">http://llvm.org/docs/LangRef.html#llvm-memcpy-intrinsic</a>

it says:
"The ‘llvm.memcpy.*‘ intrinsics copy a block of memory from the source location
to the destination location, which are not allowed to overlap."

And if running lint on the output:
opt -S -lint -o tr13026.opt.ll tr13026.ll

we get a warning about it:

Undefined behavior: memcpy source and destination overlap
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* bitcast (%struct.anon* @s to i8*),
i8* bitcast (%struct.anon* @s to i8*), i64 4, i32 4, i1 false)</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>