<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/88233>88233</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
llvm:SelectionDAG: memory leak caused by static std::set EVTs
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
hensz
</td>
</tr>
</table>
<pre>
Hi!
We're using LLVM for jit compilation in our in-memory database, therefore memory handling is crucial. While switching from llvm 13 to 18 we saw that the std::set EVTs causes a memory leak in SDNode::getValueTypeList(). As far as I understand the code, for each extended EVT (we're using i96) a new value is inserted to the set if the pointer of the Type is different. An this does happen for identical types, if the compilation is done with a new instance of the llvm classes.
A possible fix for this leak would be to make EVTs a member of SelectionDAG. However, SDNode::getValueTypeList() has no access to the SelectionDAG instance, and passing EVTs as parameter would require many further changes, since getValueTypeList is called from SDNode::getSDVTList() and this is called in many locations, also outside of SelectionDAG.
What can we do to close this memory leak?
@nhaehnle, you switched EVTs from a managed static to a local static. Do you know how to handle the situation in a better way?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyEVM1y4zYTfBroMmUWCeqPBx70rT5lU-XkYpf3PASGItYQwGBAc5WnTwGUHXn3kAt_AMx0T09jkNmcHVErNv8Tm-MKpzj40A7k-O9V5_W1_WqErER5FOVheX4jIXeBYGLjzvD4-PIH9D7AdxNB-ctoLEbjHRgHfgpg3MOFLj5cQWPEDpmE_AJxoEC9DwS3zQGdtimfYVBhUgZtAd8GYwl4NlENaa8P_gLWvl2gqiF6qPYwEzDOEAeMKSlw1KI-iPrAFOH_L88MCicmBnxHsoSvidzT8U-vaTl8pviCdqLn60iPhqOQeyGbAg4MPQZAht9hcpoCR3Q6A6kULL_k0gnVAPQjktOkEyoIuZ8_yWSarZANIDia4S1hpUqNYwqRdComs6cIps-fozcuUgC__CZmKUKbvqdALhZwcBCHtOSJYcBxJ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