diff options
| author | Rui Ueyama <ruiu@google.com> | 2016-12-02 00:38:15 +0000 |
|---|---|---|
| committer | Rui Ueyama <ruiu@google.com> | 2016-12-02 00:38:15 +0000 |
| commit | 395859bdb7534d4cf156539d5568cb30a0630038 (patch) | |
| tree | 2d69e8800b6434c671857bbb2b0ba0f13c709e6b /lld/ELF/ICF.cpp | |
| parent | 42f92a7225b538752895710bac0904dd1263d68c (diff) | |
| download | bcm5719-llvm-395859bdb7534d4cf156539d5568cb30a0630038.tar.gz bcm5719-llvm-395859bdb7534d4cf156539d5568cb30a0630038.zip | |
Fix undefined behavior.
New items can be added to Ranges here, and that invalidates
an iterater that previously pointed the end of the vector.
llvm-svn: 288443
Diffstat (limited to 'lld/ELF/ICF.cpp')
| -rw-r--r-- | lld/ELF/ICF.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/lld/ELF/ICF.cpp b/lld/ELF/ICF.cpp index b41660861d3..593e8b00833 100644 --- a/lld/ELF/ICF.cpp +++ b/lld/ELF/ICF.cpp @@ -328,19 +328,21 @@ template <class ELFT> void ICF<ELFT>::run() { }; // 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; } |

