This patch is to address https://bugs.llvm.org/show_bug.cgi?id=47833
A relevant discussion can also be found in http://lists.llvm.org/pipermail/llvm-dev/2020-November/146766.html
pthread_self() from glibc is defined with "attribute
((const))". The const attribute tells the compiler that it does
not read nor write any global state and hence always return the same
result. Hence in the following code:
auto x1 = pthread_self();
...
auto x2 = pthread_self();
the second call to pthread_self() can be optimized out. This has been
correct until coroutines. With coroutines, we can have code like this:
auto x1 = pthread_self();
co_await ...
auto x2 = pthread_self();
Now because of the co_await, the function can suspend and resume in a
different thread, in which case the second call to pthread_self()
should return a different result than the first one. Unfortunately
LLVM will still optimize out the second call in the case of
coroutines.
To fix the issue, this patch drops the readnone attribute from the pthread_self function in Clang.