diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -94,6 +94,7 @@ #include "llvm/Support/StringSaver.h" #include "llvm/Support/VirtualFileSystem.h" #include "llvm/Support/raw_ostream.h" +#include // ::getenv #include #include #include @@ -1066,6 +1067,12 @@ } bool Driver::loadDefaultConfigFiles(ArrayRef CfgFileSearchDirs) { + // Disable default config if CLANG_NO_DEFAULT_CONFIG is set to a non-empty + // value. + if (const char *NoConfigEnv = ::getenv("CLANG_NO_DEFAULT_CONFIG")) { + if (*NoConfigEnv) + return false; + } if (CLOptions && CLOptions->hasArg(options::OPT_no_default_config)) return false; diff --git a/clang/test/Driver/config-file3.c b/clang/test/Driver/config-file3.c --- a/clang/test/Driver/config-file3.c +++ b/clang/test/Driver/config-file3.c @@ -1,6 +1,7 @@ // REQUIRES: shell // REQUIRES: x86-registered-target +// RUN: unset CLANG_NO_DEFAULT_CONFIG // RUN: rm -rf %t && mkdir %t //--- If config file is specified by relative path (workdir/cfg-s2), it is searched for by that path. diff --git a/clang/test/Driver/env.c b/clang/test/Driver/env.c --- a/clang/test/Driver/env.c +++ b/clang/test/Driver/env.c @@ -4,13 +4,13 @@ // // REQUIRES: shell // The PATH variable is heavily used when trying to find a linker. -// RUN: env -i LC_ALL=C LD_LIBRARY_PATH="$LD_LIBRARY_PATH" \ +// RUN: env -i LC_ALL=C LD_LIBRARY_PATH="$LD_LIBRARY_PATH" CLANG_NO_DEFAULT_CONFIG=1 \ // RUN: %clang %s -### -o %t.o --target=i386-unknown-linux \ // RUN: --sysroot=%S/Inputs/basic_linux_tree \ // RUN: --rtlib=platform -no-pie \ // RUN: --gcc-toolchain="" 2>&1 | FileCheck --check-prefix=CHECK-LD-32 %s // -// RUN: env -i LC_ALL=C PATH="" LD_LIBRARY_PATH="$LD_LIBRARY_PATH" \ +// RUN: env -i LC_ALL=C PATH="" LD_LIBRARY_PATH="$LD_LIBRARY_PATH" CLANG_NO_DEFAULT_CONFIG=1 \ // RUN: %clang %s -### -o %t.o --target=i386-unknown-linux \ // RUN: --sysroot=%S/Inputs/basic_linux_tree \ // RUN: --rtlib=platform -no-pie \ diff --git a/clang/test/Unit/lit.cfg.py b/clang/test/Unit/lit.cfg.py --- a/clang/test/Unit/lit.cfg.py +++ b/clang/test/Unit/lit.cfg.py @@ -71,3 +71,8 @@ else: lit_config.warning("unable to inject shared library path on '{}'" .format(platform.system())) + +# It is not realistically possible to account for all options that could +# possibly be present in system and user configuration files, so disable +# default configs for the test runs. +config.environment["CLANG_NO_DEFAULT_CONFIG"] = "1" diff --git a/clang/test/lit.cfg.py b/clang/test/lit.cfg.py --- a/clang/test/lit.cfg.py +++ b/clang/test/lit.cfg.py @@ -284,3 +284,8 @@ if 'system-aix' in config.available_features: config.substitutions.append(('llvm-nm', 'env OBJECT_MODE=any llvm-nm')) + +# It is not realistically possible to account for all options that could +# possibly be present in system and user configuration files, so disable +# default configs for the test runs. +config.environment["CLANG_NO_DEFAULT_CONFIG"] = "1"