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

    <tr>
        <th>Summary</th>
        <td>
            Clang omits variable with "used" attribute
        </td>
    </tr>

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

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

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

<pre>
    [GCC](https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html) specifies the "used" attribute as:
> This attribute, attached to a variable with static storage, means that the variable must be emitted even if it appears that the variable is not referenced.

Inside a constant "if" condition, clang will fail to emit a "used" variable in the not-taken branch. This differs from GCC behavior.
```
void foo() {
 if (sizeof(double) == sizeof(long double)) {
    __attribute__((used)) static int my_item(__LINE__);
  } else {
    __attribute__((used)) static int my_item(__LINE__);
  }
}
```
Clang allocates only one variable, GCC allocates both. Given it's a GCC-defined attribute, we should behave the way GCC does. This appears to be a Clang codegen bug, as `-emit-llvm -disable-llvm-passes` shows only one item.

(Why would I need this? It's part of the instrumentation for my Rotten Green Tests project. My static variables are actually allocated into a custom section, but that's not needed to trigger the bug.)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VMGO4kgM_ZriYhGFCqHJgUMPDK2WdvewGu0eUaXiJLVbKaOy04j9-lUVND09mutICAg29vN7fjbMbgiIO1V_UfVhYWYZKe7ONFDdLFrqrinyst-r-qD0dhQ5s6qelT4qfRysLYYwFxQHpY8UvAvYkeVbSOnjnqaJwvIvE51pPS6fRaJrZ0EuRpm80g3wGa3rHTLIiKC0nhk7pTWY91wwuWN5UOWzqr7Ct9HxR1TpfXowdsQOhMDA270bXJyMwGLEWWChaIacPaEJqZuR3PKRPs0s0CLg5ESwA3zDAK4HJ2DOZzTxZ39yDIEEIvYYMVjsijvQ_P4a2HUIBiwFFhMkDej6NJ6l0Dlx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