[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.
This commit is contained in:
Fangrui Song 2021-03-28 11:30:27 -07:00
parent 3fb40ce167
commit 53c98d85a8
4 changed files with 16 additions and 4 deletions

View File

@ -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);

View File

@ -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)) {

View File

@ -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 <vector>

View File

@ -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"