[𝘀𝗽𝗿] changes introduced through rebase

Created using spr 1.3.6

[skip ci]
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index 7a69b5d..b6007f5 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -643,16 +643,7 @@
 }
 
 StringRef CGDebugInfo::getCurrentDirname() {
-  if (!CGM.getCodeGenOpts().DebugCompilationDir.empty())
-    return CGM.getCodeGenOpts().DebugCompilationDir;
-
-  if (!CWDName.empty())
-    return CWDName;
-  llvm::ErrorOr<std::string> CWD =
-      CGM.getFileSystem()->getCurrentWorkingDirectory();
-  if (!CWD)
-    return StringRef();
-  return CWDName = internString(*CWD);
+  return CGM.getCodeGenOpts().DebugCompilationDir;
 }
 
 void CGDebugInfo::CreateCompileUnit() {
@@ -3248,6 +3239,9 @@
     std::string Remapped = remapDIPath(Path);
     StringRef Relative(Remapped);
     StringRef CompDir = TheCU->getDirectory();
+    if (CompDir.empty())
+      return Remapped;
+
     if (Relative.consume_front(CompDir))
       Relative.consume_front(llvm::sys::path::get_separator());
 
diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h
index 411b2e7..497d3a6 100644
--- a/clang/lib/CodeGen/CGDebugInfo.h
+++ b/clang/lib/CodeGen/CGDebugInfo.h
@@ -158,7 +158,6 @@
   /// This is a storage for names that are constructed on demand. For
   /// example, C++ destructors, C++ operators etc..
   llvm::BumpPtrAllocator DebugInfoNames;
-  StringRef CWDName;
 
   llvm::DenseMap<const char *, llvm::TrackingMDRef> DIFileCache;
   llvm::DenseMap<const FunctionDecl *, llvm::TrackingMDRef> SPCache;
diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 4aafac3..38aaceb 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -2449,12 +2449,7 @@
     : CGM(CGM), SourceInfo(SourceInfo) {}
 
 std::string CoverageMappingModuleGen::getCurrentDirname() {
-  if (!CGM.getCodeGenOpts().CoverageCompilationDir.empty())
-    return CGM.getCodeGenOpts().CoverageCompilationDir;
-
-  SmallString<256> CWD;
-  llvm::sys::fs::current_path(CWD);
-  return CWD.str().str();
+  return CGM.getCodeGenOpts().CoverageCompilationDir;
 }
 
 std::string CoverageMappingModuleGen::normalizeFilename(StringRef Filename) {
diff --git a/clang/test/CodeGen/debug-info-abspath.c b/clang/test/CodeGen/debug-info-abspath.c
index b2047a7..193a72c 100644
--- a/clang/test/CodeGen/debug-info-abspath.c
+++ b/clang/test/CodeGen/debug-info-abspath.c
@@ -2,20 +2,15 @@
 // RUN: cp %s %t/UNIQUEISH_SENTINEL/debug-info-abspath.c
 
 // RUN: %clang_cc1 -debug-info-kind=limited -triple %itanium_abi_triple \
+// RUN:   -fdebug-compilation-dir=%t/UNIQUEISH_SENTINEL/debug-info-abspath.c \
 // RUN:   %t/UNIQUEISH_SENTINEL/debug-info-abspath.c -emit-llvm -o - \
 // RUN:   | FileCheck %s
 
 // RUN: cp %s %t.c
 // RUN: %clang_cc1 -debug-info-kind=limited -triple %itanium_abi_triple \
+// RUN:   -fdebug-compilation-dir=%t \
 // RUN:   %t.c -emit-llvm -o - | FileCheck %s --check-prefix=INTREE
 
-// RUN: cd %t/UNIQUEISH_SENTINEL
-// RUN: %clang_cc1 -debug-info-kind=limited -triple %itanium_abi_triple \
-// RUN:   debug-info-abspath.c -emit-llvm -o - \
-// RUN:   | FileCheck %s --check-prefix=CURDIR
-// RUN: %clang_cc1 -debug-info-kind=limited -triple %itanium_abi_triple \
-// RUN:   %s -emit-llvm -o - | FileCheck %s --check-prefix=CURDIR
-
 void foo(void) {}
 
 // Since %s is an absolute path, directory should be the common
@@ -28,7 +23,3 @@
 
 // INTREE: = distinct !DISubprogram({{.*}}![[SPFILE:[0-9]+]]
 // INTREE: DIFile({{.*}}directory: "{{.+}}CodeGen{{.*}}")
-
-// CURDIR: = distinct !DICompileUnit({{.*}}file: ![[CUFILE:[0-9]+]]
-// CURDIR: ![[CUFILE]] = !DIFile({{.*}}directory: "{{.+}}UNIQUEISH_SENTINEL")
-
diff --git a/clang/test/CodeGen/debug-info-compilation-dir.c b/clang/test/CodeGen/debug-info-compilation-dir.c
index b49a0f5..5f5542c 100644
--- a/clang/test/CodeGen/debug-info-compilation-dir.c
+++ b/clang/test/CodeGen/debug-info-compilation-dir.c
@@ -7,3 +7,10 @@
 // RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited %s -o - | FileCheck -check-prefix=CHECK-DIR %s
 // CHECK-DIR: CodeGen
 
+/// Test path remapping.
+// RUN: %clang_cc1 -fdebug-compilation-dir=%S -main-file-name %s -emit-llvm -debug-info-kind=limited %s -o - | FileCheck -check-prefix=CHECK-ABS %s
+// CHECK-ABS: DIFile(filename: "{{.*}}debug-info-compilation-dir.c", directory: "{{.*}}CodeGen")
+
+// RUN: %clang_cc1 -main-file-name %s -emit-llvm -debug-info-kind=limited %s -o - | FileCheck -check-prefix=CHECK-NOMAP %s
+// CHECK-NOMAP: DIFile(filename: "{{.*}}debug-info-compilation-dir.c", directory: "")
+
diff --git a/clang/test/CodeGen/debug-prefix-map.c b/clang/test/CodeGen/debug-prefix-map.c
index e242180..e58909f 100644
--- a/clang/test/CodeGen/debug-prefix-map.c
+++ b/clang/test/CodeGen/debug-prefix-map.c
@@ -12,6 +12,7 @@
 // RUN: rm -rf %t && mkdir -p %t/a/b && cp %s %t/a/b/c.c
 // RUN: %clang_cc1 -emit-llvm -debug-info-kind=standalone -I%S -fdebug-prefix-map=%t/a/b=y -fdebug-prefix-map=%t/a=x %t/a/b/c.c -o - | FileCheck %s --check-prefix=CHECK-X
 // RUN: %clang_cc1 -emit-llvm -debug-info-kind=standalone -I%S -fdebug-prefix-map=%t/a=x -fdebug-prefix-map=%t/a/b=y %t/a/b/c.c -o - | FileCheck %s --check-prefix=CHECK-Y
+// RUN: %clang_cc1 -emit-llvm -debug-info-kind=standalone -I%S -main-file-name %t/a/b/c.c -fdebug-compilation-dir=%t/a -fdebug-prefix-map=%t/a=x -fdebug-prefix-map=%t/a/b=y %t/a/b/c.c -o - | FileCheck %s --check-prefix=CHECK-REMAP-Y
 
 #include "Inputs/stdio.h"
 
@@ -26,9 +27,9 @@
   vprintf("string", argp);
 }
 
-// CHECK-NO-MAIN-FILE-NAME: !DIFile(filename: "{{/|.:\\\\}}UNLIKELY_PATH{{/|\\\\}}empty{{/|\\\\}}<stdin>",
 // CHECK-NO-MAIN-FILE-NAME: !DIFile(filename: "{{/|.:\\\\}}UNLIKELY_PATH{{/|\\\\}}empty{{/|\\\\}}{{.*}}",
 // CHECK-NO-MAIN-FILE-NAME-SAME:    directory: "")
+// CHECK-NO-MAIN-FILE-NAME: !DIFile(filename: "{{/|.:\\\\}}UNLIKELY_PATH{{/|\\\\}}empty{{/|\\\\}}<stdin>",
 // CHECK-NO-MAIN-FILE-NAME: !DIFile(filename: "{{/|.:\\\\}}UNLIKELY_PATH{{/|\\\\}}empty{{/|\\\\}}Inputs{{/|\\\\}}stdio.h",
 // CHECK-NO-MAIN-FILE-NAME-SAME:    directory: "")
 // CHECK-NO-MAIN-FILE-NAME-NOT: !DIFile(filename:
@@ -54,3 +55,5 @@
 
 // CHECK-X: !DIFile(filename: "x{{/|\\\\}}b{{/|\\\\}}c.c", directory: "")
 // CHECK-Y: !DIFile(filename: "y{{/|\\\\}}c.c", directory: "")
+
+// CHECK-REMAP-Y: !DIFile(filename: "y{{/|\\\\}}c.c", directory: "x")
diff --git a/clang/test/CodeGenCXX/debug-info-function-context.cpp b/clang/test/CodeGenCXX/debug-info-function-context.cpp
index 63fdf87..29c87b6 100644
--- a/clang/test/CodeGenCXX/debug-info-function-context.cpp
+++ b/clang/test/CodeGenCXX/debug-info-function-context.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited -triple x86_64-pc-linux-gnu %s \
+// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited -triple x86_64-pc-linux-gnu %s -fdebug-compilation-dir=%S \
 // RUN:     -dwarf-version=5 -main-file-name debug-info-function-context.cpp  -o - | FileCheck %s
 
 struct C {
diff --git a/clang/test/CodeGenCXX/difile_entry.cpp b/clang/test/CodeGenCXX/difile_entry.cpp
index 8bf6dc3..5fcd56e 100644
--- a/clang/test/CodeGenCXX/difile_entry.cpp
+++ b/clang/test/CodeGenCXX/difile_entry.cpp
@@ -3,7 +3,7 @@
 /// Test that we canonicalize the DIFile.
 // RUN: rm -rf %t && mkdir %t && cd %t
 // RUN: cp %s .
-// RUN: %clang_cc1 -triple %itanium_abi_triple -main-file-name difile_entry.cpp -debug-info-kind=limited %t/difile_entry.cpp -std=c++11 -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple %itanium_abi_triple -main-file-name difile_entry.cpp -fdebug-compilation-dir=%t -debug-info-kind=limited %t/difile_entry.cpp -std=c++11 -emit-llvm -o - | FileCheck %s
 int x();
 static int i = x();
 
diff --git a/clang/test/PCH/debug-info-pch-container-path.c b/clang/test/PCH/debug-info-pch-container-path.c
index 257cbf5..19b1a28 100644
--- a/clang/test/PCH/debug-info-pch-container-path.c
+++ b/clang/test/PCH/debug-info-pch-container-path.c
@@ -9,6 +9,7 @@
 // RUN:     -triple %itanium_abi_triple                         \
 // RUN:     -fdebug-prefix-map=%t=BUILD                         \
 // RUN:     -fdebug-prefix-map=%S=SOURCE                        \
+// RUN:     -fdebug-compilation-dir=%t                          \
 // RUN:     -o %t/prefix.ll %S/debug-info-limited-struct.h      \
 // RUN:   -mllvm -debug-only=pchcontainer &>%t-container.ll
 // RUN: cat %t-container.ll | FileCheck %s
diff --git a/clang/test/PCH/debug-info-pch-path.c b/clang/test/PCH/debug-info-pch-path.c
index f94d2fa..22b367f 100644
--- a/clang/test/PCH/debug-info-pch-path.c
+++ b/clang/test/PCH/debug-info-pch-path.c
@@ -65,7 +65,8 @@
 // RUN: %clang_cc1 -debug-info-kind=standalone                  \
 // RUN:     -dwarf-ext-refs -fmodule-format=obj                 \
 // RUN:     -triple %itanium_abi_triple                         \
-// RUN:     -include-pch %t/prefix.pch %s -emit-llvm -o %t.abs.ll %s
+// RUN:     -include-pch %t/prefix.pch %s -emit-llvm            \
+// RUN:     -fdebug-compilation-dir=%t -o %t.abs.ll %s
 // RUN: cat %t.abs.ll | FileCheck %s --check-prefix=CHECK-ABS
 
 // CHECK-ABS: !DICompileUnit
diff --git a/clang/test/Profile/coverage-prefix-map.c b/clang/test/Profile/coverage-prefix-map.c
index de9e377..1cb095f 100644
--- a/clang/test/Profile/coverage-prefix-map.c
+++ b/clang/test/Profile/coverage-prefix-map.c
@@ -25,7 +25,7 @@
 // COVERAGE-PREFIX-MAP-ORDER: @__llvm_coverage_mapping = {{.*"\\02.*newpath.*root.*nested.*coverage-prefix-map\.c}}
 
 // Test that last -fcoverage-prefix-map option (-fcoverage-prefix-map=%/t/root=.) is applied.
-// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -emit-llvm -mllvm -enable-name-compression=false -main-file-name coverage-prefix-map.c %t/root/nested/coverage-prefix-map.c -fcoverage-prefix-map==newpath -fcoverage-prefix-map=%/t/root=. -o - | FileCheck --check-prefix=COVERAGE-PREFIX-MAP-REORDER %s
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -emit-llvm -mllvm -enable-name-compression=false -main-file-name coverage-prefix-map.c %t/root/nested/coverage-prefix-map.c -fcoverage-compilation-dir=%t/root -fcoverage-prefix-map==newpath -fcoverage-prefix-map=%/t/root=. -o - | FileCheck --check-prefix=COVERAGE-PREFIX-MAP-REORDER %s
 // COVERAGE-PREFIX-MAP-REORDER: @__llvm_coverage_mapping =
 // COVERAGE-PREFIX-MAP-REORDER-NOT: newpath
 // COVERAGE-PREFIX-MAP-REORDER-SAME: nested{{.*coverage-prefix-map\.c}}
diff --git a/clang/unittests/Frontend/CodeGenActionTest.cpp b/clang/unittests/Frontend/CodeGenActionTest.cpp
index 90818b7..b2792c4 100644
--- a/clang/unittests/Frontend/CodeGenActionTest.cpp
+++ b/clang/unittests/Frontend/CodeGenActionTest.cpp
@@ -76,40 +76,4 @@
   bool Success = Compiler.ExecuteAction(Action);
   EXPECT_TRUE(Success);
 }
-
-TEST(CodeGenTest, DebugInfoCWDCodeGen) {
-  // Check that debug info is accessing the current working directory from the
-  // VFS instead of calling \p llvm::sys::fs::current_path() directly.
-
-  auto Sept = llvm::sys::path::get_separator();
-  auto VFS = std::make_unique<llvm::vfs::InMemoryFileSystem>();
-  VFS->setCurrentWorkingDirectory(
-      std::string(llvm::formatv("{0}in-memory-fs-cwd", Sept)));
-  std::string TestPath =
-      std::string(llvm::formatv("{0}in-memory-fs-cwd{0}test.cpp", Sept));
-  VFS->addFile(TestPath, 0, llvm::MemoryBuffer::getMemBuffer("int x;\n"));
-
-  auto Invocation = std::make_shared<CompilerInvocation>();
-  Invocation->getFrontendOpts().Inputs.push_back(
-      FrontendInputFile("test.cpp", Language::CXX));
-  Invocation->getFrontendOpts().ProgramAction = EmitLLVM;
-  Invocation->getTargetOpts().Triple = "x86_64-unknown-linux-gnu";
-  Invocation->getCodeGenOpts().setDebugInfo(codegenoptions::FullDebugInfo);
-  CompilerInstance Compiler(std::move(Invocation));
-
-  SmallString<256> IRBuffer;
-  Compiler.setOutputStream(std::make_unique<raw_svector_ostream>(IRBuffer));
-  Compiler.createDiagnostics(*VFS);
-  Compiler.createFileManager(std::move(VFS));
-
-  EmitLLVMAction Action;
-  bool Success = Compiler.ExecuteAction(Action);
-  EXPECT_TRUE(Success);
-
-  SmallString<128> RealCWD;
-  llvm::sys::fs::current_path(RealCWD);
-  EXPECT_TRUE(!RealCWD.empty());
-  EXPECT_FALSE(IRBuffer.str().contains(RealCWD));
-  EXPECT_TRUE(IRBuffer.str().contains("in-memory-fs-cwd"));
-}
 }