[driver/Darwin] Adjust SDKROOT handling code to not generate "-isysroot /".

llvm-svn: 172548
This commit is contained in:
Daniel Dunbar
2013-01-15 20:33:56 +00:00
parent 9f4a1c6184
commit b2543043e6
2 changed files with 15 additions and 4 deletions

View File

@@ -404,9 +404,10 @@ void Darwin::AddDeploymentTarget(DerivedArgList &Args) const {
getDriver().Diag(clang::diag::warn_missing_sysroot) << A->getValue();
} else {
if (char *env = ::getenv("SDKROOT")) {
// We only use this value as the default if it is an absolute path and
// exists.
if (llvm::sys::path::is_absolute(env) && llvm::sys::fs::exists(env)) {
// We only use this value as the default if it is an absolute path,
// exists, and it is not the root path.
if (llvm::sys::path::is_absolute(env) && llvm::sys::fs::exists(env) &&
StringRef(env) != "/") {
Args.append(Args.MakeSeparateArg(
0, Opts.getOption(options::OPT_isysroot), env));
}

View File

@@ -11,7 +11,7 @@
// CHECK-BASIC: "-isysroot" "{{.*tmpdir}}"
// Check that we don't use SDKROOT as the default if it is not a valid path.
//
// RUN: rm -rf %t.nonpath
// RUN: env SDKROOT=%t.nonpath %clang -target x86_64-apple-darwin10 \
// RUN: -c %s -### 2> %t.log
@@ -20,3 +20,13 @@
// CHECK-NONPATH: clang
// CHECK-NONPATH: "-cc1"
// CHECK-NONPATH-NOT: "-isysroot"
// Check that we don't use SDKROOT as the default if it is just "/"
//
// RUN: env SDKROOT=/ %clang -target x86_64-apple-darwin10 \
// RUN: -c %s -### 2> %t.log
// RUN: FileCheck --check-prefix=CHECK-NONROOT < %t.log %s
//
// CHECK-NONROOT: clang
// CHECK-NONROOT: "-cc1"
// CHECK-NONROOT-NOT: "-isysroot"