[PATCH] D32782: Add pthread_self function prototype and make it speculatable.

Davide Italiano via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat May 20 17:19:58 PDT 2017


davide added a comment.

OK, I think I found out the cause. I guess this patch was wrong, my bad.
GCC doesn't do anything special with `pthread_self` per-se.
What GCC does is speculating the `glibc` implementation of `pthread_self` is declared with `__attribute__(const)`.
The semantic of the attribute is that of "The const attribute is specified as asserting that the function does not examine any data except the arguments. " [1]
If the function has no arguments, it has to return the same value every time.

Therefore, it speculates.
I think that other libc implementation are free to not declare pthread_self with that attribute. In fact, from what I can see, the FreeBSD version doesn't use that argument.
In other words, I don't think we're allowed to do anything with `pthread_self()` in general as POSIX specifies weaks guarantees.

[1] https://sourceware.org/ml/libc-alpha/2016-04/msg00303.html


Repository:
  rL LLVM

https://reviews.llvm.org/D32782





More information about the llvm-commits mailing list