diff options
| author | Martin Storsjo <martin@martin.st> | 2018-04-25 21:23:59 +0000 |
|---|---|---|
| committer | Martin Storsjo <martin@martin.st> | 2018-04-25 21:23:59 +0000 |
| commit | 1fab23da1cef52d1752cb5877048c5d771e9b0f1 (patch) | |
| tree | e0c26819c000253d9461c987900b9f749dd1f09c | |
| parent | 2faf606fb6679cd0fbaed48aef8765b684835578 (diff) | |
| download | bcm5719-llvm-1fab23da1cef52d1752cb5877048c5d771e9b0f1.tar.gz bcm5719-llvm-1fab23da1cef52d1752cb5877048c5d771e9b0f1.zip | |
[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
| -rw-r--r-- | clang/include/clang/Driver/ToolChain.h | 4 | ||||
| -rw-r--r-- | clang/lib/Driver/Driver.cpp | 3 | ||||
| -rw-r--r-- | clang/test/Driver/config-file3.c | 8 |
3 files changed, 14 insertions, 1 deletions
diff --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h index b1f7338c891..9b90801c9bd 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 ceb772c87f2..932a54fad42 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<const char *> 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 c1b523cbf97..938411cf0ff 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 |

