Skip to content

Commit c495dfe

Browse files
committed
[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
1 parent 5508516 commit c495dfe

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

clang/include/clang/Frontend/CompilerInvocation.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,12 @@ class CompilerInvocation : public CompilerInvocationBase {
176176
/// \param Opts - The LangOptions object to set up.
177177
/// \param IK - The input language.
178178
/// \param T - The target triple.
179-
/// \param PPOpts - The PreprocessorOptions affected.
179+
/// \param Includes - The affected list of included files.
180180
/// \param LangStd - The input language standard.
181-
static void setLangDefaults(LangOptions &Opts, InputKind IK,
182-
const llvm::Triple &T, PreprocessorOptions &PPOpts,
183-
LangStandard::Kind LangStd = LangStandard::lang_unspecified);
181+
static void
182+
setLangDefaults(LangOptions &Opts, InputKind IK, const llvm::Triple &T,
183+
std::vector<std::string> &Includes,
184+
LangStandard::Kind LangStd = LangStandard::lang_unspecified);
184185

185186
/// Retrieve a module hash string that is suitable for uniquely
186187
/// identifying the conditions under which the module was built.

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,7 +1889,7 @@ static void ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args,
18891889

18901890
void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK,
18911891
const llvm::Triple &T,
1892-
PreprocessorOptions &PPOpts,
1892+
std::vector<std::string> &Includes,
18931893
LangStandard::Kind LangStd) {
18941894
// Set some properties which depend solely on the input kind; it would be nice
18951895
// to move these to the language standard, and have the driver resolve the
@@ -2000,9 +2000,9 @@ void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK,
20002000
if (Opts.IncludeDefaultHeader) {
20012001
if (Opts.DeclareOpenCLBuiltins) {
20022002
// Only include base header file for builtin types and constants.
2003-
PPOpts.Includes.push_back("opencl-c-base.h");
2003+
Includes.push_back("opencl-c-base.h");
20042004
} else {
2005-
PPOpts.Includes.push_back("opencl-c.h");
2005+
Includes.push_back("opencl-c.h");
20062006
}
20072007
}
20082008
}
@@ -2138,8 +2138,8 @@ static const StringRef GetInputKindName(InputKind IK) {
21382138
}
21392139

21402140
static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
2141-
const TargetOptions &TargetOpts,
2142-
PreprocessorOptions &PPOpts,
2141+
const llvm::Triple &T,
2142+
std::vector<std::string> &Includes,
21432143
DiagnosticsEngine &Diags) {
21442144
// FIXME: Cleanup per-file based stuff.
21452145
LangStandard::Kind LangStd = LangStandard::lang_unspecified;
@@ -2212,8 +2212,7 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
22122212

22132213
Opts.SYCLIsDevice = Opts.SYCL && Args.hasArg(options::OPT_fsycl_is_device);
22142214

2215-
llvm::Triple T(TargetOpts.Triple);
2216-
CompilerInvocation::setLangDefaults(Opts, IK, T, PPOpts, LangStd);
2215+
CompilerInvocation::setLangDefaults(Opts, IK, T, Includes, LangStd);
22172216

22182217
// -cl-strict-aliasing needs to emit diagnostic in the case where CL > 1.0.
22192218
// This option should be deprecated for CL > 1.0 because
@@ -2490,7 +2489,6 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
24902489
Diags.Report(diag::err_drv_argument_not_allowed_with)
24912490
<< A->getSpelling() << "-fdefault-calling-conv";
24922491
else {
2493-
llvm::Triple T(TargetOpts.Triple);
24942492
if (T.getArch() != llvm::Triple::x86)
24952493
Diags.Report(diag::err_drv_argument_not_allowed_with)
24962494
<< A->getSpelling() << T.getTriple();
@@ -2527,8 +2525,7 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
25272525
// Add unsupported host targets here:
25282526
case llvm::Triple::nvptx:
25292527
case llvm::Triple::nvptx64:
2530-
Diags.Report(diag::err_drv_omp_host_target_not_supported)
2531-
<< TargetOpts.Triple;
2528+
Diags.Report(diag::err_drv_omp_host_target_not_supported) << T.str();
25322529
break;
25332530
}
25342531
}
@@ -2960,8 +2957,8 @@ bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
29602957
} else {
29612958
// Other LangOpts are only initialized when the input is not AST or LLVM IR.
29622959
// FIXME: Should we really be calling this for an Language::Asm input?
2963-
ParseLangArgs(LangOpts, Args, DashX, Res.getTargetOpts(),
2964-
Res.getPreprocessorOpts(), Diags);
2960+
ParseLangArgs(LangOpts, Args, DashX, T, Res.getPreprocessorOpts().Includes,
2961+
Diags);
29652962
if (Res.getFrontendOpts().ProgramAction == frontend::RewriteObjC)
29662963
LangOpts.ObjCExceptions = 1;
29672964
if (T.isOSDarwin() && DashX.isPreprocessed()) {

0 commit comments

Comments
 (0)