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

    <tr>
        <th>Summary</th>
        <td>
            [clang] `static constexpr` variable initialized inside `consteval` function is loosing its value
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

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

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

<pre>
    Any variable initialized as `static constexpr` variable inside `consteval` is not keeping its value in runtime:

```c++
consteval const int & get_value() {
    constexpr static int value = 42;
    return value;
}

int foo() {
  return get_value();
}
```

generates assembly (with clang 18.1):
```asm
foo():                                # @foo()
 push    rbp
        mov     rbp, rsp
        mov     eax, dword ptr [rip + get_value()::value]
        pop     rbp
 ret
get_value()::value:
        .long   0    
```

confirmed with clang 16+ to current `main` branch (`597ac471cc7da97ccf957362a7e9f7a52d6910ee` at compiler explorer)

link to example: https://compiler-explorer.com/z/fj6zco3d5

same thing happens to strings and arrays ... their storage is all zeros
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVN1uszgQfRrnZlRkbH7CBRftRnmN1WAm4K_GRrbJ1_bpV4bQpF-3q0UIJM_M8Tln7MEQ9GCJWla-sPJ0wCWOzrcjWq1esXfx0Ln-vX2273BFr7EzBNrqqNHoD-oBA7CKh4hRK1DOhkhvs2cVf0wPuqeUtsWvaFJcB7AuwivRrO0AOga4ollSPvjFRj0Rk8-MnxjfvxXfXsXES3rX1U_QbXvQNgITFQwU_14BmTgy0QCrbwUAcGcKN-qpatueyRMUgsmHbE9x8XaLfwZYfXoklwAuzn3f7Fb8B51_gdnVPaIOZMljpAAYAk2deQcmjr91HEEZtAPkxyxf4f70CMO0rXySYnIV818PExJYwe8lm4Z5CePqQzffTUnP5K6wB8Rf4MMPccK3FO9_O9_DHD2w8sXrGZh4-W7MM5PP20J5-go3uxm-8vAUd6N-RNmt2VEy4-wAAHxV_LP3ytmL9hP18Oh3lThHB2rxntJRq_iE2qYT3Xm0akwNYhUvmxpVUedK1T02tVKXpqxlJbCm5lJjKfqqyTlRKsQIyk2zNuSB3mbjPPlP97ev0fY1bUtvOM0miYIxxjkkdeLMxHkHeNoBMuUmJs4fTJwvv6oP5WRfPiIGnAjimO7eiPNMNiT8EL22QwC0PaD3-B4gyzKII-l0V5zHgdLVRWPgg7wLh76VfSMbPFCb13mVC15KcRjbYy55faGm6Ul2zeUoc8k7SR1X_VGWHR10K7goeJk3ueDHMs9QSkVF0XBBRxRFxwpOE2qTGXOdMueHgw5hobYRVcMPBjsyYZ9bvk1JT90yBFZwo0MM97Koo1kn3NpDVp7-x8y6j7gf5tdlsSpqZ5MbxrnwZYgdFm_arw0adByX7taVRO32e5q9-0UqMnFe5QUmzqvCfwIAAP__hrarJQ">