[clang] 521e173 - [clang][cli] Store InputKind in FrontendOptions
Jan Svoboda via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 9 06:19:34 PST 2021
Author: Jan Svoboda
Date: 2021-02-09T15:19:26+01:00
New Revision: 521e1733f1496f6d554e6ce8b69cd4251499b15e
URL: https://github.com/llvm/llvm-project/commit/521e1733f1496f6d554e6ce8b69cd4251499b15e
DIFF: https://github.com/llvm/llvm-project/commit/521e1733f1496f6d554e6ce8b69cd4251499b15e.diff
LOG: [clang][cli] Store InputKind in FrontendOptions
This patch stores the `InputKind` (parsed mainly from `-x`) to `FrontendOptions`. This is necessary for command line generation.
Reviewed By: dexonsmith
Differential Revision: https://reviews.llvm.org/D96149
Added:
Modified:
clang/include/clang/Frontend/FrontendOptions.h
clang/lib/Frontend/CompilerInvocation.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Frontend/FrontendOptions.h b/clang/include/clang/Frontend/FrontendOptions.h
index 223c1e05d053..5c9a21813b62 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -374,6 +374,10 @@ class FrontendOptions {
std::string MTMigrateDir;
std::string ARCMTMigrateReportOut;
+ /// The input kind, either specified via -x argument or deduced from the input
+ /// file name.
+ InputKind DashX;
+
/// The input files and their types.
SmallVector<FrontendInputFile, 0> Inputs;
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 020cbf0f176e..3df6b37917aa 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2153,9 +2153,10 @@ static bool parseTestModuleFileExtensionArg(StringRef Arg,
return false;
}
-static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
- DiagnosticsEngine &Diags,
- bool &IsHeaderFile) {
+static bool ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
+ DiagnosticsEngine &Diags, bool &IsHeaderFile) {
+ unsigned NumErrorsBefore = Diags.getNumErrors();
+
Opts.ProgramAction = frontend::ParseSyntaxOnly;
if (const Arg *A = Args.getLastArg(OPT_Action_Group)) {
switch (A->getOption().getID()) {
@@ -2424,7 +2425,9 @@ static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
Opts.Inputs.emplace_back(std::move(Inputs[i]), IK, IsSystem);
}
- return DashX;
+ Opts.DashX = DashX;
+
+ return Diags.getNumErrors() == NumErrorsBefore;
}
std::string CompilerInvocation::GetResourcesPath(const char *Argv0,
@@ -3968,9 +3971,10 @@ bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
}
Success &= ParseDiagnosticArgs(Res.getDiagnosticOpts(), Args, &Diags,
/*DefaultDiagColor=*/false);
+ Success &= ParseFrontendArgs(Res.getFrontendOpts(), Args, Diags,
+ LangOpts.IsHeaderFile);
// FIXME: We shouldn't have to pass the DashX option around here
- InputKind DashX = ParseFrontendArgs(Res.getFrontendOpts(), Args, Diags,
- LangOpts.IsHeaderFile);
+ InputKind DashX = Res.getFrontendOpts().DashX;
ParseTargetArgs(Res.getTargetOpts(), Args, Diags);
llvm::Triple T(Res.getTargetOpts().Triple);
ParseHeaderSearchArgs(Res, Res.getHeaderSearchOpts(), Args, Diags,
More information about the cfe-commits
mailing list