llvm / llvm/llvm-project

[clang] `-ibuiltininc` does not re-add builtin include paths if `-nostdinc` is specified

Open
#165,790 1 comment 0 reactions 0 assignees View on GitHub
clang:driver
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

[Link to CLI reference](https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-ibuiltininc)

> -ibuiltininc
Enable builtin #include directories even when -nostdinc is used before or after -ibuiltininc. Using -nobuiltininc after the option disables it

Current behavior:

```
willtv@BLADEBLADEBLADE:~/foo$ clang-21 -ibuiltininc -nostdinc -v ./foo.c
// ...
clang-21: warning: argument unused during compilation: '-ibuiltininc' [-Wunused-command-line-argument]
"/usr/lib/llvm-21/bin/clang" -cc1 -triple x86_64-pc-linux-gnu -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name foo.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/home/willtv/foo -v -fcoverage-compilation-dir=/home/willtv/foo -nostdsysteminc -nobuiltininc -resource-dir /usr/lib/llvm-21/lib/clang/21 -fdeprecated-macro -ferror-limit 19 -fmessage-length=80 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/foo-290858.o -x c++ ./foo.c
clang -cc1 version 21.1.5 based upon LLVM 21.1.5 default target x86_64-pc-linux-gnu
#include "..." search starts here:
End of search list.
./foo.c:1:10: fatal error: 'stdatomic.h' file not found
1 | #include
| ^~~~~~~~~~~~~
1 error generated.
```

Example program:
```
#include
#include
#include

int main() {
printf("Hello world!\n");
return 0;
}
```

Contributor guide

Open the contributing guide

Research direction

Start with the linked Clang CLI reference and reproduce the shown `clang-21 -ibuiltininc -nostdinc -v ./foo.c` command using the example source. Trace how these options affect the `-cc1` invocation and builtin include search path; done means `-ibuiltininc` restores the builtin directories unless `-nobuiltininc` follows it, with regression coverage.

Written by the indexing model from the issue text.

Assessment

Domain
cli, compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.