From c5c9ef16fd4a48f1131d319497fa16473f88d4da Mon Sep 17 00:00:00 2001 From: q66 Date: Sun, 14 Apr 2024 14:55:21 +0200 Subject: [PATCH 26/29] clang: implicitly include stdc-predef.h This behavior is required to match gcc and get default access to some macros to get rid of certain hacks (especially on musl, which does not explicitly include this - glibc includes it from features.h) Inspired by https://reviews.llvm.org/D137043 but this should not be tied to libc choice, as gcc unconditionally does the preinclude for both. --- clang/lib/Driver/ToolChains/Clang.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 417b85899..2e583c39c 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -1168,6 +1168,16 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA, } } + // Follow gcc in pre-including stdc-predef.h in non-freestanding mode + // Has to be done this early so that it comes before user-supplied -includes + if (!Args.hasArg(options::OPT_nostdinc) && + !Args.hasArg(options::OPT_nostdlibinc) && + !Args.hasArg(options::OPT_ffreestanding) && + getToolChain().getTriple().isOSLinux()) { + CmdArgs.push_back("-include"); + CmdArgs.push_back("stdc-predef.h"); + } + bool RenderedImplicitInclude = false; for (const Arg *A : Args.filtered(options::OPT_clang_i_Group)) { if (A->getOption().matches(options::OPT_include) && -- 2.49.0