1+ diff --git a/clang/include/clang/Frontend/CompilerInstance.h b/clang/include/clang/Frontend/CompilerInstance.h
2+ index f56da69a05caf..f5dfc36953308 100644
3+ --- a/clang/include/clang/Frontend/CompilerInstance.h
4+ +++ b/clang/include/clang/Frontend/CompilerInstance.h
5+ @@ -246,6 +246,11 @@ class CompilerInstance : public ModuleLoader {
6+ /// Load the list of plugins requested in the \c FrontendOptions.
7+ void LoadRequestedPlugins();
8+
9+ + /// Parse and apply LLVM command line arguments from FrontendOptions.
10+ + /// This processes the LLVMArgs option that comes from -mllvm flags.
11+ + /// This should be called after plugins are loaded and before ExecuteAction.
12+ + void parseLLVMArgs();
13+ +
14+ /// @}
15+ /// @name Compiler Invocation and Options
16+ /// @{
17+ diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
18+ index 2cd7888b0d192..a1ea9486ac406 100644
19+ --- a/clang/lib/Frontend/CompilerInstance.cpp
20+ +++ b/clang/lib/Frontend/CompilerInstance.cpp
21+ @@ -1102,6 +1102,20 @@ void CompilerInstance::LoadRequestedPlugins() {
22+ }
23+ }
24+
25+ + void CompilerInstance::parseLLVMArgs() {
26+ + if (!getFrontendOpts().LLVMArgs.empty()) {
27+ + unsigned NumArgs = getFrontendOpts().LLVMArgs.size();
28+ + auto Args = std::make_unique<const char *[]>(NumArgs + 2);
29+ + Args[0] = "clang (LLVM option parsing)";
30+ + for (unsigned i = 0; i != NumArgs; ++i)
31+ + Args[i + 1] = getFrontendOpts().LLVMArgs[i].c_str();
32+ + Args[NumArgs + 1] = nullptr;
33+ + llvm::cl::ParseCommandLineOptions(NumArgs + 1, Args.get(), /*Overview=*/"",
34+ + /*Errs=*/nullptr,
35+ + /*VFS=*/&getVirtualFileSystem());
36+ + }
37+ + }
38+ +
39+ /// Determine the appropriate source input kind based on language
40+ /// options.
41+ static Language getLanguageFromOptions(const LangOptions &LangOpts) {
42+ diff --git a/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp b/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
43+ index 05f646b43e3c4..9fa6fbb0017e1 100644
44+ --- a/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
45+ +++ b/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
46+ @@ -237,17 +237,7 @@ bool ExecuteCompilerInvocation(CompilerInstance *Clang) {
47+ //
48+ // FIXME: Remove this, one day.
49+ // This should happen AFTER plugins have been loaded!
50+ - if (!Clang->getFrontendOpts().LLVMArgs.empty()) {
51+ - unsigned NumArgs = Clang->getFrontendOpts().LLVMArgs.size();
52+ - auto Args = std::make_unique<const char*[]>(NumArgs + 2);
53+ - Args[0] = "clang (LLVM option parsing)";
54+ - for (unsigned i = 0; i != NumArgs; ++i)
55+ - Args[i + 1] = Clang->getFrontendOpts().LLVMArgs[i].c_str();
56+ - Args[NumArgs + 1] = nullptr;
57+ - llvm::cl::ParseCommandLineOptions(NumArgs + 1, Args.get(), /*Overview=*/"",
58+ - /*Errs=*/nullptr,
59+ - /*VFS=*/&Clang->getVirtualFileSystem());
60+ - }
61+ + Clang->parseLLVMArgs();
62+
63+ #if CLANG_ENABLE_STATIC_ANALYZER
64+ // These should happen AFTER plugins have been loaded!
65+ diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp
66+ index 9c94cfa5ee381..bfb6c2a0505d1 100644
67+ --- a/clang/lib/Interpreter/Interpreter.cpp
68+ +++ b/clang/lib/Interpreter/Interpreter.cpp
69+ @@ -257,6 +257,9 @@ Interpreter::Interpreter(std::unique_ptr<CompilerInstance> Instance,
70+ auto LLVMCtx = std::make_unique<llvm::LLVMContext>();
71+ TSCtx = std::make_unique<llvm::orc::ThreadSafeContext>(std::move(LLVMCtx));
72+
73+ + // Honor -mllvm options
74+ + CI->parseLLVMArgs();
75+ +
76+ Act = TSCtx->withContextDo([&](llvm::LLVMContext *Ctx) {
77+ return std::make_unique<IncrementalAction>(*CI, *Ctx, ErrOut, *this,
78+ std::move(Consumer));
79+ @@ -465,6 +468,12 @@ Interpreter::Parse(llvm::StringRef Code) {
80+ return std::move(Err);
81+ }
82+
83+ + // Re-apply stored -mllvm options; wasm builds reset LLVM opts in wasm-ld.
84+ + llvm::Triple Triple(getCompilerInstance()->getTargetOpts().Triple);
85+ + if (Triple.isWasm()) {
86+ + getCompilerInstance()->parseLLVMArgs();
87+ + }
88+ +
89+ // Tell the interpreter sliently ignore unused expressions since value
90+ // printing could cause it.
91+ getCompilerInstance()->getDiagnostics().setSeverity(
0 commit comments