summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar/SymbolStripping.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-01-10 21:36:49 +0000
committerChris Lattner <sabre@nondot.org>2004-01-10 21:36:49 +0000
commit3bcecb92f3a349d944d546cc5e4e4137dfe8e4ff (patch)
tree401e8485156090b97ad463a2486db62993c1a9b1 /llvm/lib/Transforms/Scalar/SymbolStripping.cpp
parenta2bfab849f3555045415e470576798215072a7fa (diff)
downloadbcm5719-llvm-3bcecb92f3a349d944d546cc5e4e4137dfe8e4ff.tar.gz
bcm5719-llvm-3bcecb92f3a349d944d546cc5e4e4137dfe8e4ff.zip
Update obsolete comments
Fix iterator invalidation problems which was causing -mstrip to miss some entries, and read free'd memory. This shrinks the symbol table of 254.gap from 333 to 284 bytes! :) llvm-svn: 10751
Diffstat (limited to 'llvm/lib/Transforms/Scalar/SymbolStripping.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/SymbolStripping.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/llvm/lib/Transforms/Scalar/SymbolStripping.cpp b/llvm/lib/Transforms/Scalar/SymbolStripping.cpp
index 32ebdd36cbc..c43a2cb76e0 100644
--- a/llvm/lib/Transforms/Scalar/SymbolStripping.cpp
+++ b/llvm/lib/Transforms/Scalar/SymbolStripping.cpp
@@ -10,9 +10,9 @@
// This file implements stripping symbols out of symbol tables.
//
// Specifically, this allows you to strip all of the symbols out of:
-// * A function
// * All functions in a module
-// * All symbols in a module (all function symbols + all module scope symbols)
+// * All non-essential symbols in a module (all function symbols + all module
+// scope symbols)
//
// Notice that:
// * This pass makes code much less readable, so it should only be used in
@@ -30,12 +30,15 @@ using namespace llvm;
static bool StripSymbolTable(SymbolTable &SymTab) {
bool RemovedSymbol = false;
- for (SymbolTable::iterator I = SymTab.begin(); I != SymTab.end(); ++I) {
- std::map<const std::string, Value *> &Plane = I->second;
+ for (SymbolTable::iterator I = SymTab.begin(); I != SymTab.end();) {
+ // Removing items from the plane can cause the plane itself to get deleted.
+ // If this happens, make sure we incremented our plane iterator already!
+ std::map<const std::string, Value *> &Plane = (I++)->second;
- SymbolTable::type_iterator B = Plane.begin();
- while (B != Plane.end()) { // Found nonempty type plane!
+ SymbolTable::type_iterator B = Plane.begin(), Bend = Plane.end();
+ while (B != Bend) { // Found nonempty type plane!
Value *V = B->second;
+
if (isa<Constant>(V) || isa<Type>(V)) {
SymTab.type_remove(B++);
RemovedSymbol = true;
OpenPOWER on IntegriCloud