Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions clang/lib/Tooling/Tooling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,9 +510,11 @@ static void injectResourceDir(CommandLineArguments &Args, const char *Argv0,
return;

// If there's no override in place add our resource dir.
Args = getInsertArgumentAdjuster(
("-resource-dir=" + CompilerInvocation::GetResourcesPath(Argv0, MainAddr))
.c_str())(Args, "");
CommandLineArguments Extra = {
"-resource-dir", CompilerInvocation::GetResourcesPath(Argv0, MainAddr)};

Args =
getInsertArgumentAdjuster(Extra, ArgumentInsertPosition::END)(Args, "");
}

int ClangTool::run(ToolAction *Action) {
Expand Down
19 changes: 19 additions & 0 deletions clang/unittests/Tooling/ToolingTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,25 @@ TEST(ClangToolTest, BaseVirtualFileSystemUsage) {
EXPECT_EQ(0, Tool.run(Action.get()));
}

// Check -cc1 command doesn't fail.
TEST(ClangToolTest, CC1Arg) {
FixedCompilationDatabase Compilations("/", {"-cc1"});
llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFileSystem(
new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem()));
llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem(
new llvm::vfs::InMemoryFileSystem);
OverlayFileSystem->pushOverlay(InMemoryFileSystem);

InMemoryFileSystem->addFile(
"a.cpp", 0, llvm::MemoryBuffer::getMemBuffer("int main() {}"));

ClangTool Tool(Compilations, std::vector<std::string>(1, "a.cpp"),
std::make_shared<PCHContainerOperations>(), OverlayFileSystem);
std::unique_ptr<FrontendActionFactory> Action(
newFrontendActionFactory<SyntaxOnlyAction>());
EXPECT_EQ(0, Tool.run(Action.get()));
}

// Check getClangStripDependencyFileAdjuster doesn't strip args after -MD/-MMD.
TEST(ClangToolTest, StripDependencyFileAdjuster) {
FixedCompilationDatabase Compilations("/", {"-MD", "-c", "-MMD", "-w"});
Expand Down