[llvm-dev] Why does clang -E - of a header file may have different exit status?

Harald van Dijk via llvm-dev llvm-dev at lists.llvm.org
Fri Apr 30 02:21:00 PDT 2021


On 30/04/2021 04:04, Peng Yu via llvm-dev wrote:
> I see different exit status of clang. Does anybody know why? Should
> clang be consistent on this aspect no matter what the header file is?
> 
> $ clang -E - <<< '#include <bfd.h>' | head -n 1
> # 1 "<stdin>"
> $ declare -p PIPESTATUS
> declare -a PIPESTATUS=([0]="141" [1]="0")

$ kill -l 141
PIPE

This happens because clang failed to fully write the preprocessed output 
because the head command is no longer accepting more input. This is not 
specific to clang, it happens with many other utilities as well. Once 
the head command is no longer accepting more input, it's pointless for 
clang to continue writing output, so it's sent a signal to stop.

Depending on the contents of the header file, the signal to stop may be 
sent before or after clang has already fully written its output. If it 
has fully written the output already, then clang will not notice any 
error and exit successfully. This matches GCC, except that you need 
different header files to show this with GCC. Try a tiny header file 
such as <stdbool.h> instead.

Cheers,
Harald van Dijk


More information about the llvm-dev mailing list