Skip to content

Commit 9ade6a9

Browse files
committed
Fix a tiny bug in -no-canonical-prefixes that somehow we have never
noticed until now. The code for setting up the driver's InstalledDir didn't respect -no-canonical-prefixes. Because of this, there are a few places in the driver where we would unexpectedly form absolute paths, notably when searching for and finding GCC installations to use, etc. The fix is straightforward, and I've added this path to '-v' both so we can test it sanely and so that it will be substantially more obvious the next time someone has to debug something here. Note that there is another bug that we don't actually *canonicalize* the installed directory! I don't really want to fix that because I don't have a realistic way to test the usage of this mode. I suspect that folks using the shared module cache would care about getting this right though, and so they might want to address it. I've left the appropriate FIXMEs so that it is clear what to change, and I've updated the test code to make it clear what is happening here. llvm-svn: 244065
1 parent bce20af commit 9ade6a9

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,9 @@ void Driver::PrintVersion(const Compilation &C, raw_ostream &OS) const {
762762
} else
763763
OS << "Thread model: " << TC.getThreadModel();
764764
OS << '\n';
765+
766+
// Print out the install directory.
767+
OS << "InstalledDir: " << InstalledDir << '\n';
765768
}
766769

767770
/// PrintDiagnosticCategories - Implement the --print-diagnostic-categories
Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
// Due to ln -sf:
22
// REQUIRES: shell
3-
// RUN: mkdir -p %t
4-
// RUN: cd %t
3+
// RUN: mkdir -p %t.real
4+
// RUN: cd %t.real
55
// RUN: ln -sf %clang test-clang
6-
// RUN: ./test-clang -v -S %s 2>&1 | FileCheck %s
7-
// RUN: ./test-clang -v -S %s -no-canonical-prefixes 2>&1 | FileCheck --check-prefix=NCP %s
8-
9-
10-
// CHECK: /clang{{.*}}" -cc1
11-
// NCP: test-clang" -cc1
6+
// RUN: cd ..
7+
// RUN: ln -sf %t.real %t.fake
8+
// RUN: cd %t.fake
9+
// RUN: ./test-clang -v -S %s 2>&1 | FileCheck --check-prefix=CANONICAL %s
10+
// RUN: ./test-clang -v -S %s -no-canonical-prefixes 2>&1 | FileCheck --check-prefix=NON-CANONICAL %s
11+
//
12+
// FIXME: This should really be '.real'.
13+
// CANONICAL: InstalledDir: {{.*}}.fake
14+
// CANONICAL: {{[/|\\]*}}clang{{.*}}" -cc1
15+
//
16+
// NON-CANONICAL: InstalledDir: .{{$}}
17+
// NON-CANONICAL: test-clang" -cc1

clang/tools/driver/driver.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ CreateAndPopulateDiagOpts(ArrayRef<const char *> argv) {
344344
}
345345

346346
static void SetInstallDir(SmallVectorImpl<const char *> &argv,
347-
Driver &TheDriver) {
347+
Driver &TheDriver, bool CanonicalPrefixes) {
348348
// Attempt to find the original path used to invoke the driver, to determine
349349
// the installed path. We do this manually, because we want to support that
350350
// path being a symlink.
@@ -355,7 +355,11 @@ static void SetInstallDir(SmallVectorImpl<const char *> &argv,
355355
if (llvm::ErrorOr<std::string> Tmp = llvm::sys::findProgramByName(
356356
llvm::sys::path::filename(InstalledPath.str())))
357357
InstalledPath = *Tmp;
358-
llvm::sys::fs::make_absolute(InstalledPath);
358+
359+
// FIXME: We don't actually canonicalize this, we just make it absolute.
360+
if (CanonicalPrefixes)
361+
llvm::sys::fs::make_absolute(InstalledPath);
362+
359363
InstalledPath = llvm::sys::path::parent_path(InstalledPath);
360364
if (llvm::sys::fs::exists(InstalledPath.c_str()))
361365
TheDriver.setInstalledDir(InstalledPath);
@@ -473,7 +477,7 @@ int main(int argc_, const char **argv_) {
473477
ProcessWarningOptions(Diags, *DiagOpts, /*ReportDiags=*/false);
474478

475479
Driver TheDriver(Path, llvm::sys::getDefaultTargetTriple(), Diags);
476-
SetInstallDir(argv, TheDriver);
480+
SetInstallDir(argv, TheDriver, CanonicalPrefixes);
477481

478482
llvm::InitializeAllTargets();
479483
insertArgsFromProgramName(ProgName, DS, argv, SavedStrings);

0 commit comments

Comments
 (0)