From 53c98d85a8a609552448043d5512e70313b1eb1b Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sun, 28 Mar 2021 11:30:27 -0700 Subject: [PATCH] [Driver] Suppress libstdc++/libc++ path with -nostdinc This follows GCC. Having libstdc++/libc++ include paths is not useful anyway because libstdc++/libc++ header files cannot find features.h. While here, suppress -stdlib++-isystem with -nostdlibinc. --- clang/lib/Driver/ToolChain.cpp | 3 ++- clang/lib/Driver/ToolChains/Gnu.cpp | 5 +++-- clang/test/Driver/nostdincxx.cpp | 2 ++ clang/test/Driver/stdlibxx-isystem.cpp | 10 +++++++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp index 217ba56c3351..6b747f06439f 100644 --- a/clang/lib/Driver/ToolChain.cpp +++ b/clang/lib/Driver/ToolChain.cpp @@ -916,7 +916,8 @@ void ToolChain::AddClangCXXStdlibIsystemArgs( const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const { DriverArgs.ClaimAllArgs(options::OPT_stdlibxx_isystem); - if (!DriverArgs.hasArg(options::OPT_nostdincxx)) + if (!DriverArgs.hasArg(options::OPT_nostdinc, options::OPT_nostdincxx, + options::OPT_nostdlibinc)) for (const auto &P : DriverArgs.getAllArgValues(options::OPT_stdlibxx_isystem)) addSystemInclude(DriverArgs, CC1Args, P); diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp index 7136df94c528..0fe3916b008e 100644 --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -2876,8 +2876,9 @@ void Generic_GCC::AddMultilibIncludeArgs(const ArgList &DriverArgs, void Generic_GCC::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, ArgStringList &CC1Args) const { - if (DriverArgs.hasArg(options::OPT_nostdlibinc) || - DriverArgs.hasArg(options::OPT_nostdincxx)) + if (DriverArgs.hasArg(options::OPT_nostdinc) || + DriverArgs.hasArg(options::OPT_nostdincxx) || + DriverArgs.hasArg(options::OPT_nostdlibinc)) return; switch (GetCXXStdlibType(DriverArgs)) { diff --git a/clang/test/Driver/nostdincxx.cpp b/clang/test/Driver/nostdincxx.cpp index dc87336ece54..3fc7a5e76842 100644 --- a/clang/test/Driver/nostdincxx.cpp +++ b/clang/test/Driver/nostdincxx.cpp @@ -1,4 +1,6 @@ +// RUN: not %clangxx -nostdinc %s 2>&1 | FileCheck %s // RUN: not %clangxx -nostdinc++ %s 2>&1 | FileCheck %s +// RUN: not %clangxx -nostdlibinc %s 2>&1 | FileCheck %s // CHECK: file not found #include diff --git a/clang/test/Driver/stdlibxx-isystem.cpp b/clang/test/Driver/stdlibxx-isystem.cpp index 827cdf9a7c71..cadfa25c0db9 100644 --- a/clang/test/Driver/stdlibxx-isystem.cpp +++ b/clang/test/Driver/stdlibxx-isystem.cpp @@ -43,11 +43,19 @@ // RUN: FileCheck -check-prefix=NOCC1 %s // NOCC1-NOT: "-stdlib++-isystem" "/tmp" -// It should respect -nostdinc++. +// It should respect -nostdinc++ // RUN: %clang -target aarch64-linux-gnu -ccc-install-dir %t/bin \ // RUN: -stdlib++-isystem /tmp/foo -stdlib++-isystem /tmp/bar -nostdinc++ \ // RUN: -fsyntax-only %s -### 2>&1 | FileCheck -check-prefix=NOSTDINCXX %s // RUN: %clang -target x86_64-apple-darwin -ccc-install-dir %t/bin \ // RUN: -stdlib++-isystem /tmp/foo -stdlib++-isystem /tmp/bar -nostdinc++ \ // RUN: -fsyntax-only %s -### 2>&1 | FileCheck -check-prefix=NOSTDINCXX %s + +// ... and -nostdinc and -nostdlibinc. +// RUN: %clang -target aarch64-linux-gnu -ccc-install-dir %t/bin \ +// RUN: -stdlib++-isystem /tmp/foo -stdlib++-isystem /tmp/bar -nostdinc \ +// RUN: -fsyntax-only %s -### 2>&1 | FileCheck --check-prefix=NOSTDINCXX %s +// RUN: %clang -target aarch64-linux-gnu -ccc-install-dir %t/bin \ +// RUN: -stdlib++-isystem /tmp/foo -stdlib++-isystem /tmp/bar -nostdlibinc \ +// RUN: -fsyntax-only %s -### 2>&1 | FileCheck --check-prefix=NOSTDINCXX %s // NOSTDINCXX-NOT: "-internal-isystem" "/tmp/foo" "-internal-isystem" "/tmp/bar"