[llvm-commits] CVS: llvm/lib/Transforms/Scalar/SymbolStripping.cpp

Chris Lattner lattner at cs.uiuc.edu
Sat Jan 10 15:38:02 PST 2004


Changes in directory llvm/lib/Transforms/Scalar:

SymbolStripping.cpp updated: 1.24 -> 1.25

---
Log message:

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!  :)



---
Diffs of the changes:  (+9 -6)

Index: llvm/lib/Transforms/Scalar/SymbolStripping.cpp
diff -u llvm/lib/Transforms/Scalar/SymbolStripping.cpp:1.24 llvm/lib/Transforms/Scalar/SymbolStripping.cpp:1.25
--- llvm/lib/Transforms/Scalar/SymbolStripping.cpp:1.24	Fri Nov 21 19:29:35 2003
+++ llvm/lib/Transforms/Scalar/SymbolStripping.cpp	Sat Jan 10 15:36:49 2004
@@ -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 @@
 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;





More information about the llvm-commits mailing list