[clang] d970ab6 - Driver: Accept multiple --config options if filenames are the same

Tom Stellard via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 16 12:24:16 PDT 2020


Author: Tom Stellard
Date: 2020-06-16T12:23:57-07:00
New Revision: d970ab63e22eb5918774953da6b99ac27e5832a0

URL: https://github.com/llvm/llvm-project/commit/d970ab63e22eb5918774953da6b99ac27e5832a0
DIFF: https://github.com/llvm/llvm-project/commit/d970ab63e22eb5918774953da6b99ac27e5832a0.diff

LOG: Driver: Accept multiple --config options if filenames are the same

Summary:
We're trying to use the --config options to pass distro specific
options for Fedora via the CFLAGS variable.  However, some projects
end up using the CFLAGS variable multiple times in their command line,
which leads to an error when --config is used.

This patch resolves this issue by allowing more than one --config option
on the command line as long as the file names are the same.

Reviewers: sepavloff, hfinkel

Reviewed By: sepavloff

Subscribers: cfe-commits, llvm-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D81424

Added: 
    

Modified: 
    clang/lib/Driver/Driver.cpp
    clang/test/Driver/config-file.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 3add665c1156..a8442d2cd0af 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -833,8 +833,12 @@ bool Driver::loadConfigFile() {
     std::vector<std::string> ConfigFiles =
         CLOptions->getAllArgValues(options::OPT_config);
     if (ConfigFiles.size() > 1) {
-      Diag(diag::err_drv_duplicate_config);
-      return true;
+      if (!std::all_of(
+              ConfigFiles.begin(), ConfigFiles.end(),
+              [ConfigFiles](std::string s) { return s == ConfigFiles[0]; })) {
+        Diag(diag::err_drv_duplicate_config);
+        return true;
+      }
     }
 
     if (!ConfigFiles.empty()) {

diff  --git a/clang/test/Driver/config-file.c b/clang/test/Driver/config-file.c
index 04127d404f67..fde7260ecd73 100644
--- a/clang/test/Driver/config-file.c
+++ b/clang/test/Driver/config-file.c
@@ -71,3 +71,8 @@
 // RUN: %clang --config-system-dir=%S/Inputs/config --config-user-dir=%S/Inputs/config2 --config config-4 -S %s -o /dev/null -v 2>&1 | FileCheck %s -check-prefix CHECK-PRECEDENCE
 // CHECK-PRECEDENCE: Configuration file: {{.*}}Inputs{{.}}config2{{.}}config-4.cfg
 // CHECK-PRECEDENCE: -Wall
+
+
+//--- Duplicate --config options are allowed if the value is the same
+// RUN: %clang --config-system-dir=%S/Inputs/config --config-user-dir=%S/Inputs/config2 --config config-4 --config config-4 -S %s -o /dev/null -v 2>&1 | FileCheck %s -check-prefix CHECK-SAME-CONFIG
+// CHECK-SAME-CONFIG: Configuration file: {{.*}}Inputs{{.}}config2{{.}}config-4.cfg


        


More information about the cfe-commits mailing list