[libcxx-commits] [libcxx] [llvm] [libc++] Refactor the configuration macros to being always defined (PR #112094)

Martin Storsjö via libcxx-commits libcxx-commits at lists.llvm.org
Wed Nov 6 04:24:34 PST 2024


mstorsjo wrote:

This caused a surprising issue in external code that is checking these libcxx config macros. Is this change slated to be backported to 19.x, or is this strictly for 20.x development going forward?



Since b4130bee6bfd34d8045f02fc9f951bcb5db9d85c (#109525) we have code in compiler-rt/libfuzzer, which tries to check the kind of thread API used for c++ threads, by doing 
```c++
#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) ||                                 \
    defined(_GLIBCXX_GCC_GTHR_POSIX_H)
```
Admittedly, this is known to not be a supported construct. (CC @Zentrik)


Now after this change, we suddenly end up picking this pthread codepath every time. The way forward of fixing this, is to extend the condition like this:
```c++
#if (defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && _LIBCPP_HAS_THREAD_API_PTHREAD) || \
    defined(_GLIBCXX_GCC_GTHR_POSIX_H)
```

However with the previous form, we'd have
```c++
#define _LIBCPP_HAS_THREAD_API_PTHREAD
```
where the macro expands to nothing (contrary to `-D _LIBCPP_HAS_THREAD_API_PTHREAD` which would be equal to `-D_LIBCPP_HAS_THREAD_API_PTHREAD=1`).

If we try doing that with the new form of the ifdef, we end up with this error:
```
test.cpp:4:79: error: expected value in expression
    4 | #if (defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && _LIBCPP_HAS_THREAD_API_PTHREAD) || \
      |                                                                               ^
1 error generated.
```

Do you see any way of adjusting the `#if` condition so that it works both with the old and new forms of the define? As the old define doesn't expand to anything, it's hard to do any sort of comparison with it.

If not, I'm afraid that we'd need to rip out the libc++ specific part of #109525, or entirely skip setting the thread names in libfuzzer on mingw targets.

https://github.com/llvm/llvm-project/pull/112094


More information about the libcxx-commits mailing list