[clang] c495dfe - [clang][cli] NFC: Decrease the scope of ParseLangArgs parameters
Jan Svoboda via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 15 00:02:59 PST 2021
Author: Jan Svoboda
Date: 2021-01-15T08:41:50+01:00
New Revision: c495dfe0268bc2be8737725d657411baa1399e9d
URL: https://github.com/llvm/llvm-project/commit/c495dfe0268bc2be8737725d657411baa1399e9d
DIFF: https://github.com/llvm/llvm-project/commit/c495dfe0268bc2be8737725d657411baa1399e9d.diff
LOG: [clang][cli] NFC: Decrease the scope of ParseLangArgs parameters
Instead of passing the whole `TargetOptions` and `PreprocessorOptions` to `ParseLangArgs` give it only the necessary members.
This makes tracking the dependencies between various parsers and option groups easier.
Reviewed By: Bigcheese
Differential Revision: https://reviews.llvm.org/D94674
Added:
Modified:
clang/include/clang/Frontend/CompilerInvocation.h
clang/lib/Frontend/CompilerInvocation.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Frontend/CompilerInvocation.h b/clang/include/clang/Frontend/CompilerInvocation.h
index c723fc084c85..9f16c5077154 100644
--- a/clang/include/clang/Frontend/CompilerInvocation.h
+++ b/clang/include/clang/Frontend/CompilerInvocation.h
@@ -176,11 +176,12 @@ class CompilerInvocation : public CompilerInvocationBase {
/// \param Opts - The LangOptions object to set up.
/// \param IK - The input language.
/// \param T - The target triple.
- /// \param PPOpts - The PreprocessorOptions affected.
+ /// \param Includes - The affected list of included files.
/// \param LangStd - The input language standard.
- static void setLangDefaults(LangOptions &Opts, InputKind IK,
- const llvm::Triple &T, PreprocessorOptions &PPOpts,
- LangStandard::Kind LangStd = LangStandard::lang_unspecified);
+ static void
+ setLangDefaults(LangOptions &Opts, InputKind IK, const llvm::Triple &T,
+ std::vector<std::string> &Includes,
+ LangStandard::Kind LangStd = LangStandard::lang_unspecified);
/// Retrieve a module hash string that is suitable for uniquely
/// identifying the conditions under which the module was built.
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 6327723699d2..d80d1f79c692 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1889,7 +1889,7 @@ static void ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args,
void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK,
const llvm::Triple &T,
- PreprocessorOptions &PPOpts,
+ std::vector<std::string> &Includes,
LangStandard::Kind LangStd) {
// Set some properties which depend solely on the input kind; it would be nice
// to move these to the language standard, and have the driver resolve the
@@ -2000,9 +2000,9 @@ void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK,
if (Opts.IncludeDefaultHeader) {
if (Opts.DeclareOpenCLBuiltins) {
// Only include base header file for builtin types and constants.
- PPOpts.Includes.push_back("opencl-c-base.h");
+ Includes.push_back("opencl-c-base.h");
} else {
- PPOpts.Includes.push_back("opencl-c.h");
+ Includes.push_back("opencl-c.h");
}
}
}
@@ -2138,8 +2138,8 @@ static const StringRef GetInputKindName(InputKind IK) {
}
static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
- const TargetOptions &TargetOpts,
- PreprocessorOptions &PPOpts,
+ const llvm::Triple &T,
+ std::vector<std::string> &Includes,
DiagnosticsEngine &Diags) {
// FIXME: Cleanup per-file based stuff.
LangStandard::Kind LangStd = LangStandard::lang_unspecified;
@@ -2212,8 +2212,7 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
Opts.SYCLIsDevice = Opts.SYCL && Args.hasArg(options::OPT_fsycl_is_device);
- llvm::Triple T(TargetOpts.Triple);
- CompilerInvocation::setLangDefaults(Opts, IK, T, PPOpts, LangStd);
+ CompilerInvocation::setLangDefaults(Opts, IK, T, Includes, LangStd);
// -cl-strict-aliasing needs to emit diagnostic in the case where CL > 1.0.
// This option should be deprecated for CL > 1.0 because
@@ -2490,7 +2489,6 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
Diags.Report(diag::err_drv_argument_not_allowed_with)
<< A->getSpelling() << "-fdefault-calling-conv";
else {
- llvm::Triple T(TargetOpts.Triple);
if (T.getArch() != llvm::Triple::x86)
Diags.Report(diag::err_drv_argument_not_allowed_with)
<< A->getSpelling() << T.getTriple();
@@ -2527,8 +2525,7 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
// Add unsupported host targets here:
case llvm::Triple::nvptx:
case llvm::Triple::nvptx64:
- Diags.Report(diag::err_drv_omp_host_target_not_supported)
- << TargetOpts.Triple;
+ Diags.Report(diag::err_drv_omp_host_target_not_supported) << T.str();
break;
}
}
@@ -2960,8 +2957,8 @@ bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
} else {
// Other LangOpts are only initialized when the input is not AST or LLVM IR.
// FIXME: Should we really be calling this for an Language::Asm input?
- ParseLangArgs(LangOpts, Args, DashX, Res.getTargetOpts(),
- Res.getPreprocessorOpts(), Diags);
+ ParseLangArgs(LangOpts, Args, DashX, T, Res.getPreprocessorOpts().Includes,
+ Diags);
if (Res.getFrontendOpts().ProgramAction == frontend::RewriteObjC)
LangOpts.ObjCExceptions = 1;
if (T.isOSDarwin() && DashX.isPreprocessed()) {
More information about the cfe-commits
mailing list