summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2013-08-10 00:50:57 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2013-08-10 00:50:57 +0000
commit6ee163875c5334647d09369f361f207f6a97fc49 (patch)
tree169a25948cd6afb4adf0f7819de3a839cbe591ff /llvm
parent0ec71a0c01a85b7718aca0517ef0d985001fdde8 (diff)
downloadbcm5719-llvm-6ee163875c5334647d09369f361f207f6a97fc49.tar.gz
bcm5719-llvm-6ee163875c5334647d09369f361f207f6a97fc49.zip
Check for $PWD in llvm::sys::current_path.
Some users (clang, libTooling) require this. After this patch we can remove the calls to getenv("PWD") from clang. llvm-svn: 188125
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/Support/Unix/Path.inc12
-rw-r--r--llvm/test/MC/ELF/comp-dir.s10
2 files changed, 22 insertions, 0 deletions
diff --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc
index 4dcfa094a7b..f6a137e7a0b 100644
--- a/llvm/lib/Support/Unix/Path.inc
+++ b/llvm/lib/Support/Unix/Path.inc
@@ -298,6 +298,18 @@ UniqueID file_status::getUniqueID() const {
}
error_code current_path(SmallVectorImpl<char> &result) {
+ result.clear();
+
+ const char *pwd = ::getenv("PWD");
+ llvm::sys::fs::file_status PWDStatus, DotStatus;
+ if (pwd && llvm::sys::path::is_absolute(pwd) &&
+ !llvm::sys::fs::status(pwd, PWDStatus) &&
+ !llvm::sys::fs::status(".", DotStatus) &&
+ PWDStatus.getUniqueID() == DotStatus.getUniqueID()) {
+ result.append(pwd, pwd + strlen(pwd));
+ return error_code::success();
+ }
+
#ifdef MAXPATHLEN
result.reserve(MAXPATHLEN);
#else
diff --git a/llvm/test/MC/ELF/comp-dir.s b/llvm/test/MC/ELF/comp-dir.s
index 59e3d7ded26..1b91f64a502 100644
--- a/llvm/test/MC/ELF/comp-dir.s
+++ b/llvm/test/MC/ELF/comp-dir.s
@@ -1,7 +1,17 @@
+// REQUIRES: shell
+// XFAIL: mingw
// RUN: llvm-mc -triple=x86_64-linux-unknown -g -fdebug-compilation-dir=/test/comp/dir %s -filetype=obj -o %t.o
// RUN: llvm-dwarfdump -debug-dump=info %t.o | FileCheck %s
// CHECK: DW_AT_comp_dir [DW_FORM_string] ("{{([A-Za-z]:.*)?}}/test/comp/dir")
+// RUN: mkdir -p %t.foo
+// RUN: ln -sf %t.foo %t.bar
+// RUN: cd %t.foo
+// RUN: env PWD=%t.bar llvm-mc -triple=x86_64-linux-unknown -g %s -filetype=obj -o %t.o
+// RUN: llvm-dwarfdump -debug-dump=info %t.o | FileCheck --check-prefix=PWD %s
+// PWD: DW_AT_comp_dir [DW_FORM_string] ("{{.*}}.bar")
+
+
f:
nop
OpenPOWER on IntegriCloud