[PATCH] D129833: Use @llvm.threadlocal.address intrinsic to access TLS

Chuanqi Xu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 12 00:59:34 PDT 2022


ChuanqiXu added a comment.

In D129833#3717291 <https://reviews.llvm.org/D129833#3717291>, @jyknight wrote:

> Note that this change caused LLVM to no longer be aware that a TLS variable cannot be NULL. Thus, code like:
>
>   __thread int x;
>   int main() {
>     int* y = &x;
>     return *y;
>   }
>
> built with `clang -O -fsanitize=null` emits a null-pointer check, when it wouldn't previously. I think llvm.threadlocal.address's return value probably ought to be given the nonnull attribute. We also might want to infer other properties of the returned pointer based on knowledge of the global value parameter, such as alignment.
>
> Furthermore, while the above problem should simply be a very minor optimization degradation, in fact it caused miscompiles, due to a pre-existing bug in the X86 backend. I've sent https://reviews.llvm.org/D131716 to fix //that// part of the problem.

Oh, got it. I'll try to make it. And I find we can't set an intrinsic as `NonNull` directly in Intrinsics.td and I filed an issue for it: https://github.com/llvm/llvm-project/issues/57113.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129833/new/

https://reviews.llvm.org/D129833



More information about the cfe-commits mailing list