[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [RFC v2 1/4] tls: add macros for coroutine-safe TLS variables
From: |
Peter Maydell |
Subject: |
Re: [RFC v2 1/4] tls: add macros for coroutine-safe TLS variables |
Date: |
Thu, 2 Dec 2021 14:50:46 +0000 |
On Thu, 2 Dec 2021 at 14:44, Peter Maydell <peter.maydell@linaro.org> wrote:
> My compiler-developer colleagues present the following case where
> 'noinline' is not sufficient for the compiler to definitely
> use different values of the address-of-the-TLS-var across an
> intervening function call:
>
> __thread int i;
>
> __attribute__((noinline)) long get_ptr_i()
> {
> return (long)&i;
> }
>
> void switcher();
>
> int g()
> {
> long a = get_ptr_i();
> switcher();
> return a == get_ptr_i();
> }
>
> Trunk clang optimizes the comparison of the two pointers down
> to "must be always true" even though they might not be if the
> switcher() function has resulted in a change-of-thread:
> https://godbolt.org/z/hd67zh6jW
>
> The 'optnone' attribute (clang-specific) seems to be able
> to suppress this
...no it doesn't -- although the get_ptr_i() function is
called both before and after, its return value is ignored
and g() always still returns 'true'.
-- PMM