From: Rui Ueyama Date: Fri, 2 Dec 2016 00:38:15 +0000 (+0000) Subject: Fix undefined behavior. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=395859bdb7534d4cf156539d5568cb30a0630038;p=platform%2Fupstream%2Fllvm.git 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 --- diff --git a/lld/ELF/ICF.cpp b/lld/ELF/ICF.cpp index b416608..593e8b0 100644 --- a/lld/ELF/ICF.cpp +++ b/lld/ELF/ICF.cpp @@ -328,19 +328,21 @@ template void ICF::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; }