[PATCH] D45964: [Driver] Fix implicit config files from prefixed symlinks

Martin Storsjö via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 23 07:43:01 PDT 2018


mstorsjo created this revision.
mstorsjo added reviewers: sepavloff, hfinkel, hans, rnk.

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.


Repository:
  rC Clang

https://reviews.llvm.org/D45964

Files:
  lib/Driver/Driver.cpp
  test/Driver/config-file3.c


Index: test/Driver/config-file3.c
===================================================================
--- test/Driver/config-file3.c
+++ 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
Index: lib/Driver/Driver.cpp
===================================================================
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -129,7 +129,8 @@
 
 void Driver::ParseDriverMode(StringRef ProgramName,
                              ArrayRef<const char *> Args) {
-  ClangNameParts = ToolChain::getTargetAndModeFromProgramName(ProgramName);
+  if (ClangNameParts.TargetPrefix.empty() && ClangNameParts.DriverMode == nullptr)
+    ClangNameParts = ToolChain::getTargetAndModeFromProgramName(ProgramName);
   setDriverModeFromOption(ClangNameParts.DriverMode);
 
   for (const char *ArgPtr : Args) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45964.143560.patch
Type: text/x-patch
Size: 1626 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180423/5ce08333/attachment.bin>


More information about the cfe-commits mailing list