Search code examples
cclangpthreadsgithub-actionsclang-static-analyzer

clang-analyzer: scan-build ./configure fails looking for pthread support: "_REENTRANT must be defined"


I'm using pthreads and my scan-build action has failed:

https://github.com/SentryPeer/SentryPeer/runs/5034401493?check_suite_focus=true

I see this:

cat clang_output_*
conftest.c:59:26: error: "_REENTRANT must be defined"
#                        error "_REENTRANT must be defined"
                         ^

and

checking whether /usr/bin/../libexec/ccc-analyzer is Clang... rm: cannot remove 'conftest.plist': Is a directory
no
checking whether pthreads work with "-pthread" and "-lpthread"... no
checking whether pthreads work with -pthread... no
checking whether pthreads work with -pthreads... no
checking for the pthreads library -lpthreads... no
checking whether pthreads work without any flags... no
checking whether pthreads work with -Kthread... no
checking whether pthreads work with -pthread... no
checking whether pthreads work with -pthreads... no
checking whether pthreads work with -mthreads... no
checking for the pthreads library -lpthread... no
checking whether pthreads work with --thread-safe... no
checking whether pthreads work with -mt... no
checking for pthread-config... no
configure: error: POSIX threads support is required
scan-build: Analysis run complete.
scan-build: Removing directory '/tmp/scan-build-2022-02-02-202911-1481984-1' because it contains no reports.
scan-build: No bugs found.

Version: clang-analyzer-13.0.0-3.fc35.noarch

My autotools builds fine without scan-build on the same Ubuntu version, as per:

https://github.com/SentryPeer/SentryPeer/actions/runs/1783127976

Any tips here? Not sure if this is a bug nor where to ask. I've raised it here too - https://github.com/llvm/llvm-project/issues/53552

Thanks for reading, Gavin.


Solution

  • _REENTRANT is an obsolete feature-test macro recognized at one time by Glibc and some other C implementations. The supported use case for this macro is for the user to define it in their source code or on the compiler command line to request features or behavior that otherwise might not be provided.

    The configure script you are using seems to be trying to determine whether pthreads support has successfully been enabled by checking whether _REENTRANT has been defined. However, this has always been questionable because it depends on undocumented implementation details of the C library and compiler. It worked at one time, for some C implementations, but it does not work with the C implementation you are now using. I would account that a flaw in clang-static-analyzer.