aboutsummaryrefslogtreecommitdiff
path: root/lib/Driver/Tools.cpp
diff options
context:
space:
mode:
authorChad Rosier <mcrosier@apple.com>2013-04-26 20:49:50 +0000
committerChad Rosier <mcrosier@apple.com>2013-04-26 20:49:50 +0000
commitb1c8122b43058fc0c049a9c6fc8aaef044005798 (patch)
treeb474ad0ef41232ecc5cebe95a95f6990cd00c42a /lib/Driver/Tools.cpp
parent84bf8a8c705ba6b4f86c58a49e72afa7b38c2b05 (diff)
[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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@180628 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Driver/Tools.cpp')
-rw-r--r--lib/Driver/Tools.cpp29
1 files changed, 21 insertions, 8 deletions
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index 2ea4932a84..dec2ba5cec 100644
--- a/lib/Driver/Tools.cpp
+++ b/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));
}
}