[lld] r288443 - Fix undefined behavior.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 1 16:38:16 PST 2016
Author: ruiu
Date: Thu Dec 1 18:38:15 2016
New Revision: 288443
URL: http://llvm.org/viewvc/llvm-project?rev=288443&view=rev
Log:
Fix undefined behavior.
New items can be added to Ranges here, and that invalidates
an iterater that previously pointed the end of the vector.
Modified:
lld/trunk/ELF/ICF.cpp
Modified: lld/trunk/ELF/ICF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ICF.cpp?rev=288443&r1=288442&r2=288443&view=diff
==============================================================================
--- lld/trunk/ELF/ICF.cpp (original)
+++ lld/trunk/ELF/ICF.cpp Thu Dec 1 18:38:15 2016
@@ -328,19 +328,21 @@ template <class ELFT> void ICF<ELFT>::ru
};
// Compare static contents and assign unique IDs for each static content.
- auto End = Ranges.end();
- foreach(Ranges.begin(), End, [&](Range &R) { segregate(&R, true); });
- foreach(End, Ranges.end(), Copy);
+ size_t Size = Ranges.size();
+ foreach(Ranges.begin(), Ranges.end(),
+ [&](Range &R) { segregate(&R, true); });
+ foreach(Ranges.begin() + Size, Ranges.end(), Copy);
++Cnt;
// Split ranges by comparing relocations until convergence is obtained.
for (;;) {
- auto End = Ranges.end();
- foreach(Ranges.begin(), End, [&](Range &R) { segregate(&R, false); });
- foreach(End, Ranges.end(), Copy);
+ size_t Size = Ranges.size();
+ foreach(Ranges.begin(), Ranges.end(),
+ [&](Range &R) { segregate(&R, false); });
+ foreach(Ranges.begin() + Size, Ranges.end(), Copy);
++Cnt;
- if (End == Ranges.end())
+ if (Size == Ranges.size())
break;
}
More information about the llvm-commits
mailing list