<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/73415>73415</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-tidy] llvmlibc-restrict-system-libc-headers assumes that clang's internal include directory is before the system include directory in the include order
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang,
clang-tidy
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
vimproved
</td>
</tr>
</table>
<pre>
The test for llvmlibc-restrict-system-libc-headers fails on musl systems due to it assuming that Clang's internal headers will always be included over the system headers (which is not the case on musl).
```
FAIL: Clang Tools :: clang-tidy/checkers/llvmlibc/restrict-system-libc-headers.cpp (372 of 1101)
******************** TEST 'Clang Tools :: clang-tidy/checkers/llvmlibc/restrict-system-libc-headers.cpp' FAILED ********************
Script:
--
: 'RUN: at line 1'; /usr/bin/python3.12 /var/tmp/portage/sys-devel/llvm-17.0.5-r1/work/clang-tools-extra/test/../test/clang-tidy/check_clang_tidy.py /var/tmp/portage/sys-devel/llvm-17.0.5-r1/work/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/restrict-system-libc-headers.cpp llvmlibc-restrict-system-libc-headers /var/tmp/portage/sys-devel/llvm-17.0.5-r1/work/x/y/llvm-abi_x86_64.amd64/tools/clang/tools/extra/test/clang-tidy/checkers/llvmlibc/Output/restrict-system-libc-headers.cpp.tmp -- -- -isystem /var/tmp/portage/sys-devel/llvm-17.0.5-r1/work/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/Inputs/system -resource-dir /var/tmp/portage/sys-devel/llvm-17.0.5-r1/work/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/Inputs/resource
--
Exit Code: 1
Command Output (stdout):
--
Running ['clang-tidy', '/var/tmp/portage/sys-devel/llvm-17.0.5-r1/work/x/y/llvm-abi_x86_64.amd64/tools/clang/tools/extra/test/clang-tidy/checkers/llvmlibc/Output/restrict-system-libc-headers.cpp.tmp.cpp', '-fix', '--checks=-*,llvmlibc-restrict-system-libc-headers', '--config={}', '--', '-isystem', '/var/tmp/portage/sys-devel/llvm-17.0.5-r1/work/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/Inputs/system', '-resource-dir', '/var/tmp/portage/sys-devel/llvm-17.0.5-r1/work/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/Inputs/resource', '-std=c++11', '-nostdinc++']...
------------------------ clang-tidy output -----------------------
5 warnings generated.
/var/tmp/portage/sys-devel/llvm-17.0.5-r1/work/x/y/llvm-abi_x86_64.amd64/tools/clang/tools/extra/test/clang-tidy/checkers/llvmlibc/Output/restrict-system-libc-headers.cpp.tmp.cpp:5:1: warning: system include stdio.h not allowed [llvmlibc-restrict-system-libc-headers]
5 | #include <stdio.h>
| ^~~~~~~~~~~~~~~~~~
6 | //
/var/tmp/portage/sys-devel/llvm-17.0.5-r1/work/x/y/llvm-abi_x86_64.amd64/tools/clang/tools/extra/test/clang-tidy/checkers/llvmlibc/Output/restrict-system-libc-headers.cpp.tmp.cpp:5:1: note: FIX-IT applied suggested code changes
/var/tmp/portage/sys-devel/llvm-17.0.5-r1/work/x/y/llvm-abi_x86_64.amd64/tools/clang/tools/extra/test/clang-tidy/checkers/llvmlibc/Output/restrict-system-libc-headers.cpp.tmp.cpp:7:1: warning: system include stdlib.h not allowed [llvmlibc-restrict-system-libc-headers]
7 | #include <stdlib.h>
| ^~~~~~~~~~~~~~~~~~~
8 | //
/var/tmp/portage/sys-devel/llvm-17.0.5-r1/work/x/y/llvm-abi_x86_64.amd64/tools/clang/tools/extra/test/clang-tidy/checkers/llvmlibc/Output/restrict-system-libc-headers.cpp.tmp.cpp:7:1: note: FIX-IT applied suggested code changes
/var/tmp/portage/sys-devel/llvm-17.0.5-r1/work/x/y/llvm-abi_x86_64.amd64/tools/clang/tools/extra/test/clang-tidy/checkers/llvmlibc/Output/restrict-system-libc-headers.cpp.tmp.cpp:9:1: warning: system include string.h not allowed [llvmlibc-restrict-system-libc-headers]
9 | #include "string.h"
| ^~~~~~~~~~~~~~~~~~~
10 | //
/var/tmp/portage/sys-devel/llvm-17.0.5-r1/work/x/y/llvm-abi_x86_64.amd64/tools/clang/tools/extra/test/clang-tidy/checkers/llvmlibc/Output/restrict-system-libc-headers.cpp.tmp.cpp:9:1: note: FIX-IT applied suggested code changes
/var/tmp/portage/sys-devel/llvm-17.0.5-r1/work/x/y/llvm-abi_x86_64.amd64/tools/clang/tools/extra/test/clang-tidy/checkers/llvmlibc/Output/restrict-system-libc-headers.cpp.tmp.cpp:12:1: warning: system include stddef.h not allowed [llvmlibc-restrict-system-libc-headers]
12 | #include <stddef.h>
| ^~~~~~~~~~~~~~~~~~~
13 | // Compiler provided headers should not throw warnings.
/var/tmp/portage/sys-devel/llvm-17.0.5-r1/work/x/y/llvm-abi_x86_64.amd64/tools/clang/tools/extra/test/clang-tidy/checkers/llvmlibc/Output/restrict-system-libc-headers.cpp.tmp.cpp:12:1: note: FIX-IT applied suggested code changes
clang-tidy applied 4 of 4 suggested fixes.
Suppressed 1 warnings (1 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
------------------------------------------------------------------
diff -u /var/tmp/portage/sys-devel/llvm-17.0.5-r1/work/x/y/llvm-abi_x86_64.amd64/tools/clang/tools/extra/test/clang-tidy/checkers/llvmlibc/Output/restrict-system-libc-headers.cpp.tmp.orig /var/tmp/portage/sys-devel/llvm-17.0.5-r1/work/x/y/llvm-abi_x86_64.amd64/tools/clang/tools/extra/test/clang-tidy/checkers/llvmlibc/Output/restrict-system-libc-headers.cpp.tmp.cpp failed:
--- /var/tmp/portage/sys-devel/llvm-17.0.5-r1/work/x/y/llvm-abi_x86_64.amd64/tools/clang/tools/extra/test/clang-tidy/checkers/llvmlibc/Output/restrict-system-libc-headers.cpp.tmp.orig 2023-11-25 21:17:21.477217544 +0000
+++ /var/tmp/portage/sys-devel/llvm-17.0.5-r1/work/x/y/llvm-abi_x86_64.amd64/tools/clang/tools/extra/test/clang-tidy/checkers/llvmlibc/Output/restrict-system-libc-headers.cpp.tmp.cpp 2023-11-25 21:17:21.497217544 +0000
@@ -2,12 +2,8 @@
// RUN: -- -- -isystem %S/Inputs/system \
// RUN: -resource-dir %S/Inputs/resource
-#include <stdio.h>
//
-#include <stdlib.h>
//
-#include "string.h"
//
#include "stdatomic.h"
-#include <stddef.h>
// Compiler provided headers should not throw warnings.
------------------------------ Fixes -----------------------------
--- /var/tmp/portage/sys-devel/llvm-17.0.5-r1/work/x/y/llvm-abi_x86_64.amd64/tools/clang/tools/extra/test/clang-tidy/checkers/llvmlibc/Output/restrict-system-libc-headers.cpp.tmp.orig 2023-11-25 21:17:21.477217544 +0000
+++ /var/tmp/portage/sys-devel/llvm-17.0.5-r1/work/x/y/llvm-abi_x86_64.amd64/tools/clang/tools/extra/test/clang-tidy/checkers/llvmlibc/Output/restrict-system-libc-headers.cpp.tmp.cpp 2023-11-25 21:17:21.497217544 +0000
@@ -2,12 +2,8 @@
// RUN: -- -- -isystem %S/Inputs/system \
// RUN: -resource-dir %S/Inputs/resource
-#include <stdio.h>
//
-#include <stdlib.h>
//
-#include "string.h"
//
#include "stdatomic.h"
-#include <stddef.h>
// Compiler provided headers should not throw warnings.
------------------------------------------------------------------
FileCheck -input-file=/var/tmp/portage/sys-devel/llvm-17.0.5-r1/work/x/y/llvm-abi_x86_64.amd64/tools/clang/tools/extra/test/clang-tidy/checkers/llvmlibc/Output/restrict-system-libc-headers.cpp.tmp.cpp.msg /var/tmp/portage/sys-devel/llvm-17.0.5-r1/work/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/restrict-system-libc-headers.cpp -check-prefixes=CHECK-MESSAGES -implicit-check-not={{warning|error}}: failed:
command line:1:22: error: CHECK-MESSAGES-NOT: excluded string found in input
-implicit-check-not='{{warning|error}}:'
^
/var/tmp/portage/sys-devel/llvm-17.0.5-r1/work/x/y/llvm-abi_x86_64.amd64/tools/clang/tools/extra/test/clang-tidy/checkers/llvmlibc/Output/restrict-system-libc-headers.cpp.tmp.cpp.msg:17:186: note: found here
/var/tmp/portage/sys-devel/llvm-17.0.5-r1/work/x/y/llvm-abi_x86_64.amd64/tools/clang/tools/extra/test/clang-tidy/checkers/llvmlibc/Output/restrict-system-libc-headers.cpp.tmp.cpp:12:1: warning: system include stddef.h not allowed [llvmlibc-restrict-system-libc-headers]
^~~~~~~~
Input file: /var/tmp/portage/sys-devel/llvm-17.0.5-r1/work/x/y/llvm-abi_x86_64.amd64/tools/clang/tools/extra/test/clang-tidy/checkers/llvmlibc/Output/restrict-system-libc-headers.cpp.tmp.cpp.msg
Check file: /var/tmp/portage/sys-devel/llvm-17.0.5-r1/work/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/restrict-system-libc-headers.cpp
-dump-input=help explains the following input dump.
Input was:
<<<<<<
.
.
.
12: /var/tmp/portage/sys-devel/llvm-17.0.5-r1/work/x/y/llvm-abi_x86_64.amd64/tools/clang/tools/extra/test/clang-tidy/checkers/llvmlibc/Output/restrict-system-libc-headers.cpp.tmp.cpp:9:1: warning: system include string.h not allowed [llvmlibc-restrict-system-libc-headers]
13: 9 | #include "string.h"
14: | ^~~~~~~~~~~~~~~~~~~
15: 10 | //
16: /var/tmp/portage/sys-devel/llvm-17.0.5-r1/work/x/y/llvm-abi_x86_64.amd64/tools/clang/tools/extra/test/clang-tidy/checkers/llvmlibc/Output/restrict-system-libc-headers.cpp.tmp.cpp:9:1: note: FIX-IT applied suggested code changes
17: /var/tmp/portage/sys-devel/llvm-17.0.5-r1/work/x/y/llvm-abi_x86_64.amd64/tools/clang/tools/extra/test/clang-tidy/checkers/llvmlibc/Output/restrict-system-libc-headers.cpp.tmp.cpp:12:1: warning: system include stddef.h not allowed [llvmlibc-restrict-system-libc-headers]
not:imp1 !~~~~~~~ error: no match expected
18: 12 | #include <stddef.h>
19: | ^~~~~~~~~~~~~~~~~~~
20: 13 | // Compiler provided headers should not throw warnings.
21: /var/tmp/portage/sys-devel/llvm-17.0.5-r1/work/x/y/llvm-abi_x86_64.amd64/tools/clang/tools/extra/test/clang-tidy/checkers/llvmlibc/Output/restrict-system-libc-headers.cpp.tmp.cpp:12:1: note: FIX-IT applied suggested code changes
22: clang-tidy applied 4 of 4 suggested fixes.
23: Suppressed 1 warnings (1 in non-user code).
24: Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
>>>>>>
```
Full build log: https://0x0.st/Hw3E.log
Not sure what the best potential fix here is, but it seems to me that this is somewhat related to the discussion in https://github.com/llvm/llvm-project/issues/63510, since this check is intended for llvm-libc.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsW19zozgS_zTKSxcUCBPihzw4_nM7dXezVZts1b1NyagxuhWIkkQcv9xnv5KAhNjOjGeSmZ1yxkUlgJpWq_vXrVYLmDFiUyNek_SGpIsL1tpS6et7UTVa3SO_WCu-u74rESwaC4XSIOV9JcU6DzQaq0VuA7MzFqvA3yyRcdQGCiakAVVD1RoJHYUB3iJYBcICM6atRL0BWzILc8nqDaGZAVFb1DWTMDDaCimByS3bGVgjiDqXLUcO6h412BJ73o_0hF5tS5GXIAzUynqSnBkcZCF0GpJoQaJZ__cy6g9_uZp9-BdJZp1EcKeUNECSmbuVu1uBFXxH6CovMf8LtSF0NSiE0NXnVBLmTeOkSzIKqoA4jmJCp70Q9NsPuFve3gGh2fcRmdAMnFKWC3iNlN04b3MtGuuE85dB0A8_mbkB_PHnR3fGLEhRI8SEZiS5AUJXrdGErtaiJnTV7Gyp6iSMqWu5Z67FVo1rUdqyDRK6MjsTcLxH2Y81iLMwCtNAx4Sutkr_5dTR6capK8AHq5njg8YSugrDp_NDFX7ytz65W2Gz-25CvAXcTvPVV43ggdDVbmhna_Hp4ery0-UkZBW_nDiebmzDcEbXXz_a31vbtPaEYYe2aiAI_CH68PA3WulD3bTWdF05UZwxVKtzDLjQP4Vgg0DPvXL5ICzMFUfnlPE4Zs5VVbGaQ2cRF9SM5crZZnrg23-0de3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