Use ArgList::hasFlag().

I just didn't know that ArgList had that function.

llvm-svn: 316499
This commit is contained in:
Rui Ueyama 2017-10-24 20:59:55 +00:00
parent 513d8fbb3a
commit ac7aaeb770
1 changed files with 15 additions and 22 deletions

View File

@ -409,13 +409,6 @@ void LinkerDriver::main(ArrayRef<const char *> ArgsArr, bool CanExitEarly) {
}
}
static bool getArg(opt::InputArgList &Args, unsigned K1, unsigned K2,
bool Default) {
if (auto *Arg = Args.getLastArg(K1, K2))
return Arg->getOption().getID() == K1;
return Default;
}
static std::vector<StringRef> getArgs(opt::InputArgList &Args, int Id) {
std::vector<StringRef> V;
for (auto *Arg : Args.filtered(Id))
@ -434,8 +427,8 @@ static UnresolvedPolicy getUnresolvedSymbolPolicy(opt::InputArgList &Args) {
if (Args.hasArg(OPT_relocatable))
return UnresolvedPolicy::IgnoreAll;
UnresolvedPolicy ErrorOrWarn = getArg(Args, OPT_error_unresolved_symbols,
OPT_warn_unresolved_symbols, true)
UnresolvedPolicy ErrorOrWarn = Args.hasFlag(OPT_error_unresolved_symbols,
OPT_warn_unresolved_symbols, true)
? UnresolvedPolicy::ReportError
: UnresolvedPolicy::Warn;
@ -628,26 +621,26 @@ void LinkerDriver::readConfigs(opt::InputArgList &Args) {
Config->BsymbolicFunctions = Args.hasArg(OPT_Bsymbolic_functions);
Config->Chroot = Args.getLastArgValue(OPT_chroot);
Config->CompressDebugSections = getCompressDebugSections(Args);
Config->DefineCommon = getArg(Args, OPT_define_common, OPT_no_define_common,
!Args.hasArg(OPT_relocatable));
Config->Demangle = getArg(Args, OPT_demangle, OPT_no_demangle, true);
Config->DefineCommon = Args.hasFlag(OPT_define_common, OPT_no_define_common,
!Args.hasArg(OPT_relocatable));
Config->Demangle = Args.hasFlag(OPT_demangle, OPT_no_demangle, true);
Config->DisableVerify = Args.hasArg(OPT_disable_verify);
Config->Discard = getDiscard(Args);
Config->DynamicLinker = getDynamicLinker(Args);
Config->EhFrameHdr =
getArg(Args, OPT_eh_frame_hdr, OPT_no_eh_frame_hdr, false);
Args.hasFlag(OPT_eh_frame_hdr, OPT_no_eh_frame_hdr, false);
Config->EmitRelocs = Args.hasArg(OPT_emit_relocs);
Config->EnableNewDtags = !Args.hasArg(OPT_disable_new_dtags);
Config->Entry = Args.getLastArgValue(OPT_entry);
Config->ExportDynamic =
getArg(Args, OPT_export_dynamic, OPT_no_export_dynamic, false);
Args.hasFlag(OPT_export_dynamic, OPT_no_export_dynamic, false);
Config->FatalWarnings =
getArg(Args, OPT_fatal_warnings, OPT_no_fatal_warnings, false);
Args.hasFlag(OPT_fatal_warnings, OPT_no_fatal_warnings, false);
Config->FilterList = getArgs(Args, OPT_filter);
Config->Fini = Args.getLastArgValue(OPT_fini, "_fini");
Config->GcSections = getArg(Args, OPT_gc_sections, OPT_no_gc_sections, false);
Config->GdbIndex = getArg(Args, OPT_gdb_index, OPT_no_gdb_index, false);
Config->ICF = getArg(Args, OPT_icf_all, OPT_icf_none, false);
Config->GcSections = Args.hasFlag(OPT_gc_sections, OPT_no_gc_sections, false);
Config->GdbIndex = Args.hasFlag(OPT_gdb_index, OPT_no_gdb_index, false);
Config->ICF = Args.hasFlag(OPT_icf_all, OPT_icf_none, false);
Config->Init = Args.getLastArgValue(OPT_init, "_init");
Config->LTOAAPipeline = Args.getLastArgValue(OPT_lto_aa_pipeline);
Config->LTONewPmPasses = Args.getLastArgValue(OPT_lto_newpm_passes);
@ -664,7 +657,7 @@ void LinkerDriver::readConfigs(opt::InputArgList &Args) {
Config->OptRemarksWithHotness = Args.hasArg(OPT_opt_remarks_with_hotness);
Config->Optimize = getInteger(Args, OPT_O, 1);
Config->OutputFile = Args.getLastArgValue(OPT_o);
Config->Pie = getArg(Args, OPT_pie, OPT_nopie, false);
Config->Pie = Args.hasFlag(OPT_pie, OPT_nopie, false);
Config->PrintGcSections = Args.hasArg(OPT_print_gc_sections);
Config->Rpath = getRpath(Args);
Config->Relocatable = Args.hasArg(OPT_relocatable);
@ -677,14 +670,14 @@ void LinkerDriver::readConfigs(opt::InputArgList &Args) {
Config->SortSection = getSortSection(Args);
Config->Strip = getStrip(Args);
Config->Sysroot = Args.getLastArgValue(OPT_sysroot);
Config->Target1Rel = getArg(Args, OPT_target1_rel, OPT_target1_abs, false);
Config->Target1Rel = Args.hasFlag(OPT_target1_rel, OPT_target1_abs, false);
Config->Target2 = getTarget2(Args);
Config->ThinLTOCacheDir = Args.getLastArgValue(OPT_thinlto_cache_dir);
Config->ThinLTOCachePolicy = check(
parseCachePruningPolicy(Args.getLastArgValue(OPT_thinlto_cache_policy)),
"--thinlto-cache-policy: invalid cache policy");
Config->ThinLTOJobs = getInteger(Args, OPT_thinlto_jobs, -1u);
ThreadsEnabled = getArg(Args, OPT_threads, OPT_no_threads, true);
ThreadsEnabled = Args.hasFlag(OPT_threads, OPT_no_threads, true);
Config->Trace = Args.hasArg(OPT_trace);
Config->Undefined = getArgs(Args, OPT_undefined);
Config->UnresolvedSymbols = getUnresolvedSymbolPolicy(Args);
@ -779,7 +772,7 @@ void LinkerDriver::readConfigs(opt::InputArgList &Args) {
}
bool HasExportDynamic =
getArg(Args, OPT_export_dynamic, OPT_no_export_dynamic, false);
Args.hasFlag(OPT_export_dynamic, OPT_no_export_dynamic, false);
// Parses -dynamic-list and -export-dynamic-symbol. They make some
// symbols private. Note that -export-dynamic takes precedence over them