From 449670a8f7ffd364fc0ab5a1e3ee90587e17dcf7 Mon Sep 17 00:00:00 2001 From: John Criswell Date: Thu, 7 Aug 2003 14:43:13 +0000 Subject: Fixed a segfault in gccld. The original code does not work because the value from WorkList.end() is invalidated once WorkList.erase() is called. To ensure proper functionality, we must ensure that WorkList.erase() is always called before WorkList.end(). llvm-svn: 7673 --- llvm/lib/Transforms/IPO/GlobalDCE.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'llvm/lib/Transforms') diff --git a/llvm/lib/Transforms/IPO/GlobalDCE.cpp b/llvm/lib/Transforms/IPO/GlobalDCE.cpp index c7fddc99139..f991229e985 100644 --- a/llvm/lib/Transforms/IPO/GlobalDCE.cpp +++ b/llvm/lib/Transforms/IPO/GlobalDCE.cpp @@ -123,8 +123,10 @@ bool GlobalDCE::RemoveIfDead(GlobalValue *GV) { // If the global variable is still on the worklist, remove it now. std::vector::iterator I = std::find(WorkList.begin(), WorkList.end(), GV); - while (I != WorkList.end()) - I = std::find(WorkList.erase(I), WorkList.end(), GV); + while (I != WorkList.end()) { + I = WorkList.erase(I); + I = std::find(I, WorkList.end(), GV); + } return true; } -- cgit v1.2.3