musllvm

A pure LLVM/Clang cross compiler toolchain targeting musl C
git clone git://git.daat.foo/musllvm.git
Log | Files | Refs | README | LICENSE

0026-clang-implicitly-include-stdc-predef.h.patch (1579B)


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