On GNU/Linux, GCC will automatically include stdc-predefs.h, while clang does
not. That is OK for glibc system because glibc includes this file manually. But
with other libc (e.g. musl), which does not manually include this, clang will
fail but GCC can get it compiled.
In 2017, D34158 try to introduce a new flag called fsystem-include-if-exists
to fix this, but it was reverted. Nearly, D106577 points out that macro
__STDC_ISO_10646__ was indeed needed, which is defined in stdc-predefs.h.
After a discussion, the community reaches a consensus, to make this macro
available with a D34158-like method.
In this patch, we port the patch in D34158 into the current clang codebase. The
change is almost the same with D34158, but we change some tests to suit current
codes:
- c-index-test now does not accept a -ffreestanding flag, and it should not.
We choose to disable this pre-include action in Objective-C because it will
cause some c-index-test's tests on Objective-C to fail.
- Some unit tests about parsing and re-parsing will be affected by this change.
To keep such tests passed, we add -ffreestanding flags to them.
- The new tool, Clang-Scan-Deps, will analyze all header files to find
dependencies. After we add an implicit include, its result will have an extra
stdc-predefs.h. Currently, we choose to add -ffreestanding flags to all the
affected tests for it. But maybe making it ignore the default header will be a
better choice.
Signed-off-by: Tao Liang <Origami404@foxmail.com>
Co-authored-by: YingChi Long <me@inclyc.cn>
Link: https://reviews.llvm.org/D34158
Link: https://gcc.gnu.org/gcc-4.8/porting_to.html
Link: https://reviews.llvm.org/D106577