Compilation error in swi-pl 8.4.3

clang 13.0.0 on FreeBSD 12.4Stable produces this error while building swi-pl 8.4.3:

/usr/ports/local/swi-pl/work/swipl-8.4.3/src/pl-thread.c:1821:31: error: too few arguments to function call, expected 2, have 1
if ( pthread_setname_np(name) == 0 )
~~~~~~~~~~~~~~~~~~ ^
/usr/include/pthread.h:306:6: note: ‘pthread_setname_np’ declared here
int pthread_setname_np(pthread_t, const char *);
^
1 error generated.
ninja: build stopped: subcommand failed.
*** Error code 1

Stop.
make: stopped in /usr/ports/local/swi-pl

Fortunately gcc12 overlooks this anomoly, so I’m able to continue. :slight_smile: Though this is something that needs attention.

Thanks for reporting. In theory this is covered. If you look at pl-thread.c you’ll see there are three variants for pthread_setname_np(). The CMake code in cmake/Config.cmake first checks the function exists and then tries to compile fragments using the -Werror flag to find out which of the three versions applies.

Apparently something goes wrong. Could you figure out what? E.g., check the settings using grep HAVE_PTHREAD_SETNAME CMakeCache.txt and if these are incorrect try to figure out what happens in cmake/Config.h?

edit probably these tests should be rewritten using CheckPrototypeDefinition

Sincere apologies for the noise, entirely my fault. I had inadvertently included -fno-math-errno in the CFLAGS, a left over from earlier work. (Using multiple dev machines and a holiday are not conducive to sound engineering :wink: )
It is interesting that gcc12 did not fail with this flag but clang13 did.
FYI, as requested:

With clang 13.0.0 and -fno-math-errno

# find ../ -name CMakeCache.txt|xargs grep HAVE_PTHREAD_SETNAME
HAVE_PTHREAD_SETNAME_NP:INTERNAL=1
//Test HAVE_PTHREAD_SETNAME_NP_WITH_TID
HAVE_PTHREAD_SETNAME_NP_WITH_TID:INTERNAL=
//Test HAVE_PTHREAD_SETNAME_NP_WITH_TID_AND_ARG
HAVE_PTHREAD_SETNAME_NP_WITH_TID_AND_ARG:INTERNAL=

with gcc12 and -fno-math-errno

HAVE_PTHREAD_SETNAME_NP:INTERNAL=1
//Test HAVE_PTHREAD_SETNAME_NP_WITH_TID
HAVE_PTHREAD_SETNAME_NP_WITH_TID:INTERNAL=1
//Test HAVE_PTHREAD_SETNAME_NP_WITH_TID_AND_ARG
HAVE_PTHREAD_SETNAME_NP_WITH_TID_AND_ARG:INTERNAL=

Thank-you for your prompt attention.
Kind regards, Dewayne

Thanks for the feedback. I wonder whether using CheckPrototypeDefinition would have had this right anyway. Seems a bit involved in getting all the includes and defines right though :frowning: Bit of a pity they managed to get three difference signatures for this nice but not vital feature. Setting the thread name makes debugging under GDB a bit nicer.

If someone likes making a PR using CheckPrototypeDefinition() …