aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <kyrtzidis@apple.com>2022-07-23 00:11:44 -0700
committerArgyrios Kyrtzidis <kyrtzidis@apple.com>2022-07-26 13:48:39 -0700
commit8dfaecc4c24494337933aff9d9166486ca0949f1 (patch)
tree49d5a2db87bc471fdd6c2831e5cfd686287b815a /clang/unittests
parent0734c02b34e49568d278dce7ca4b818fc465853d (diff)
downloadllvm-8dfaecc4c24494337933aff9d9166486ca0949f1.zip
llvm-8dfaecc4c24494337933aff9d9166486ca0949f1.tar.gz
llvm-8dfaecc4c24494337933aff9d9166486ca0949f1.tar.bz2
[CGDebugInfo] Access the current working directory from the `VFS`
...instead of calling `llvm::sys::fs::current_path()` directly. Differential Revision: https://reviews.llvm.org/D130443
Diffstat (limited to 'clang/unittests')
-rw-r--r--clang/unittests/CodeGen/TestCompiler.h10
-rw-r--r--clang/unittests/Frontend/CodeGenActionTest.cpp37
2 files changed, 41 insertions, 6 deletions
diff --git a/clang/unittests/CodeGen/TestCompiler.h b/clang/unittests/CodeGen/TestCompiler.h
index c2fd8ac..d308cdc 100644
--- a/clang/unittests/CodeGen/TestCompiler.h
+++ b/clang/unittests/CodeGen/TestCompiler.h
@@ -56,12 +56,10 @@ struct TestCompiler {
compiler.createASTContext();
- CG.reset(CreateLLVMCodeGen(compiler.getDiagnostics(),
- "main-module",
- compiler.getHeaderSearchOpts(),
- compiler.getPreprocessorOpts(),
- compiler.getCodeGenOpts(),
- Context));
+ CG.reset(CreateLLVMCodeGen(
+ compiler.getDiagnostics(), "main-module",
+ &compiler.getVirtualFileSystem(), compiler.getHeaderSearchOpts(),
+ compiler.getPreprocessorOpts(), compiler.getCodeGenOpts(), Context));
}
void init(const char *TestProgram,
diff --git a/clang/unittests/Frontend/CodeGenActionTest.cpp b/clang/unittests/Frontend/CodeGenActionTest.cpp
index f932be6..d50648c 100644
--- a/clang/unittests/Frontend/CodeGenActionTest.cpp
+++ b/clang/unittests/Frontend/CodeGenActionTest.cpp
@@ -15,6 +15,7 @@
#include "clang/CodeGen/BackendUtil.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Lex/PreprocessorOptions.h"
+#include "llvm/Support/FormatVariadic.h"
#include "gtest/gtest.h"
using namespace llvm;
@@ -76,4 +77,40 @@ TEST(CodeGenTest, CodeGenFromIRMemBuffer) {
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 VFS = std::make_unique<llvm::vfs::InMemoryFileSystem>();
+ VFS->setCurrentWorkingDirectory("/in-memory-fs-cwd");
+ auto Sept = llvm::sys::path::get_separator();
+ 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;
+
+ SmallString<256> IRBuffer;
+ Compiler.setOutputStream(std::make_unique<raw_svector_ostream>(IRBuffer));
+ Compiler.setInvocation(std::move(Invocation));
+ Compiler.createDiagnostics();
+ 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"));
+}
}