From 1fab23da1cef52d1752cb5877048c5d771e9b0f1 Mon Sep 17 00:00:00 2001 From: Martin Storsjo Date: Wed, 25 Apr 2018 21:23:59 +0000 Subject: [PATCH] [Driver] Fix implicit config files from prefixed symlinks If -no-canonical-prefixes isn't used, the clang executable name used is the one of the actual executable, not the name of the symlink that the user invoked. In these cases, the target prefix was overridden based on the clang executable name. (On the other hand the implicit -target option that such a symlink adds, is added as an actual command line parameter in tools/driver/driver.cop, before resolving the symlink and finding the actual clang executable. Use the original ClangNameParts (set from argv[0] in tools/driver/driver.cpp) if it seems to be initialized propery. All existing tests of this feature used -no-canonical-prefixes (possibly because it also makes the driver look in the directory of the symlink instead of the directory of the executable); add another one that uses --config-user-dir= to specify the directory instead. (For actual users of such symlinks, outisde of the test suite, the directory is probably the same for both.) This makes this feature work more like what the documentation describes. Differential Revision: https://reviews.llvm.org/D45964 llvm-svn: 330871 --- clang/include/clang/Driver/ToolChain.h | 4 ++++ clang/lib/Driver/Driver.cpp | 3 ++- clang/test/Driver/config-file3.c | 8 ++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h index b1f7338c8910..9b90801c9bd4 100644 --- a/clang/include/clang/Driver/ToolChain.h +++ b/clang/include/clang/Driver/ToolChain.h @@ -78,6 +78,10 @@ struct ParsedClangName { bool IsRegistered) : TargetPrefix(Target), ModeSuffix(Suffix), DriverMode(Mode), TargetIsValid(IsRegistered) {} + + bool isEmpty() const { + return TargetPrefix.empty() && ModeSuffix.empty() && DriverMode == nullptr; + } }; /// ToolChain - Access to tools for a single platform. diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index ceb772c87f2d..932a54fad428 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -129,7 +129,8 @@ Driver::Driver(StringRef ClangExecutable, StringRef DefaultTargetTriple, void Driver::ParseDriverMode(StringRef ProgramName, ArrayRef Args) { - ClangNameParts = ToolChain::getTargetAndModeFromProgramName(ProgramName); + if (ClangNameParts.isEmpty()) + ClangNameParts = ToolChain::getTargetAndModeFromProgramName(ProgramName); setDriverModeFromOption(ClangNameParts.DriverMode); for (const char *ArgPtr : Args) { diff --git a/clang/test/Driver/config-file3.c b/clang/test/Driver/config-file3.c index c1b523cbf97e..938411cf0fff 100644 --- a/clang/test/Driver/config-file3.c +++ b/clang/test/Driver/config-file3.c @@ -27,6 +27,14 @@ // FULL-NAME: -Wundefined-func-template // FULL-NAME-NOT: -Werror // +//--- Invocation qqq-clang-g++ tries to find config file qqq-clang-g++.cfg even without -no-canonical-prefixes. +// (As the clang executable and symlink are in different directories, this +// requires specifying the path via --config-*-dir= though.) +// +// RUN: %T/testdmode/qqq-clang-g++ --config-system-dir= --config-user-dir=%T/testdmode -c %s -### 2>&1 | FileCheck %s -check-prefix SYMLINK +// +// SYMLINK: Configuration file: {{.*}}/testdmode/qqq-clang-g++.cfg +// //--- File specified by --config overrides config inferred from clang executable. // // RUN: %T/testdmode/qqq-clang-g++ --config-system-dir=%S/Inputs/config --config-user-dir= --config i386-qqq -c -no-canonical-prefixes %s -### 2>&1 | FileCheck %s -check-prefix CHECK-EXPLICIT