[PATCH] D109621: [clang] [Driver] Fall back to default.cfg when calling clang w/o prefix
Michał Górny via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 16 13:25:58 PDT 2022
mgorny updated this revision to Diff 460877.
mgorny retitled this revision from "[clang][Driver] Default to loading clang.cfg if config file not specified" to "[clang] [Driver] Fall back to default.cfg when calling clang w/o prefix".
mgorny edited the summary of this revision.
mgorny added a comment.
Changed the base config filename to `default.cfg`, and included looking up `default-<mode-suffix>.cfg` first. Added tests.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D109621/new/
https://reviews.llvm.org/D109621
Files:
clang/docs/UsersManual.rst
clang/lib/Driver/Driver.cpp
clang/test/Driver/config-file3.c
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
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/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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109621.460877.patch
Type: text/x-patch
Size: 4655 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220916/ca55e137/attachment.bin>
More information about the cfe-commits
mailing list