Issue 126200
Summary Miscompilation: Missing prefixes for emulatedTLS variables on macOS/ARM64 with -O0
Labels new issue
Assignees
Reporter sschaller
    Reproducer:
https://alive2.llvm.org/ce/z/6Xr9_c

```cpp
struct T {
    T() {} // required
    int a = 0;
};

thread_local T aa;

int main() {
    return 0;
}
```
Trying to compile this code on macOS / ARM64 with `clang -stdlib=libc++ -std=c++17 -femulated-tls main.cpp`
leads to a linker error for undefined symbols `___tls_guard` and `_aa` (4-5, 60-61 in the reproducer).

Inspecting the generated assembly code shows that both symbols are used as operands instead of the prefixed variables `___emutls_v.__tls_guard` and `___emutls_v.aa`.

Compiling with `-O1` correctly prefixes the operands and fixes the issue.

I'm not quite sure what is missing and would appreciate any pointers.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to