Index: clang/docs/UsersManual.rst =================================================================== --- clang/docs/UsersManual.rst +++ clang/docs/UsersManual.rst @@ -911,12 +911,14 @@ Another way to specify a configuration file is to encode it in executable name. For example, if the Clang executable is named `armv7l-clang` (it may be a symbolic link to `clang`), then Clang will search for file `armv7l.cfg` in the -directory where Clang resides. +directory where Clang resides. If Clang is started via an executable without +target prefix, Clang will use `default.cfg` instead. If a driver mode is specified in invocation, Clang tries to find a file specific for the specified mode. For example, if the executable file is named `x86_64-clang-cl`, Clang first looks for `x86_64-cl.cfg` and if it is not found, -looks for `x86_64.cfg`. +looks for `x86_64.cfg`. Similarly, for `clang-cl`, it looks for `default-cl.cfg` +before trying `default.cfg`. If the command line contains options that effectively change target architecture (these are -m32, -EL, and some others) and the configuration file starts with an Index: clang/lib/Driver/Driver.cpp =================================================================== --- clang/lib/Driver/Driver.cpp +++ clang/lib/Driver/Driver.cpp @@ -1024,18 +1024,21 @@ } } - if (!(CLOptions && CLOptions->hasArg(options::OPT_no_default_config))) { + if (CfgFileName.empty()) { + if (CLOptions && CLOptions->hasArg(options::OPT_no_default_config)) + return false; + // If config file is not specified explicitly, try to deduce configuration // from executable name. For instance, an executable 'armv7l-clang' will - // search for config file 'armv7l-clang.cfg'. - if (CfgFileName.empty() && !ClangNameParts.TargetPrefix.empty()) + // search for config file 'armv7l-clang.cfg'. If we are called without + // a specific prefix, use e.g. 'default-clang.cfg' instead. + if (!ClangNameParts.TargetPrefix.empty()) CfgFileName = ClangNameParts.TargetPrefix + '-' + ClangNameParts.ModeSuffix; + else + CfgFileName = "default-" + ClangNameParts.ModeSuffix; } - if (CfgFileName.empty()) - return false; - // Determine architecture part of the file name, if it is present. StringRef CfgFileArch = CfgFileName; size_t ArchPrefixLen = CfgFileArch.find('-'); @@ -1093,9 +1096,9 @@ return readConfigFile(CfgFilePath); // Finally try removing driver mode part: 'x86_64-clang.cfg' -> 'x86_64.cfg'. - if (!ClangNameParts.ModeSuffix.empty() && - !ClangNameParts.TargetPrefix.empty()) { - CfgFileName.assign(ClangNameParts.TargetPrefix); + if (!FileSpecifiedExplicitly && !ClangNameParts.ModeSuffix.empty()) { + CfgFileName.resize(CfgFileName.size() - ClangNameParts.ModeSuffix.size() - + 5); CfgFileName.append(".cfg"); if (searchForFile(CfgFilePath, CfgFileSearchDirs, CfgFileName, getVFS())) return readConfigFile(CfgFilePath); Index: clang/test/Driver/config-file3.c =================================================================== --- clang/test/Driver/config-file3.c +++ clang/test/Driver/config-file3.c @@ -21,6 +21,10 @@ // RUN: ln -s %clang %t/testdmode/qqq-clang-g++ // RUN: echo "-Wundefined-func-template" > %t/testdmode/qqq-clang-g++.cfg // RUN: echo "-Werror" > %t/testdmode/qqq.cfg +// RUN: ln -s %clang %t/testdmode/clang-g++ +// RUN: ln -s %clang %t/testdmode/clang +// RUN: : > %t/testdmode/default-clang.cfg +// RUN: : > %t/testdmode/default.cfg // RUN: %t/testdmode/qqq-clang-g++ --config-system-dir= --config-user-dir= -c -no-canonical-prefixes -### %s 2>&1 | FileCheck %s -check-prefix FULL-NAME // // FULL-NAME: Configuration file: {{.*}}/testdmode/qqq-clang-g++.cfg @@ -41,6 +45,16 @@ // // CHECK-EXPLICIT: Configuration file: {{.*}}/Inputs/config/i386-qqq.cfg +//--- Invoking clang falls back to default-clang.cfg. +// RUN: %t/testdmode/clang --config-system-dir= --config-user-dir= -c -no-canonical-prefixes -### %s 2>&1 | FileCheck %s -check-prefix DEFAULT-CLANG +// +// DEFAULT-CLANG: Configuration file: {{.*}}/testdmode/default-clang.cfg + +//--- Invoking clang-g++ falls back to default.cfg. +// RUN: %t/testdmode/clang-g++ --config-system-dir= --config-user-dir= -c -no-canonical-prefixes -### %s 2>&1 | FileCheck %s -check-prefix DEFAULT +// +// DEFAULT: Configuration file: {{.*}}/testdmode/default.cfg + //--- --no-default-config disables config search. // // RUN: %t/testdmode/qqq-clang-g++ --config-system-dir= --config-user-dir=%t/testdmode --no-default-config -c -### %s 2>&1 | FileCheck %s -check-prefix NO-DEFAULT-CONFIG