Author: mstorsjo Date: Wed Apr 25 14:23:59 2018 New Revision: 330871 URL: http://llvm.org/viewvc/llvm-project?rev=330871&view=rev Log: [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 Modified: cfe/trunk/include/clang/Driver/ToolChain.h cfe/trunk/lib/Driver/Driver.cpp cfe/trunk/test/Driver/config-file3.c Modified: cfe/trunk/include/clang/Driver/ToolChain.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/ToolChain.h?rev=330871&r1=330870&r2=330871&view=diff ============================================================================== --- cfe/trunk/include/clang/Driver/ToolChain.h (original) +++ cfe/trunk/include/clang/Driver/ToolChain.h Wed Apr 25 14:23:59 2018 @@ -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. Modified: cfe/trunk/lib/Driver/Driver.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=330871&r1=330870&r2=330871&view=diff ============================================================================== --- cfe/trunk/lib/Driver/Driver.cpp (original) +++ cfe/trunk/lib/Driver/Driver.cpp Wed Apr 25 14:23:59 2018 @@ -129,7 +129,8 @@ Driver::Driver(StringRef ClangExecutable 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) { Modified: cfe/trunk/test/Driver/config-file3.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/config-file3.c?rev=330871&r1=330870&r2=330871&view=diff ============================================================================== --- cfe/trunk/test/Driver/config-file3.c (original) +++ cfe/trunk/test/Driver/config-file3.c Wed Apr 25 14:23:59 2018 @@ -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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits