diff --git a/llvm/test/tools/llvm-ar/print-thin-archive-path.test b/llvm/test/tools/llvm-ar/print-thin-archive-path.test new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-ar/print-thin-archive-path.test @@ -0,0 +1,10 @@ +RUN: mkdir -p %t/foo +RUN: touch %t/foo/a.txt +RUN: rm -f %t/foo/archive.a + +RUN: cd %t && llvm-ar rcST foo/archive.a foo/a.txt +RUN: cd %t && llvm-ar t foo/archive.a | FileCheck %s --match-full-lines --check-prefix=PARENT-DIR +RUN: cd %t/foo && llvm-ar t archive.a | FileCheck %s --match-full-lines --check-prefix=CHILD-DIR + +PARENT-DIR: foo/a.txt +CHILD-DIR: a.txt \ No newline at end of file diff --git a/llvm/tools/llvm-ar/llvm-ar.cpp b/llvm/tools/llvm-ar/llvm-ar.cpp --- a/llvm/tools/llvm-ar/llvm-ar.cpp +++ b/llvm/tools/llvm-ar/llvm-ar.cpp @@ -429,8 +429,9 @@ } if (C.getParent()->isThin()) { - outs() << sys::path::parent_path(ArchiveName); - outs() << '/'; + StringRef ParentDir = sys::path::parent_path(ArchiveName); + if (!ParentDir.empty()) + outs() << ParentDir << '/'; } outs() << Name << "\n"; }