Hi nicholas,
On code like switch (0) { case 0:; } clang leaks one basic block.
First, CodeGenFunction::EmitSwitchStmt creates a new BasicBlock,
then it does the following and exits:
// See if we can constant fold the condition of the switch and therefore only
// emit the live case statement (if any) of the switch.
This BasicBlock remains unattached to anything an leaks.
The following fix removes the leak.
Confirmed by running clang on a function with 500K such statements:
the memory footprint drops from 800K to 500K.
(also tested by "check-clang")
Alternative fix may be to move the creation of SwitchExit to some later point,
by my attempts to do so failed (the test CodeGenCXX/condition.cpp starts
failing).
http://llvm-reviews.chandlerc.com/D2472
Files:
lib/CodeGen/CGStmt.cpp
Index: lib/CodeGen/CGStmt.cpp
===================================================================
--- lib/CodeGen/CGStmt.cpp
+++ lib/CodeGen/CGStmt.cpp
@@ -1270,6 +1270,7 @@
// switches continue to function properly
SwitchInsn = SavedSwitchInsn;
+ delete SwitchExit.getBlock(); // SwitchExit will not be needed.
return;
}
}
Index: lib/CodeGen/CGStmt.cpp
===================================================================
--- lib/CodeGen/CGStmt.cpp
+++ lib/CodeGen/CGStmt.cpp
@@ -1270,6 +1270,7 @@
// switches continue to function properly
SwitchInsn = SavedSwitchInsn;
+ delete SwitchExit.getBlock(); // SwitchExit will not be needed.
return;
}
}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits