[PATCH] D42681: [ELF] - Remove unused synthetic sections correctly.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 31 01:28:09 PST 2018
>> - std::vector<BaseCommand *>::iterator Empty = OS->SectionCommands.end();
>> - for (auto I = OS->SectionCommands.begin(), E = OS->SectionCommands.end();
>> - I != E; ++I) {
>> - BaseCommand *B = *I;
>> + // If we reach here, then SS is an unused synthetic section and we want to
>> + // remove it from corresponding input section description of output section.
>> + for (BaseCommand *B : OS->SectionCommands) {
>> if (auto *ISD = dyn_cast<InputSectionDescription>(B)) {
>> - llvm::erase_if(ISD->Sections,
>> - [=](InputSection *IS) { return IS == SS; });
>> - if (ISD->Sections.empty())
>> - Empty = I;
>> + auto It = llvm::find(ISD->Sections, SS);
>> + if (It == ISD->Sections.end())
>> + continue;
>> + ISD->Sections.erase(It);
>> + break;
>
>This can keep using erase_if:
>
> for (BaseCommand *B : OS->SectionCommands)
> if (auto *ISD = dyn_cast<InputSectionDescription>(B))
> llvm::erase_if(ISD->Sections,
> [=](InputSection *IS) { return IS == SS; });
>
>LGTM with that.
>
>Cheers,
>Rafael
Ok, thanks !
This stops doing early loop break, but makes code simpler and not a perfomance hit anyways.
Updated the patch.
Rui, are you OK to land it ?
George.
More information about the llvm-commits
mailing list