[PATCH] D134018: [clang] [Driver] Add an option to disable default config filenames

Michał Górny via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 16 00:10:52 PDT 2022


mgorny created this revision.
mgorny added reviewers: sepavloff, asymptotically, MaskRay, tstellar.
Herald added a subscriber: StephenFan.
Herald added a project: All.
mgorny requested review of this revision.

Add a `--no-default-config` option that disables the search for default
set of config filenames (based on the compiler executable name).

Suggested in https://discourse.llvm.org/t/rfc-adding-a-default-file-location-to-config-file-support/63606.


https://reviews.llvm.org/D134018

Files:
  clang/docs/UsersManual.rst
  clang/include/clang/Driver/Options.td
  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
@@ -41,6 +41,12 @@
 //
 // CHECK-EXPLICIT: Configuration file: {{.*}}/Inputs/config/i386-qqq.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
+//
+// NO-DEFAULT-CONFIG-NOT: Configuration file:
+//
 //--- Invocation qqq-clang-g++ tries to find config file qqq.cfg if qqq-clang-g++.cfg is not found.
 //
 // RUN: rm %t/testdmode/qqq-clang-g++.cfg
Index: clang/lib/Driver/Driver.cpp
===================================================================
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1024,11 +1024,14 @@
     }
   }
 
-  // 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())
-    CfgFileName = ClangNameParts.TargetPrefix + '-' + ClangNameParts.ModeSuffix;
+  if (!CLOptions || !CLOptions->hasArg(options::OPT_no_default_config)) {
+    // 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())
+      CfgFileName =
+          ClangNameParts.TargetPrefix + '-' + ClangNameParts.ModeSuffix;
+  }
 
   if (CfgFileName.empty())
     return false;
Index: clang/include/clang/Driver/Options.td
===================================================================
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -901,6 +901,8 @@
 def compatibility__version : JoinedOrSeparate<["-"], "compatibility_version">;
 def config : Separate<["--"], "config">, Flags<[NoXarchOption]>,
   HelpText<"Specifies configuration file">;
+def no_default_config : Flag<["--"], "no-default-config">, Flags<[NoXarchOption]>,
+  HelpText<"Disable loading default configuration files">;
 def config_system_dir_EQ : Joined<["--"], "config-system-dir=">, Flags<[NoXarchOption, HelpHidden]>,
   HelpText<"System directory for configuration files">;
 def config_user_dir_EQ : Joined<["--"], "config-user-dir=">, Flags<[NoXarchOption, HelpHidden]>,
Index: clang/docs/UsersManual.rst
===================================================================
--- clang/docs/UsersManual.rst
+++ clang/docs/UsersManual.rst
@@ -904,6 +904,10 @@
 CLANG_CONFIG_FILE_SYSTEM_DIR respectively. The first file found is used. It is
 an error if the required file cannot be found.
 
+If no explicit configuration file is specified, Clang searches for a default
+configuration file following the rules described in the next paragraphs.
+To disable this behavior, `--no-default-config` flag can be used.
+
 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134018.460657.patch
Type: text/x-patch
Size: 3353 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220916/8e6e33c3/attachment-0001.bin>


More information about the cfe-commits mailing list