-
Notifications
You must be signed in to change notification settings - Fork 14k
[Clang] Add resource_dir_EQ flag to CC1Option group #140870
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Clang] Add resource_dir_EQ flag to CC1Option group #140870
Conversation
This PR fixes ClangTool error in -cc1 mode: error: unknown argument: '-resource-dir=
@llvm/pr-subscribers-clang Author: Wenju He (wenju-he) ChangesThis PR fixes ClangTool error in -cc1 mode: Full diff: https://github.com/llvm/llvm-project/pull/140870.diff 2 Files Affected:
diff --git a/clang/lib/Tooling/Tooling.cpp b/clang/lib/Tooling/Tooling.cpp
index 3c72f52040142..87a984672662b 100644
--- a/clang/lib/Tooling/Tooling.cpp
+++ b/clang/lib/Tooling/Tooling.cpp
@@ -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) {
diff --git a/clang/unittests/Tooling/ToolingTest.cpp b/clang/unittests/Tooling/ToolingTest.cpp
index 8cdfffb54390e..07104ccf9835f 100644
--- a/clang/unittests/Tooling/ToolingTest.cpp
+++ b/clang/unittests/Tooling/ToolingTest.cpp
@@ -771,6 +771,25 @@ TEST(ClangToolTest, BaseVirtualFileSystemUsage) {
EXPECT_EQ(0, Tool.run(Action.get()));
}
+// Check -cc1 command doesn't crash.
+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"});
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we know why https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Driver/Options.td#L5894-L5901 doesn't declare _EQ version for cc1?
i think instead of working around this in various places, we should unify the two if possible.
Git history shows the earliest commit f3e624c already have the difference. I don't see obvious reason why resource_dir_EQ should not be cc1 option.
done, thanks for the suggestion. |
LGTM, but cc @llvm/clang-area-team, in case they have any concerns here |
I bisected a crash that I see when running
|
thanks @nathanchance for the bisecting. |
This PR fixes ClangTool error in -cc1 mode in function injectResourceDir: error: unknown argument: '-resource-dir=
#142509) This reverts commit c7b8d6e. Fix check-clang CodeGenTest.TestNonAlterTest regression, see #140870 (comment)
…p (#140870)" (#142509) This reverts commit c7b8d6e. Fix check-clang CodeGenTest.TestNonAlterTest regression, see llvm/llvm-project#140870 (comment)
)" (llvm#142509) This reverts commit c7b8d6e. Fix check-clang CodeGenTest.TestNonAlterTest regression, see llvm#140870 (comment)
)" (llvm#142509) This reverts commit c7b8d6e. Fix check-clang CodeGenTest.TestNonAlterTest regression, see llvm#140870 (comment)
)" (llvm#142509) This reverts commit c7b8d6e. Fix check-clang CodeGenTest.TestNonAlterTest regression, see llvm#140870 (comment)
This PR fixes ClangTool error in -cc1 mode in function injectResourceDir:
error: unknown argument: '-resource-dir=