On Thu, 2 Dec 2021 at 14:44, Peter Maydell <peter.mayd...@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