Changing thread_local to __thread in libFuzzer
ClosedPublic

Authored by george.karpenkov on Thu, Apr 20, 2:53 PM.

Details

Summary

Old apple compilers do not support thread_local keyword.
__thread is supported, and appears to have the same effect.

Diff Detail

Repository
rL LLVM

Yes, I don't like the change -- I really want to have portable modern C++ w/o any old stuff.
Can you do some cmake magic to add -Dthread_local=__thread for old compilers (and only for them)?

george.karpenkov edited the summary of this revision. (Show Details)

Detect whether thread_local is supported in CMake, and alternate between thread_local and __thread.
Files built using the built script would always have thread_local.

I understand that you would prefer not to have __thread at all, but I'm not sure whether it is possible, since thread_local is a keyword, not a define, and CMake operates by generating files which are later included by a compiler.

A system modifying the source code and replacing thread_local by __thread could be implemented, but I think it would cause far more trouble.

That's even worse.
Why can't you add -Dthread_local=__thread to compiler flags if the compiler is old?

Indeed, you are right, my assumption was that keywords could not be changed by the preprocessor, yet surprisingly that works.

kcc accepted this revision.Thu, Apr 20, 8:38 PM

LGTM

This revision is now accepted and ready to land.Thu, Apr 20, 8:38 PM
This revision was automatically updated to reflect the committed changes.