<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/57103>57103</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            SmallString/SmallVector don't allow self-assign() or append()
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          brettw
      </td>
    </tr>
</table>

<pre>
    The `assign(in_iter in_start, in_iter in_end)` function of `SmallVector` (and by extension, `SmallString`) can't allow assignment to themselves or substrings/subvectors of themselves.

This manifested in a surprising crash in this very innocuous looking code:
```
SmallString AssetsPath<1024>;
...read AssetsPath...
AssetsPath = llvm::sys::path::parent_path(AssetsPath);  // CRASH
```
The issue is that `parent_path` returns a `StringRef` of a substring of its input. The similar function `append(in_iter in_start, in_iter in_end)` has the same problem.

I notice that the other assign variant of assign: `assign(size_type NumElts, ValueParamT Elt)` explicitly handles self-assignment

Related is https://github.com/llvm/llvm-project/issues/25667 which I think is the same underlying problem.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJydVE1vnDAQ_TVwGQV5DfvBgcPmS82lipIo18jAsLgxNrLNbra_vmOTdonUQ1UJATMent_Me6Y27bl66RGSDRPOyYNO-E7qN-nRAj2dF9Yn_AYWOdRtwkv6ALpJN14aDaYLAM-DUOoVG29sWCUkoVuoz4AfHrWjwoD0u_DZW6kPFBEYNILWth4ob04wMxlQe_AGfI-DQ3VEB8aCm2oXv3QJv6fgGPdzgcKlMEvYbcL28_2llw4GoWWHzmNLLYAgGDta6QgHGitcH7I-FB7RninQppnM5EAZ8x6LTItJ_okYSM9XDBftwN459O5R-D7Jb1aMF0l-l-TXc2GWZRZFuyiizLx0SUGS34JSxyFsl-_d2c0vY8Sc3yyN5i0m-G6xI6mSXwMN_p4uuHnaP3_7K-EguHRuCnfqWvggyhKV1LPoJ6sdjSoIFpt7wi6s0KTFRYYQSu9oZOPkMwjQTg5SCXuxRzDXOEbf_Lu5ehG4EZoYEEZraoXDF10fQBsvG5w7CKWGbvbTPXAUVgpyUKA7Ozvff7G5kz_xzZ9HhO_TcKe8C1RehZrwUVgxvADlPrngx6hkI706Ey3dKrIiGa27uhh1SewJlYhGc9B7P0b9oiQH6fupzhozUBAlnh9X1N4P8jGFUZZgbb7ebLZw6mXTw0Owpn6f1fqcyKRbtOocFPg9nBSr1WbD6MuizNO2ytsyL0XqiTdWyzPH7xdHFVqzPHuLvmhG4WxSyR_1KE4nq6r_72u9XbE87StWll2xboqOia5kiO2urou6LHLGmg2v21SJGpWrkvV1wrnG0-xYek_Wt6msOOOc7VYrzvkq59muZjnDpl2XZVs2211SMByEVFngkRl7SG0VKdUT_TkKpqTz7rI4N4wYtyN8Mfne2KqmU-BPady5isx_AdjYsys">