[PATCH] Unify handling of PWD (llvm patch)

Rafael Ávila de Espíndola rafael.espindola at gmail.com
Fri Aug 9 15:55:39 PDT 2013


  add testcase

Hi klimek, nicholas,

http://llvm-reviews.chandlerc.com/D1335

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D1335?vs=3305&id=3334#toc

Files:
  lib/Support/Unix/Path.inc
  test/MC/ELF/comp-dir.s

Index: lib/Support/Unix/Path.inc
===================================================================
--- lib/Support/Unix/Path.inc
+++ lib/Support/Unix/Path.inc
@@ -298,6 +298,18 @@
 }
 
 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
Index: test/MC/ELF/comp-dir.s
===================================================================
--- test/MC/ELF/comp-dir.s
+++ test/MC/ELF/comp-dir.s
@@ -1,7 +1,16 @@
+// REQUIRES: shell
 // 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1335.2.patch
Type: text/x-patch
Size: 1470 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130809/ff0e72a6/attachment.bin>


More information about the llvm-commits mailing list