@@ -120,16 +120,16 @@ std::string Driver::GetResourcesPath(StringRef BinaryPath,
120
120
Driver::Driver (StringRef ClangExecutable, StringRef TargetTriple,
121
121
DiagnosticsEngine &Diags,
122
122
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS)
123
- : Opts(createDriverOptTable()), Diags(Diags), VFS(std::move(VFS)),
124
- Mode(GCCMode), SaveTemps(SaveTempsNone), BitcodeEmbed(EmbedNone),
125
- LTOMode(LTOK_None ), ClangExecutable(ClangExecutable ),
126
- SysRoot(DEFAULT_SYSROOT), DriverTitle(" clang LLVM compiler" ),
127
- CCPrintOptionsFilename (nullptr ), CCPrintHeadersFilename (nullptr ),
128
- CCLogDiagnosticsFilename( nullptr ), CCCPrintBindings (false ),
129
- CCPrintOptions (false ), CCPrintHeaders( false ), CCLogDiagnostics (false ),
130
- CCGenDiagnostics( false ), TargetTriple(TargetTriple ),
131
- CCCGenericGCCName( " " ), Saver(Alloc), CheckInputsExist( true ),
132
- GenReproducer( false ), SuppressMissingInputWarning(false ) {
123
+ : Diags(Diags), VFS(std::move(VFS)), Mode(GCCMode ),
124
+ SaveTemps(SaveTempsNone), BitcodeEmbed(EmbedNone), LTOMode(LTOK_None ),
125
+ ClangExecutable(ClangExecutable ), SysRoot(DEFAULT_SYSROOT ),
126
+ DriverTitle(" clang LLVM compiler" ), CCPrintOptionsFilename( nullptr ),
127
+ CCPrintHeadersFilename (nullptr ), CCLogDiagnosticsFilename (nullptr ),
128
+ CCCPrintBindings( false ), CCPrintOptions( false ), CCPrintHeaders (false ),
129
+ CCLogDiagnostics (false ), CCGenDiagnostics (false ),
130
+ TargetTriple(TargetTriple ), CCCGenericGCCName( " " ), Saver(Alloc ),
131
+ CheckInputsExist( true ), GenReproducer( false ),
132
+ SuppressMissingInputWarning(false ) {
133
133
134
134
// Provide a sane fallback if no VFS is specified.
135
135
if (!this ->VFS )
@@ -310,7 +310,7 @@ phases::ID Driver::getFinalPhase(const DerivedArgList &DAL,
310
310
return FinalPhase;
311
311
}
312
312
313
- static Arg *MakeInputArg (DerivedArgList &Args, OptTable &Opts,
313
+ static Arg *MakeInputArg (DerivedArgList &Args, const OptTable &Opts,
314
314
StringRef Value, bool Claim = true ) {
315
315
Arg *A = new Arg (Opts.getOption (options::OPT_INPUT), Value,
316
316
Args.getBaseArgs ().MakeIndex (Value), Value.data ());
@@ -321,6 +321,7 @@ static Arg *MakeInputArg(DerivedArgList &Args, OptTable &Opts,
321
321
}
322
322
323
323
DerivedArgList *Driver::TranslateInputArgs (const InputArgList &Args) const {
324
+ const llvm::opt::OptTable &Opts = getOpts ();
324
325
DerivedArgList *DAL = new DerivedArgList (Args);
325
326
326
327
bool HasNostdlib = Args.hasArg (options::OPT_nostdlib);
@@ -337,12 +338,12 @@ DerivedArgList *Driver::TranslateInputArgs(const InputArgList &Args) const {
337
338
A->getOption ().matches (options::OPT_Xlinker)) &&
338
339
A->containsValue (" --no-demangle" )) {
339
340
// Add the rewritten no-demangle argument.
340
- DAL->AddFlagArg (A, Opts-> getOption (options::OPT_Z_Xlinker__no_demangle));
341
+ DAL->AddFlagArg (A, Opts. getOption (options::OPT_Z_Xlinker__no_demangle));
341
342
342
343
// Add the remaining values as Xlinker arguments.
343
344
for (StringRef Val : A->getValues ())
344
345
if (Val != " --no-demangle" )
345
- DAL->AddSeparateArg (A, Opts-> getOption (options::OPT_Xlinker), Val);
346
+ DAL->AddSeparateArg (A, Opts. getOption (options::OPT_Xlinker), Val);
346
347
347
348
continue ;
348
349
}
@@ -355,12 +356,11 @@ DerivedArgList *Driver::TranslateInputArgs(const InputArgList &Args) const {
355
356
A->getValue (0 ) == StringRef (" -MMD" ))) {
356
357
// Rewrite to -MD/-MMD along with -MF.
357
358
if (A->getValue (0 ) == StringRef (" -MD" ))
358
- DAL->AddFlagArg (A, Opts-> getOption (options::OPT_MD));
359
+ DAL->AddFlagArg (A, Opts. getOption (options::OPT_MD));
359
360
else
360
- DAL->AddFlagArg (A, Opts-> getOption (options::OPT_MMD));
361
+ DAL->AddFlagArg (A, Opts. getOption (options::OPT_MMD));
361
362
if (A->getNumValues () == 2 )
362
- DAL->AddSeparateArg (A, Opts->getOption (options::OPT_MF),
363
- A->getValue (1 ));
363
+ DAL->AddSeparateArg (A, Opts.getOption (options::OPT_MF), A->getValue (1 ));
364
364
continue ;
365
365
}
366
366
@@ -371,13 +371,13 @@ DerivedArgList *Driver::TranslateInputArgs(const InputArgList &Args) const {
371
371
// Rewrite unless -nostdlib is present.
372
372
if (!HasNostdlib && !HasNodefaultlib && !HasNostdlibxx &&
373
373
Value == " stdc++" ) {
374
- DAL->AddFlagArg (A, Opts-> getOption (options::OPT_Z_reserved_lib_stdcxx));
374
+ DAL->AddFlagArg (A, Opts. getOption (options::OPT_Z_reserved_lib_stdcxx));
375
375
continue ;
376
376
}
377
377
378
378
// Rewrite unconditionally.
379
379
if (Value == " cc_kext" ) {
380
- DAL->AddFlagArg (A, Opts-> getOption (options::OPT_Z_reserved_lib_cckext));
380
+ DAL->AddFlagArg (A, Opts. getOption (options::OPT_Z_reserved_lib_cckext));
381
381
continue ;
382
382
}
383
383
}
@@ -386,7 +386,7 @@ DerivedArgList *Driver::TranslateInputArgs(const InputArgList &Args) const {
386
386
if (A->getOption ().matches (options::OPT__DASH_DASH)) {
387
387
A->claim ();
388
388
for (StringRef Val : A->getValues ())
389
- DAL->append (MakeInputArg (*DAL, * Opts, Val, false ));
389
+ DAL->append (MakeInputArg (*DAL, Opts, Val, false ));
390
390
continue ;
391
391
}
392
392
@@ -395,14 +395,14 @@ DerivedArgList *Driver::TranslateInputArgs(const InputArgList &Args) const {
395
395
396
396
// Enforce -static if -miamcu is present.
397
397
if (Args.hasFlag (options::OPT_miamcu, options::OPT_mno_iamcu, false ))
398
- DAL->AddFlagArg (0 , Opts-> getOption (options::OPT_static));
398
+ DAL->AddFlagArg (0 , Opts. getOption (options::OPT_static));
399
399
400
400
// Add a default value of -mlinker-version=, if one was given and the user
401
401
// didn't specify one.
402
402
#if defined(HOST_LINK_VERSION)
403
403
if (!Args.hasArg (options::OPT_mlinker_version_EQ) &&
404
404
strlen (HOST_LINK_VERSION) > 0 ) {
405
- DAL->AddJoinedArg (0 , Opts-> getOption (options::OPT_mlinker_version_EQ),
405
+ DAL->AddJoinedArg (0 , Opts. getOption (options::OPT_mlinker_version_EQ),
406
406
HOST_LINK_VERSION);
407
407
DAL->getLastArg (options::OPT_mlinker_version_EQ)->claim ();
408
408
}
@@ -1592,16 +1592,17 @@ void Driver::HandleAutocompletions(StringRef PassedFlags) const {
1592
1592
if (llvm::is_contained (Flags, " -Xclang" ) || llvm::is_contained (Flags, " -cc1" ))
1593
1593
DisableFlags &= ~options::NoDriverOption;
1594
1594
1595
+ const llvm::opt::OptTable &Opts = getOpts ();
1595
1596
StringRef Cur;
1596
1597
Cur = Flags.at (Flags.size () - 1 );
1597
1598
StringRef Prev;
1598
1599
if (Flags.size () >= 2 ) {
1599
1600
Prev = Flags.at (Flags.size () - 2 );
1600
- SuggestedCompletions = Opts-> suggestValueCompletions (Prev, Cur);
1601
+ SuggestedCompletions = Opts. suggestValueCompletions (Prev, Cur);
1601
1602
}
1602
1603
1603
1604
if (SuggestedCompletions.empty ())
1604
- SuggestedCompletions = Opts-> suggestValueCompletions (Cur, " " );
1605
+ SuggestedCompletions = Opts. suggestValueCompletions (Cur, " " );
1605
1606
1606
1607
// If Flags were empty, it means the user typed `clang [tab]` where we should
1607
1608
// list all possible flags. If there was no value completion and the user
@@ -1619,7 +1620,7 @@ void Driver::HandleAutocompletions(StringRef PassedFlags) const {
1619
1620
// If the flag is in the form of "--autocomplete=-foo",
1620
1621
// we were requested to print out all option names that start with "-foo".
1621
1622
// For example, "--autocomplete=-fsyn" is expanded to "-fsyntax-only".
1622
- SuggestedCompletions = Opts-> findByPrefix (Cur, DisableFlags);
1623
+ SuggestedCompletions = Opts. findByPrefix (Cur, DisableFlags);
1623
1624
1624
1625
// We have to query the -W flags manually as they're not in the OptTable.
1625
1626
// TODO: Find a good way to add them to OptTable instead and them remove
@@ -2037,6 +2038,7 @@ bool Driver::DiagnoseInputExistence(const DerivedArgList &Args, StringRef Value,
2037
2038
// Construct a the list of inputs and their types.
2038
2039
void Driver::BuildInputs (const ToolChain &TC, DerivedArgList &Args,
2039
2040
InputList &Inputs) const {
2041
+ const llvm::opt::OptTable &Opts = getOpts ();
2040
2042
// Track the current user specified (-x) input. We also explicitly track the
2041
2043
// argument used to set the type; we only want to claim the type when we
2042
2044
// actually use it, so we warn about unused -x arguments.
@@ -2160,15 +2162,15 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args,
2160
2162
StringRef Value = A->getValue ();
2161
2163
if (DiagnoseInputExistence (Args, Value, types::TY_C,
2162
2164
/* TypoCorrect=*/ false )) {
2163
- Arg *InputArg = MakeInputArg (Args, * Opts, A->getValue ());
2165
+ Arg *InputArg = MakeInputArg (Args, Opts, A->getValue ());
2164
2166
Inputs.push_back (std::make_pair (types::TY_C, InputArg));
2165
2167
}
2166
2168
A->claim ();
2167
2169
} else if (A->getOption ().matches (options::OPT__SLASH_Tp)) {
2168
2170
StringRef Value = A->getValue ();
2169
2171
if (DiagnoseInputExistence (Args, Value, types::TY_CXX,
2170
2172
/* TypoCorrect=*/ false )) {
2171
- Arg *InputArg = MakeInputArg (Args, * Opts, A->getValue ());
2173
+ Arg *InputArg = MakeInputArg (Args, Opts, A->getValue ());
2172
2174
Inputs.push_back (std::make_pair (types::TY_CXX, InputArg));
2173
2175
}
2174
2176
A->claim ();
@@ -2202,7 +2204,7 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args,
2202
2204
if (CCCIsCPP () && Inputs.empty ()) {
2203
2205
// If called as standalone preprocessor, stdin is processed
2204
2206
// if no other input is present.
2205
- Arg *A = MakeInputArg (Args, * Opts, " -" );
2207
+ Arg *A = MakeInputArg (Args, Opts, " -" );
2206
2208
Inputs.push_back (std::make_pair (types::TY_C, A));
2207
2209
}
2208
2210
}
0 commit comments