<div dir="ltr">Hi,<br><br>Sorry for a late reply...<br><br>I changed the approach to fix those reachable memory issues, because my previous approach had problems.<br><br>My previous approach wrapped cl::list with ManagedStatic. But, this had an initialization problem because cl::list strictly depends on purely being static variable, ie, it must be initialized at the start of runtime. But ManagedStatic delays the initialization by its nature.<br>
<br>My new approach wraps Parser with ManagedStatic inside cl::list. This way, cl::list is correctly initialized at the start of runtime and the PassNamePaser is destroyed correctly at the same time. PassNameParser is the actual culprit for the memory issues.<br>
<br>In my opinion, this solution looks simpler and more straight fix than the previous one.<br><br>I've checked all tests pass.<br><br>And I've checked the memory issues are gone by running this:<br><br>  valgrind --leak-check=full --show-reachable=yes ./Debug+Asserts/bin/opt -instnamer hello.ll -o hello.bc<br>
<br>I think it's hard to test it correctly, because this is a memory leak issue, which happens at the very end of process termination.<br><br>Is there any similar test in the repository?<br></div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Tue, May 14, 2013 at 11:07 PM, Rafael Espíndola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Any idea why opt is still leaking? Can you turn toy.cpp into a unit<br>
test and include it in the patch?<br>
<div class="HOEnZb"><div class="h5"><br>
On 13 May 2013 07:21, Ryo Onodera <<a href="mailto:ryoqun@gmail.com">ryoqun@gmail.com</a>> wrote:<br>
> Hi,<br>
><br>
> Thanks for trying my patch!<br>
><br>
> I've prepared a minimal test case. Could you give it a try?<br>
><br>
> Build the attached source file and run like this:<br>
><br>
> $ clang++ -g -O3 toy.cpp `/path/to//llvm-config --cppflags --libs`<br>
> `/path/to/llvm-config --ldflags` -o toy && valgrind --show-reachable=yes<br>
> --leak-check=full ./toy<br>
><br>
> Regards,<br>
><br>
> On Wed, May 8, 2013 at 11:02 PM, Rafael Espíndola<br>
> <<a href="mailto:rafael.espindola@gmail.com">rafael.espindola@gmail.com</a>> wrote:<br>
>><br>
>> How are you getting these warning? I tried running<br>
>><br>
>> valgrind --leak-check=full --show-reachable=yes .opt -instnamer<br>
>> test.ll  -o test.bc<br>
>><br>
>> And I get the same 96 bytes with or without your patch.<br>
>><br>
>> On 1 April 2013 19:50, Ryo Onodera <<a href="mailto:ryoqun@gmail.com">ryoqun@gmail.com</a>> wrote:<br>
>> > (This is repost of my previous post to llvm-dev<br>
>> > <a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2013-March/060691.html" target="_blank">http://lists.cs.uiuc.edu/pipermail/llvmdev/2013-March/060691.html</a><br>
>> >  I sent my patch to a wrong list, sorry)<br>
>> ><br>
>> > Hi, I'm Ryo Onodera.<br>
>> ><br>
>> > This is my first post to this mailing list. Fist, thanks for creating<br>
>> > a great library!<br>
>> ><br>
>> > We're using LLVM to support JIT in Rubinius (an alternative<br>
>> > implementation of Ruby, a dynamic programming language).<br>
>> ><br>
>> > I'm submitting a small patch for a minor issue.<br>
>> ><br>
>> > It solves still-reachable leak warnings from Valgrind. Example<br>
>> > warnings are shown at the end of this mail.<br>
>> ><br>
>> > As these warnings weren't considered problematic in the past(*1), I<br>
>> > know this is really minor issue. But, I want to fix it to reduce<br>
>> > noises when using Valgrind, not resorting to Valgrind's suppression<br>
>> > mechanism.<br>
>> ><br>
>> > This patch contains no functional change. And it should cause no<br>
>> > problem.<br>
>> ><br>
>> > Since this is my first patch to LLVM, please let me know any<br>
>> > corrections. I'll greatly appreciate them and happily update my patch.<br>
>> ><br>
>> > Also, LLVM's codebase is really clean. It took little time to make this<br>
>> > patch.<br>
>> ><br>
>> > The actual warnings are like this:<br>
>> ><br>
>> > ==26332== 40 bytes in 1 blocks are still reachable in loss record 5 of<br>
>> > 10<br>
>> > ==26332==    at 0x4C2B3F8: malloc (in<br>
>> > /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)<br>
>> > ==26332==    by 0x165CC6C: llvm::sys::MutexImpl::MutexImpl(bool)<br>
>> > (Mutex.cpp:49)<br>
>> > ==26332==    by 0xD41D5A:<br>
>> > llvm::sys::SmartMutex<true>::SmartMutex(bool) (Mutex.h:94)<br>
>> > ==26332==    by 0xD3E81F: void*<br>
>> > llvm::object_creator<llvm::sys::SmartMutex<true> >()<br>
>> > (ManagedStatic.h:26)<br>
>> > ==26332==    by 0x165AA95:<br>
>> > llvm::ManagedStaticBase::RegisterManagedStatic(void* (*)(), void<br>
>> > (*)(void*)) const (ManagedStatic.cpp:50)<br>
>> > ==26332==    by 0xD3C372:<br>
>> > llvm::ManagedStatic<llvm::sys::SmartMutex<true> >::operator*()<br>
>> > (ManagedStatic.h:68)<br>
>> > ==26332==    by 0x1605FE2:<br>
>> ><br>
>> > llvm::PassRegistry::removeRegistrationListener(llvm::PassRegistrationListener*)<br>
>> > (PassRegistry.cpp:195)<br>
>> > ==26332==    by 0x15F1FC5:<br>
>> > llvm::PassRegistrationListener::~PassRegistrationListener()<br>
>> > (Pass.cpp:211)<br>
>> > ==26332==    by 0x15F2074: llvm::PassNameParser::~PassNameParser()<br>
>> > (Pass.cpp:221)<br>
>> > ==26332==    by 0x1604973: llvm::cl::list<llvm::PassInfo const*, bool,<br>
>> > llvm::PassNameParser>::~list() (in<br>
>> > /home/ryoqun/rubinius/ryoqun/bin/rbx)<br>
>> > ==26332==    by 0x5EE4900: __run_exit_handlers (exit.c:78)<br>
>> > ==26332==    by 0x5EE4984: exit (exit.c:100)<br>
>> ><br>
>> > *1 <a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-January/046828.html" target="_blank">http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-January/046828.html</a><br>
>> ><br>
>> > Regards,<br>
>> ><br>
>> > _______________________________________________<br>
>> > llvm-commits mailing list<br>
>> > <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
>> > <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
>> ><br>
><br>
><br>
><br>
><br>
> --<br>
>  ryo   | 小野寺 諒   | <a href="mailto:ryoqun@gmail.com">ryoqun@gmail.com</a><br>
>    qun | Ryo Onodera | <a href="http://ryoqun.github.com/" target="_blank">http://ryoqun.github.com/</a><br>
>        |             | 090-1264-2619<br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><div dir="ltr"> ryo   | 小野寺 諒   | <a href="mailto:ryoqun@gmail.com" target="_blank">ryoqun@gmail.com</a><br>
   qun | Ryo Onodera | <a href="http://ryoqun.github.com/" target="_blank">http://ryoqun.github.com/</a><br>
       |             | 090-1264-2619</div>
</div>