diff options
| author | Chad Rosier <mcrosier@apple.com> | 2013-04-26 20:49:50 +0000 |
|---|---|---|
| committer | Chad Rosier <mcrosier@apple.com> | 2013-04-26 20:49:50 +0000 |
| commit | a35d5a38fe650a9ffb8395657d9321ef50c139f2 (patch) | |
| tree | 3161758a6927a7b610ffbc937cb9e334a6e94bfa | |
| parent | 148fdf2ed14b779810cfe5d557921fc81935f88b (diff) | |
| download | bcm5719-llvm-a35d5a38fe650a9ffb8395657d9321ef50c139f2.tar.gz bcm5719-llvm-a35d5a38fe650a9ffb8395657d9321ef50c139f2.zip | |
[driver] Implement the -fdebug-compilation-dir in a way that is compatible with
gcc. No test case included as I'm having problems finding a test case where
the inode/dev don't match.
llvm-svn: 180628
| -rw-r--r-- | clang/lib/Driver/Tools.cpp | 29 | ||||
| -rw-r--r-- | clang/test/Driver/debug-comp-dir.S | 3 | ||||
| -rw-r--r-- | clang/test/Driver/debug.c | 3 |
3 files changed, 21 insertions, 14 deletions
diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index 2ea4932a84d..dec2ba5cec5 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -7,6 +7,9 @@ // //===----------------------------------------------------------------------===// +#include <sys/param.h> +#include <sys/stat.h> +#include <unistd.h> #include "Tools.h" #include "InputInfo.h" #include "SanitizerArgs.h" @@ -1776,14 +1779,24 @@ static bool shouldUseLeafFramePointer(const ArgList &Args, /// If the PWD environment variable is set, add a CC1 option to specify the /// debug compilation directory. static void addDebugCompDirArg(const ArgList &Args, ArgStringList &CmdArgs) { - if (const char *pwd = ::getenv("PWD")) { - // GCC also verifies that stat(pwd) and stat(".") have the same inode - // number. Not doing those because stats are slow, but we could. - if (llvm::sys::path::is_absolute(pwd)) { - std::string CompDir = pwd; - CmdArgs.push_back("-fdebug-compilation-dir"); - CmdArgs.push_back(Args.MakeArgString(CompDir)); - } + struct stat StatPWDBuf, StatDotBuf; + + const char *pwd; + if ((pwd = ::getenv("PWD")) != 0 && + llvm::sys::path::is_absolute(pwd) && + stat(pwd, &StatPWDBuf) == 0 && + stat(".", &StatDotBuf) == 0 && + StatPWDBuf.st_ino == StatDotBuf.st_ino && + StatPWDBuf.st_dev == StatDotBuf.st_dev) { + CmdArgs.push_back("-fdebug-compilation-dir"); + CmdArgs.push_back(Args.MakeArgString(pwd)); + return; + } + // Fall back to using getcwd. + char cwd[MAXPATHLEN]; + if (pwd && ::getcwd(cwd, MAXPATHLEN)) { + CmdArgs.push_back("-fdebug-compilation-dir"); + CmdArgs.push_back(Args.MakeArgString(cwd)); } } diff --git a/clang/test/Driver/debug-comp-dir.S b/clang/test/Driver/debug-comp-dir.S index ca1ca30ae6b..daf895c18ac 100644 --- a/clang/test/Driver/debug-comp-dir.S +++ b/clang/test/Driver/debug-comp-dir.S @@ -1,9 +1,6 @@ // RUN: cd %S && %clang -### -g %s -c 2>&1 | FileCheck -check-prefix=CHECK-PWD %s // CHECK-PWD: {{"-fdebug-compilation-dir" ".*Driver.*"}} -// RUN: env PWD=/foo %clang -### -g %s -c 2>&1 | FileCheck -check-prefix=CHECK-FOO %s -// CHECK-FOO: {{"-fdebug-compilation-dir" ".*foo"}} - // "PWD=/foo gcc" wouldn't necessarily work. You would need to pick a different // path to the same directory (try a symlink). diff --git a/clang/test/Driver/debug.c b/clang/test/Driver/debug.c index ca1ca30ae6b..daf895c18ac 100644 --- a/clang/test/Driver/debug.c +++ b/clang/test/Driver/debug.c @@ -1,9 +1,6 @@ // RUN: cd %S && %clang -### -g %s -c 2>&1 | FileCheck -check-prefix=CHECK-PWD %s // CHECK-PWD: {{"-fdebug-compilation-dir" ".*Driver.*"}} -// RUN: env PWD=/foo %clang -### -g %s -c 2>&1 | FileCheck -check-prefix=CHECK-FOO %s -// CHECK-FOO: {{"-fdebug-compilation-dir" ".*foo"}} - // "PWD=/foo gcc" wouldn't necessarily work. You would need to pick a different // path to the same directory (try a symlink). |

