-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[clang-repl] Handle frontend options for clang-repl before calling executeAction #132670
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
base: main
Are you sure you want to change the base?
[clang-repl] Handle frontend options for clang-repl before calling executeAction #132670
Conversation
@llvm/pr-subscribers-clang Author: Anutosh Bhat (anutosh491) Changes
It goes from Creating the Compiler Instance -> Addressing these llvmargs -> calling executeAction
So ExecuteAction is framed like this
And clang-repl would need to handle these before getting to executeAction. Otherwise
Full diff: https://github.com/llvm/llvm-project/pull/132670.diff 1 Files Affected:
diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp
index fa4c1439c9261..5f48117dbf3b8 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -141,6 +141,37 @@ CreateCI(const llvm::opt::ArgStringList &Argv) {
return std::move(Clang);
}
+static llvm::Error HandleFrontendOptions(const CompilerInstance &CI) {
+ const auto &FrontendOpts = CI.getFrontendOpts();
+
+ if (FrontendOpts.ShowHelp) {
+ driver::getDriverOptTable().printHelp(
+ llvm::outs(), "clang -cc1 [options] file...",
+ "LLVM 'Clang' Compiler: http://clang.llvm.org",
+ /*ShowHidden=*/false, /*ShowAllAliases=*/false,
+ llvm::opt::Visibility(driver::options::CC1Option));
+ return llvm::createStringError(llvm::errc::not_supported, "Help displayed");
+ }
+
+ if (FrontendOpts.ShowVersion) {
+ llvm::cl::PrintVersionMessage();
+ return llvm::createStringError(llvm::errc::not_supported, "Version displayed");
+ }
+
+ if (!FrontendOpts.LLVMArgs.empty()) {
+ unsigned NumArgs = FrontendOpts.LLVMArgs.size();
+ auto Args = std::make_unique<const char*[]>(NumArgs + 2);
+ Args[0] = "clang-repl (LLVM option parsing)";
+ for (unsigned i = 0; i != NumArgs; ++i)
+ Args[i + 1] = FrontendOpts.LLVMArgs[i].c_str();
+ Args[NumArgs + 1] = nullptr;
+ llvm::errs() << "Parsing LLVM backend options via cl::ParseCommandLineOptions...\n";
+ llvm::cl::ParseCommandLineOptions(NumArgs + 1, Args.get());
+ }
+
+ return llvm::Error::success();
+}
+
} // anonymous namespace
namespace clang {
@@ -451,7 +482,12 @@ const char *const Runtimes = R"(
llvm::Expected<std::unique_ptr<Interpreter>>
Interpreter::create(std::unique_ptr<CompilerInstance> CI) {
- llvm::Error Err = llvm::Error::success();
+
+ llvm::Error Err = HandleFrontendOptions(*CI);
+ if (Err) {
+ return std::move(Err);
+ }
+
auto Interp =
std::unique_ptr<Interpreter>(new Interpreter(std::move(CI), Err));
if (Err)
|
After handling these args we should see
rather than the abort. |
✅ With the latest revision this PR passed the C/C++ code formatter. |
I see clang handle 4 types of FrontendOpts before calling ExecuteAction
We might be interesting in 1, 2 and 4 for clang-repl |
Hey @anutosh491 can you add some testing? |
Sorry for missing your last reply completely. Thanks for going through it in the first place :) I've added a small test to get us started We would get the following as a whole
But I am just checking the presence of the string "Version displayed" cause the version number and the output through help is subject to change in the future. |
Hey @serge-sans-paille , Gentle ping. This should be ready from my side. Would be great if you could review it anytime soon. |
It goes from Creating the Compiler Instance -> Addressing these llvmargs -> calling executeAction
So ExecuteAction is framed like this
And clang-repl would need to handle these before getting to executeAction.
Otherwise