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

    <tr>
        <th>Summary</th>
        <td>
            clang ignores `tls_model` attribute
        </td>
    </tr>

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

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

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

<pre>
    According to the [documentation](https://releases.llvm.org/5.0.0/tools/clang/docs/AttributeReference.html#tls-model-gnu-tls-model) and some old tickets (e.g. #10160), clang has support for the `tls_model` attribute allows overriding the [access model](https://www.akkadia.org/drepper/tls.pdf) for a thread-local variable.

In practice I haven't been able to get this attribute to do anything. It seems to have no effect on generated code. Digging around in the code leads me to believe that this is a case of either:

1. The attribute not being propagated correctly.
2. Some subsequent optimisation step not respecting the override, and undoing it (e.g. from `global-dynamic` -> `local-exec`).

This attribute is supported and working in GCC, and comparing generated code with it in Compiler Explorer is a good way to highlight the problem.

Clang example (18.1.0): https://godbolt.org/z/fs6vK3zM1

We can see that both thread-locals are accessed exactly the same way. Using other access modes also has no effect.

GCC example (14.1): https://godbolt.org/z/EjTPfTWM7

We can clearly see that the access modes are respected, especially through the call to `__tls_get_addr`.

I also haven't gotten the global TLS mode override flag of clang to do anything.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVUFv2zgT_TX0ZWBBpm0lPviQOnVRfF-BxTaLHoMROZLYUBwtObKb_PoFJSeNiy6wF9siLc57894bYkquDUR7tf2gtvcLHKXjuBd8-e7Comb7vL8zhqN1oQVhkI5AbT9YNmNPQVAcB7W9V_q2ExmSWt8pfVT6GMkTJkqF96e-4NgqfdwWZVEqfRRmn5Q-Go8hr1s2-fFOJLp6FPqTGooUDBWd9F7ptfi07NmSX7ZhXL49Kb0DDBYS9wTsLYgzTyQJlL6loi1A6fWqXFWl0julDzDVgw4TpH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