[PATCH] D137043: [clang] add implicit include for Linux/gnu compatibility

Tao Liang via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Oct 30 11:34:13 PDT 2022


Origami404 created this revision.
Herald added a project: All.
Origami404 added reviewers: aaron.ballman, erichkeane, mgorny, jyknight, mibintc, clang-language-wg.
Origami404 published this revision for review.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

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 <https://reviews.llvm.org/D34158> try to introduce a new flag called `fsystem-include-if-exists`
to fix this, but it was reverted. Nearly, D106577 <https://reviews.llvm.org/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 <https://reviews.llvm.org/D34158>-like method.

In this patch, we port the patch in D34158 <https://reviews.llvm.org/D34158> into the current clang codebase. The
change is almost the same with D34158 <https://reviews.llvm.org/D34158>, but we change some tests to suit current
codes:

1. 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.

2. 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.

3. 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 at foxmail.com>
Co-authored-by: YingChi Long <me at 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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137043

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Lex/PreprocessorOptions.h
  clang/lib/Driver/Job.cpp
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/lib/Driver/ToolChains/Linux.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/test/ClangScanDeps/Inputs/has_include_if_elif.json
  clang/test/ClangScanDeps/Inputs/header_stat_before_open_cdb.json
  clang/test/ClangScanDeps/Inputs/headerwithdirname.json
  clang/test/ClangScanDeps/Inputs/headerwithdirnamefollowedbyinclude.json
  clang/test/ClangScanDeps/Inputs/module_fmodule_name_cdb.json
  clang/test/ClangScanDeps/Inputs/modules-context-hash/cdb_a.json.template
  clang/test/ClangScanDeps/Inputs/modules-context-hash/cdb_b.json.template
  clang/test/ClangScanDeps/Inputs/modules-pch-common-submodule/cdb_pch.json
  clang/test/ClangScanDeps/Inputs/modules-pch-common-submodule/cdb_tu.json
  clang/test/ClangScanDeps/Inputs/modules-pch-common-via-submodule/cdb_pch.json
  clang/test/ClangScanDeps/Inputs/modules-pch-common-via-submodule/cdb_tu.json
  clang/test/ClangScanDeps/Inputs/modules-pch/cdb_pch.json
  clang/test/ClangScanDeps/Inputs/modules-pch/cdb_tu.json
  clang/test/ClangScanDeps/Inputs/modules-pch/cdb_tu_with_common.json
  clang/test/ClangScanDeps/Inputs/modules_cdb.json
  clang/test/ClangScanDeps/Inputs/modules_inferred_cdb.json
  clang/test/ClangScanDeps/Inputs/no-werror.json
  clang/test/ClangScanDeps/Inputs/preprocess_minimized_pragmas_cdb.json
  clang/test/ClangScanDeps/Inputs/regular_cdb.json
  clang/test/ClangScanDeps/Inputs/relative_directory.json
  clang/test/ClangScanDeps/Inputs/static-analyzer-cdb.json
  clang/test/ClangScanDeps/Inputs/subframework_header_dir_symlink_cdb.json
  clang/test/ClangScanDeps/Inputs/symlink_cdb.json
  clang/test/ClangScanDeps/Inputs/target-filename-cdb.json
  clang/test/ClangScanDeps/Inputs/vfsoverlay_cdb.json
  clang/test/ClangScanDeps/header-search-pruning-transitive.c
  clang/test/ClangScanDeps/modules-dep-args.c
  clang/test/ClangScanDeps/modules-header-sharing.m
  clang/test/ClangScanDeps/modules-implementation-module-map.c
  clang/test/ClangScanDeps/modules-implicit-dot-private.m
  clang/test/ClangScanDeps/modules-incomplete-umbrella.c
  clang/test/ClangScanDeps/modules-no-undeclared-includes.c
  clang/test/Driver/Inputs/stdc-predef/usr/include/stdc-predef.h
  clang/test/Driver/stdc-predef.c
  clang/test/Driver/stdc-predef.i
  clang/unittests/Tooling/TestVisitor.h
  clang/unittests/libclang/LibclangTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137043.471853.patch
Type: text/x-patch
Size: 34782 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221030/7fb2019e/attachment-0001.bin>


More information about the cfe-commits mailing list