Issue 91262
Summary Clang omits variable with "used" attribute
Labels clang:codegen
Assignees
Reporter pogo59
    [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.)
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to