brad created this revision. brad added reviewers: MaskRay, mgorny, krytarowski. brad added a project: clang. Herald added subscribers: StephenFan, ormris, arichardson, emaste. Herald added a project: All. brad requested review of this revision.
This matches OpenBSD and FreeBSD. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D140817 Files: clang/lib/Driver/ToolChains/NetBSD.cpp clang/lib/Driver/ToolChains/NetBSD.h clang/lib/Lex/InitHeaderSearch.cpp clang/test/Driver/netbsd.c clang/test/Driver/netbsd.cpp
Index: clang/test/Driver/netbsd.cpp =================================================================== --- clang/test/Driver/netbsd.cpp +++ clang/test/Driver/netbsd.cpp @@ -339,3 +339,11 @@ // S-POWERPC64: "{{.*}}/usr/lib{{/|\\\\}}crti.o" // S-POWERPC64: "{{.*}}/usr/lib{{/|\\\\}}crtbegin.o" "{{.*}}.o" "-lc++" // S-POWERPC64: "-lm" "-lc" "{{.*}}/usr/lib{{/|\\\\}}crtend.o" "{{.*}}/usr/lib{{/|\\\\}}crtn.o" + +// Check that the driver passes include paths to cc1 on NetBSD. +// RUN: %clang -### %s --target=x86_64-unknown-netbsd -r 2>&1 \ +// RUN: | FileCheck %s --check-prefix=DRIVER-PASS-INCLUDES +// DRIVER-PASS-INCLUDES: "-cc1" {{.*}}"-resource-dir" "[[RESOURCE:[^"]+]]" +// DRIVER-PASS-INCLUDES-SAME: {{^}} "-internal-isystem" "/usr/include/c++/v1" +// DRIVER-PASS-INCLUDES-SAME: {{^}} "-internal-isystem" "[[RESOURCE]]{{/|\\\\}}include" +// DRIVER-PASS-INCLUDES-SAME: {{^}} "-internal-externc-isystem" "/usr/include" Index: clang/test/Driver/netbsd.c =================================================================== --- clang/test/Driver/netbsd.c +++ clang/test/Driver/netbsd.c @@ -477,3 +477,10 @@ // RELOCATABLE-NOT: "-dynamic-linker" // RELOCATABLE-NOT: "-l // RELOCATABLE-NOT: crt{{[^./\\]+}}.o + +// Check that the driver passes include paths to cc1 on NetBSD. +// RUN: %clang -### %s --target=x86_64-unknown-netbsd -r 2>&1 \ +// RUN: | FileCheck %s --check-prefix=DRIVER-PASS-INCLUDES +// DRIVER-PASS-INCLUDES: "-cc1" {{.*}}"-resource-dir" "[[RESOURCE:[^"]+]]" +// DRIVER-PASS-INCLUDES-SAME: {{^}} "-internal-isystem" "[[RESOURCE]]{{/|\\\\}}include" +// DRIVER-PASS-INCLUDES-SAME: {{^}} "-internal-externc-isystem" "/usr/include" Index: clang/lib/Lex/InitHeaderSearch.cpp =================================================================== --- clang/lib/Lex/InitHeaderSearch.cpp +++ clang/lib/Lex/InitHeaderSearch.cpp @@ -231,7 +231,6 @@ if (HSOpts.UseStandardSystemIncludes) { switch (os) { case llvm::Triple::CloudABI: - case llvm::Triple::NetBSD: case llvm::Triple::NaCl: case llvm::Triple::PS4: case llvm::Triple::PS5: @@ -412,9 +411,10 @@ case llvm::Triple::AIX: case llvm::Triple::Emscripten: case llvm::Triple::FreeBSD: + case llvm::Triple::NetBSD: + case llvm::Triple::OpenBSD: case llvm::Triple::Hurd: case llvm::Triple::Linux: - case llvm::Triple::OpenBSD: case llvm::Triple::Solaris: case llvm::Triple::WASI: return false; Index: clang/lib/Driver/ToolChains/NetBSD.h =================================================================== --- clang/lib/Driver/ToolChains/NetBSD.h +++ clang/lib/Driver/ToolChains/NetBSD.h @@ -58,6 +58,9 @@ CXXStdlibType GetDefaultCXXStdlibType() const override; + void + AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args) const override; void addLibCxxIncludePaths( const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; Index: clang/lib/Driver/ToolChains/NetBSD.cpp =================================================================== --- clang/lib/Driver/ToolChains/NetBSD.cpp +++ clang/lib/Driver/ToolChains/NetBSD.cpp @@ -11,6 +11,7 @@ #include "Arch/Mips.h" #include "Arch/Sparc.h" #include "CommonArgs.h" +#include "clang/Config/config.h" #include "clang/Driver/Compilation.h" #include "clang/Driver/Driver.h" #include "clang/Driver/Options.h" @@ -435,6 +436,40 @@ return ToolChain::CST_Libstdcxx; } +void NetBSD::AddClangSystemIncludeArgs( + const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args) const { + const Driver &D = getDriver(); + + if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc)) + return; + + if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { + SmallString<128> Dir(D.ResourceDir); + llvm::sys::path::append(Dir, "include"); + addSystemInclude(DriverArgs, CC1Args, Dir.str()); + } + + if (DriverArgs.hasArg(options::OPT_nostdlibinc)) + return; + + // Check for configure-time C include directories. + StringRef CIncludeDirs(C_INCLUDE_DIRS); + if (CIncludeDirs != "") { + SmallVector<StringRef, 5> dirs; + CIncludeDirs.split(dirs, ":"); + for (StringRef dir : dirs) { + StringRef Prefix = + llvm::sys::path::is_absolute(dir) ? StringRef(D.SysRoot) : ""; + addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir); + } + return; + } + + addExternCSystemInclude(DriverArgs, CC1Args, + concat(D.SysRoot, "/usr/include")); +} + void NetBSD::addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const { const std::string Candidates[] = {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits