From 22bb29967322d1bfee61e02d007d72b433d886ec Mon Sep 17 00:00:00 2001 From: Jason Hiser <jdhiser@gmail.com> Date: Tue, 12 Feb 2019 21:00:01 -0500 Subject: [PATCH] minor code cleanups Former-commit-id: 72178881af10bbacb1a057984cc662a3c92b2f99 --- ir_builders/fill_in_cfg.cpp | 2 -- ir_builders/read_variantir.cpp | 4 ++-- ir_builders/split_eh_frame.cpp | 11 +++++------ tools/selective_cfi/scfi_instr.cpp | 31 ++++++++++++------------------ 4 files changed, 19 insertions(+), 29 deletions(-) diff --git a/ir_builders/fill_in_cfg.cpp b/ir_builders/fill_in_cfg.cpp index aa921235f..85ce8cf0e 100644 --- a/ir_builders/fill_in_cfg.cpp +++ b/ir_builders/fill_in_cfg.cpp @@ -591,7 +591,6 @@ void PopulateCFG::fill_in_landing_pads(FileIR_t *firp) map<Function_t*,set<Instruction_t*> > insns_to_add_to_funcs; - // for_each(firp->getInstructions().begin(), firp->getInstructions().end(), [&](Instruction_t* t) for(const auto t : firp->getInstructions()) { if(t->getFunction()==NULL) @@ -602,7 +601,6 @@ void PopulateCFG::fill_in_landing_pads(FileIR_t *firp) }; - // for_each(insns_to_add_to_funcs.begin(), insns_to_add_to_funcs.end(), [&](pair<Function_t* const,set<Instruction_t*> > & p) for(const auto & p : insns_to_add_to_funcs) { auto & func=p.first; diff --git a/ir_builders/read_variantir.cpp b/ir_builders/read_variantir.cpp index 18aaf555d..ac2433396 100644 --- a/ir_builders/read_variantir.cpp +++ b/ir_builders/read_variantir.cpp @@ -64,7 +64,7 @@ int main(int argc, char* argv[]) FileIR_t* firp=new FileIR_t(*pidp, this_file); assert(firp); - std::for_each(firp->GetFunctions().begin(), firp->GetFunctions().end(), [](const Function_t* fn) { + for(auto fn : firp->GetFunctions()) if (!fn) return; cout<<"Function: " << fn->GetName(); cout<<" NumArgs: " << fn->GetNumArguments(); @@ -72,7 +72,7 @@ int main(int argc, char* argv[]) cout<<" StackFrameSize: " << fn->GetStackFrameSize(); cout<<" OutArgsRegionSize: " << fn->GetOutArgsRegionSize(); cout<<endl; - }); + }; for( set<Instruction_t*>::const_iterator it=firp->GetInstructions().begin(); diff --git a/ir_builders/split_eh_frame.cpp b/ir_builders/split_eh_frame.cpp index b1c96c7e2..dcd7adb75 100644 --- a/ir_builders/split_eh_frame.cpp +++ b/ir_builders/split_eh_frame.cpp @@ -91,7 +91,7 @@ void split_eh_frame_impl_t<ptrsize>::lsda_call_site_build_ir } else { - for_each(action_table.begin(), action_table.end(), [&](const shared_ptr<LSDACallSiteAction_t>& p) + for(auto p : action_table) { const auto action=p->getAction(); if(action==0) @@ -153,7 +153,7 @@ void split_eh_frame_impl_t<ptrsize>::lsda_call_site_build_ir cout<<"What? :"<< action <<endl; exit(1); } - }); + }; } } @@ -163,12 +163,11 @@ void split_eh_frame_impl_t<ptrsize>::lsda_build_ir(const LSDA_t& lsda, Instructi const auto call_site_table_ptr=lsda.getCallSites(); const auto& call_site_table=*call_site_table_ptr; const auto& type_table_ptr=lsda.getTypeTable(); -// auto& type_table=*type_table_ptr; const auto cs_ptr_it=find_if(ALLOF(call_site_table), [&](const shared_ptr<LSDACallSite_t> &p) - { - return lsda_call_site_appliesTo(*p, insn); - }); + { + return lsda_call_site_appliesTo(*p, insn); + }); if(cs_ptr_it!= call_site_table.end()) { diff --git a/tools/selective_cfi/scfi_instr.cpp b/tools/selective_cfi/scfi_instr.cpp index 42cdfe23f..10cec5511 100644 --- a/tools/selective_cfi/scfi_instr.cpp +++ b/tools/selective_cfi/scfi_instr.cpp @@ -83,8 +83,6 @@ Relocation_t* SCFI_Instrument::create_reloc(Instruction_t* insn) { /* * Relocation_t* reloc=new Relocation_t; - insn->getRelocations().insert(reloc); - firp->getRelocations().insert(reloc); */ auto reloc=firp->addNewRelocation(insn,0,"error-if-seen"); // will update offset and type in caller @@ -1175,30 +1173,30 @@ static void insert_into_scoop_at(const string &str, DataScoop_t* scoop, FileIR_t scoop->getEnd()->setVirtualOffset(newend); // update each reloc to point to the new location. - for_each(scoop->getRelocations().begin(), scoop->getRelocations().end(), [str,at](Relocation_t* reloc) + for(auto reloc : scoop->getRelocations()) { if((unsigned int)reloc->getOffset()>=at) reloc->setOffset(reloc->getOffset()+str.size()); - }); + }; // check relocations for pointers to this object. // we'll update dataptr_to_scoop relocs, but nothing else // so assert if we find something else - for_each(firp->getRelocations().begin(), firp->getRelocations().end(), [scoop](Relocation_t* reloc) + for(auto reloc : firp->getRelocations()) { - DataScoop_t* wrt=dynamic_cast<DataScoop_t*>(reloc->getWRT()); + auto wrt=dynamic_cast<DataScoop_t*>(reloc->getWRT()); assert(wrt != scoop || reloc->getType()=="dataptr_to_scoop"); - }); + }; // for each scoop - for_each(firp->getDataScoops().begin(), firp->getDataScoops().end(), [&str,scoop,firp,at](DataScoop_t* scoop_to_update) + for(auto scoop_to_update : firp->getDataScoops()) { // for each relocation for that scoop - for_each(scoop_to_update->getRelocations().begin(), scoop_to_update->getRelocations().end(), [&str,scoop,firp,scoop_to_update,at](Relocation_t* reloc) + for(auto reloc : scoop_to_update->getRelocations()) { // if it's a reloc that's wrt scoop - DataScoop_t* wrt=dynamic_cast<DataScoop_t*>(reloc->getWRT()); + auto wrt=dynamic_cast<DataScoop_t*>(reloc->getWRT()); if(wrt==scoop) { // then we need to update the scoop @@ -1234,9 +1232,9 @@ static void insert_into_scoop_at(const string &str, DataScoop_t* scoop, FileIR_t } } - }); + }; - }); + }; }; template<int ptrsize> @@ -1410,21 +1408,16 @@ bool SCFI_Instrument::add_got_entries() // ICFS_t *newicfs=new ICFS_t; // firp->GetAllICFS().insert(newicfs); auto newicfs=firp->addNewICFS(); - for_each(firp->getInstructions().begin(), firp->getInstructions().end(), [&](Instruction_t* insn) + for(auto insn : firp->getInstructions()) { if(insn->getIndirectBranchTargetAddress() != NULL ) newicfs->insert(insn); - }); + }; zestcfi_function_entry->setIBTargets(newicfs); firp->assembleRegistry(); // add a relocation so that the zest_cfi "function" gets pointed to by the symbol - /* - Relocation_t* zestcfi_reloc=new Relocation_t(BaseObj_t::NOT_IN_DATABASE, zestcfi_pos+((uintptr_t)&zestcfi_sym.st_value - (uintptr_t)&zestcfi_sym), "data_to_insn_ptr", zestcfi_function_entry); - dynsym_scoop->getRelocations().insert(zestcfi_reloc); - firp->getRelocations().insert(zestcfi_reloc); - */ auto zestcfi_reloc=firp->addNewRelocation(dynsym_scoop,zestcfi_pos+((uintptr_t)&zestcfi_sym.st_value - (uintptr_t)&zestcfi_sym), "data_to_insn_ptr", zestcfi_function_entry); (void)zestcfi_reloc; -- GitLab