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

    <tr>
        <th>Summary</th>
        <td>
            -fvisibility-inlines-hidden makes static local var hidden on macOS
        </td>
    </tr>

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

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

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

<pre>
    Given
```
$ cat dynamic.cc
int i = 1;
inline int func() {
    static int var = i;
    return var;
}
int f() { return func(); }
```
and
```
$ cat main.cc
#include <iostream>
int i = 2;
inline int func() {
 static int var = i;
    return var;
}
int f();
int main() {
 std::cout << f() << func() << '\n';
}
```
On Linux,
```
$ clang++ -fvisibility-inlines-hidden -shared -fPIC dynamic.cc -o dynamic.so
$ clang++ -fvisibility-inlines-hidden main.cc dynamic.so
$ LD_LIBRARY_PATH=. ./a.out 
22
```
apparently implements the `-fvisibility-inlines-hidden ` semantics guaranteed by GCC (&ldquo;it does not affect static variables local to the function&rdquo;, <https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/C_002b_002b-Dialect-Options.html#index-fvisibility-inlines-hidden>), and both `dynamic.so` and `a.out` share a single `func::var` instance.
But on macOS,
```
$ clang++ -fvisibility-inlines-hidden -shared -fPIC dynamic.cc -o dynamic.dylib
$ clang++ -fvisibility-inlines-hidden main.cc dynamic.dylib
$ ./a.out 
12
```
apparently leads to two different `func::var` instances.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8VU-P47YP_TTMhbBhy4knPvgwSX7Z3wIDzGLbS08DWmIStbKUWnJ28-0LKf8G6TRt0aJAEEMkRfI9Ptrkvd5a5hZmC5itJjSGnRtaHzoetj1ZO-mcOraf9IEtFCsonqEuzr_TUUxRUkB1tNRrmUt5smsbUCNUKyyhWlxsRlvG6NqMVoKYg2gQns5uREQfKGiZQg40pPv6ej8GDBzGwUbn1QxPq1vNzS3rJfZWC6oFXqPvgJBVDwH2pO0VHYhKW2lGxQjVUjsfBqYeqv_dgxd_Gfy_hfxdwVPTH1RSUD1D9SzdGGL_UC1vvJ2P71o8WUA8wWxp4-N35e8oe7X4ou34HcTyjyk1ZLcgFiAWmG0O2utOGx2O2Yknn-20Umwx8zsaWGG2-fJ5-U5lmLnrybu_n_c8zg9zvKzeXj4vvj5__enty_OP_4dqlWMOYk15IizFCfGxivZ7GtgGc0Td7w33bIPHsGOEunjUD9QFeu7JBi09bkcayAZmhd0RPy0j_XMQtVG_jg6qhQ6oHHu0LiBtNizDRT8HGjR1hj0aJ8lgcKl6nGfQzoKoh3MOEMs4210Iex_1INYg1lsp860dczdsQaxd6lE56U-urBS5yIvTAcR6-VYUokt_2UqTYRmy132s4_Nd6E1aE8XfHwCPOyOa2AtZhZ0Lu0jFu6nURfJAXST6E09REkjotd2axGySa9J0XI-6QG19ICs5P41lMQZ0cejy9Yf_SpXqaHT3z4V5l-Zeh-Wf6tAwKZ908M2h0psNR8dD1nw-UW2lmqqhCbdl_VRO60qU88murTdVN52JmoionLOkYjZlLjrVzafckJroVhRClKJsypkoynleUsV1PZuWtWpkQx1MC-5Jm9yYQx-FNtHej9zOmllTTgx1bHz6HAlh-RsmJwgRv05DG-9k3bj1MC2M9sHfsgQdDLePqf2F_WVRTusRX7Vn70Ufk3Ew7d1W6LAbu1y6HsQ6Fjw_sv3gfmYZQKxTm3FNEozfAgAA__-PfTQX">