From d970ab63e22eb5918774953da6b99ac27e5832a0 Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Tue, 16 Jun 2020 11:20:20 -0700 Subject: [PATCH] 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 --- clang/lib/Driver/Driver.cpp | 8 ++++++-- clang/test/Driver/config-file.c | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 3add665..a8442d2 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -833,8 +833,12 @@ bool Driver::loadConfigFile() { std::vector 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 04127d4..fde7260 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 -- 1.8.3.1