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

    <tr>
        <th>Summary</th>
        <td>
            Question about optimization attributes
        </td>
    </tr>

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

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

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

<pre>
    Let's say I'm writing a function and inside I'm calling another function. How do I prove to the compiler that calling it won't change local variables and class fields around?
This is very relevant for calls to logging functions (they are not pure), and I also encountered this when implementing type erasure (for example, the compiler cannot understand that when calling the constructor's move constructor through a pointer to it, the private field of my class will definitely not change, etc. )

I want something like:
```C++
int log();

struct A {
 int x;
 int foo() const {
 [[clang::assume_not_changes_nothing_visible_here]] log();
    return x;
 }
};
int bar(A& v) {
 v.x = 15;
 return v.foo(); // want to optimize to 'return 15', but its loaded twice instead
}
```
https://godbolt.org/z/jcjnPvKav
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxsVE2PozgQ_TXmUpqIGAjhwKEzUbSt3cOutPeWMQW4x9jILpPO_PqVTTqdWY1kJbhc9d6r5w_hvRoNYsuqE6vOmQg0Wdf-QN1Zk3W2v7V_ITFee_DiBq-M1zNcnSJlRhAwBCNJWQPC9KCMVz3ec6TQOuUYSxO6R-YO_rBX6C28wuLsikAWaEKQdl6URgc0CXpUK4KrNYzXBHISZkTQVgoNq3BKdBp9IpZaeA-DQt17EM4G07PiwvIzy1_-nZQH5WFFdwOHGldhCAbrEoeP9NqOYyT7lOiB8SNNeAPhEIwlWIJDxhvGvye-VxDaW0AjbTCEDnugSHOd0ICaF40zmuQQ3RYEdMIHhxE18uKHiCkR7JfGpTCRK5genafIk6xIoJ9-bAXGkwuSrEv7MkcXn4JAk7NhnEDAYlXUF5tU9Em4OLUKws0vsAPMt7uDV6U19Dgoowj1LbW-2R5rkeQOogvJ1-33Fa7RTm9npCkK1OoHsuK-yg75Nr4zfoojRZWhaDnjxwhWnJ7xth7gBVh9j0NM_3ikpelg7Va9tf2UnE7xSWphxqiieBHehxnfjKW3rRMfv6PUt1V51Wl8m9Ahq86sOv9GFgCAQwrOPItg9fmuuj4_olFZJxzjxxfGD7BGfV_K1t0HsOIM--oL5g687h4NseIEjF8Yv2zGkgW7kJrVz3RRGK_vNfuK8TruShcIFHnQVvTxHF6VxHgTCUX_pfHX7dimE9Hio0uJb7R9ZzXtrBsZv_xk_PIu383f659izfq26JuiERm2-0OzL4t6Xx2yqeXNoTkem7ws8obXlSz7ChtZd0Up993QHTPV8pwX-TGv903R7A-7ohrKcjhWsuZVJbFjZY6zUHqn9TpH7kx5H7A9lFVeZ1p0qH16mjg3eIW0yDiPL5VrY823LoyelblWnvwXCinS2P4T0G-vU2cDfTopthCRU10g9Flwuv2fGYqm0O2knRm_RND737fF2XeUxPglSfGMX5LU_wIAAP__eRWxMA">