[LLVMdev] Unreachable code in Mutex.cpp

David Blaikie dblaikie at gmail.com
Fri Jan 13 23:17:49 PST 2012


On Fri, Jan 13, 2012 at 10:24 PM, Chris Lattner <clattner at apple.com> wrote:
>
> On Jan 13, 2012, at 4:43 PM, David Blaikie wrote:
>
>> It looks like for a while now (5 years) some code that was meant to do
>> smart things in Mutex.cpp hasn't been doing such smart things:
>>
>> https://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Mutex.cpp?r1=29287&r2=29932&diff_format=h
>>
>> I don't know if this change was even deliberate since it came in with
>> another change & the description doesn't mention it. Should we do away
>> with this logic if it hasn't been needed all this time? Reinstate it
>> (with the old logic? or with a configure-based preprocessor variable
>> instead)?
>
> On some (linux?) implementations, various pthread APIs are defined as "weak extern" symbols in libc and strong definitions in libpthreads.  The idea of this check is thus to detect if pthreads is linked into the app and enable threads if so.

Sorry, right - I should've been more clear. I understand that that's
what the declaration/boolean used to do:


 static const bool pthread_enabled = static_cast<bool>(pthread_mutex_init);

But that's not what the code does now - the change you made 5 years
ago changed it to a constant:

 static const bool pthread_enabled = true;

(I found this because the return outside the 'if (pthread_unabled) {
... return }' was marked as unreachable by -Wunreachable-code). Since
it hasn't actually been doing anything for 5 years - should we just
remove the variable & all the conditions (unconditionally using
pthreads), or reinstate the smarts it used to have (testing the weak
symbol)?




More information about the llvm-dev mailing list