<div dir="ltr">I was about to do the same :) But one thing I wanted to ask is, why change Entry into a pointer? Why not just call operator[] twice? As Tobias said we'll need to cast to CXXRecordDecl. And we'll have to change Entry.get to Entry->get if Entry needs to be a pointer.</div>
<div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jun 30, 2014 at 5:42 PM, Tobias Hahn <span dir="ltr"><<a href="mailto:tobias.hahn@ableton.com" target="_blank">tobias.hahn@ableton.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>
<div><font><span style="font-size:10pt">
<div>Hey Richard,<br>
<br>
I'll check your patch in a minute, but except for a missing const_cast I believe it should be fine just by comparing it with the patch I came up with (attached below).<br>
<br>
Best,<br>
Tobias<br>
</div>
</span></font></div>
<div><font><span style="font-size:10pt">
<div>Am 27.06.2014 um 18:24 schrieb Richard Smith <<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>>:<div><div class="h5"><br>
<br>
> I think this may be one of those changes for which we need to accept that a unit test would not be useful. Does the change I suggested upthread fix the issue for you?<br>
> <br>
> On Fri, Jun 27, 2014 at 9:15 AM, Tobias Hahn <<a href="mailto:tobias.hahn@ableton.com" target="_blank">tobias.hahn@ableton.com</a>> wrote:<br>
> The last test case I sent around is as minimal as I could get it, but still over a hundred loc. It only crashes reliably when clang is built with asan (valgrind would probably be another option). I've tried a patch very similar to yours; and it fixes the
issue. <br>
> <br>
> Maybe one could construct a simpler test case with the knowledge that it has to force the KeyFunctions DenseMap to re-allocate?<br>
> <br>
> I've also thought about how to unit-test this, but it seems impossible to write a unit test without exposing the KeyFunctions cache in ASTContext. At this point I stopped because I have no idea what your policy is for such changes and in what general directions
this code is meant to evolve. <br>
> <br>
> Best,<br>
> Tobias<br>
> <br>
> Am 27.06.2014 um 17:24 schrieb "Richard Smith" <<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>>:<br>
> <br>
>> On Sun, Jun 22, 2014 at 5:45 PM, Nikola Smiljanic <<a href="mailto:popizdeh@gmail.com" target="_blank">popizdeh@gmail.com</a>> wrote:<br>
>> Awesome work Tobias, very interesting sequence of events. Adding Richard as he'll know how to best reshuffle this code :D<br>
>> <br>
>> The precompiled header is good, the trouble starts in ASTContext::getCurrentKeyFunctions:<br>
>> <br>
>> LazyDeclPtr &Entry = KeyFunctions[RD];<br>
>> if (!Entry)<br>
>> Entry = const_cast<CXXMethodDecl*>(computeKeyFunction(*this, RD));<br>
>> <br>
>> That's a classic :)<br>
>> <br>
>> It should be straightforward to fix this, something like:<br>
>> <br>
>> LazyDeclPtr *Entry = &KeyFunctions[RD];<br>
>> if (!*Entry) {<br>
>> auto *KeyFunction = computeKeyFunction(*this, RD);<br>
>> // Entry might have been invalidated by computeKeyFunction.<br>
>> Entry = &KeyFunctions[RD];<br>
>> *Entry = KeyFunction;<br>
>> }<br>
>> // do stuff with *Entry<br>
>> <br>
>> Do we have a reduced testcase? I suspect that such a test may be fragile to the point of being useless, so maybe we should go without =(<br>
>> <br>
>> KeyFunctions DenseMap will undergo reallocation inside computeKeyFunctions (see two markers in the attached callstack). Upon return Entry will point to freed memory. Good lord it took me a while to figure this out, I suck at debugging on Linux...<br>
>> <br>
>> <br>
>> On Sat, Jun 21, 2014 at 6:12 AM, Tobias Hahn <<a href="mailto:tobias.hahn@ableton.com" target="_blank">tobias.hahn@ableton.com</a>> wrote:<br>
>> Hi Nikola,<br>
>> <br>
>> I can reproduce the bug on linux if I tell clang to cross-compile for osx. Attached is a minimal example. You need to build clang with asan to reproduce the crash:<br>
>> <br>
>> ../llvm/configure --enable-libcpp CFLAGS="-fsanitize=address" CXXFLAGS="-fsanitize=address"<br>
>> <br>
>> Thanks again for looking into this crash!<br>
>> <br>
>> Best,<br>
>> Tobias<br>
>> <br>
>> Am 17.06.2014 um 00:16 schrieb Nikola Smiljanic <<a href="mailto:popizdeh@gmail.com" target="_blank">popizdeh@gmail.com</a>>:<br>
>> <br>
>> <br>
>> > It might make sense to file this with apple if you're using clang shipped with XCode as they ship their own releases. What version of clang are you using? Is the isystem flag important? What about #include <list>? I've tried to reproduce this but it's
not so straightforward because I'm on linux and some of the stuff in that bash script assumes mac os... I was wondering if it's possible to reduce this to something that's reproducible everywhere or if this is a mac specific issue.<br>
>> > <br>
>> > <br>
>> > On Mon, Jun 16, 2014 at 11:55 PM, Nikola Smiljanic <<a href="mailto:popizdeh@gmail.com" target="_blank">popizdeh@gmail.com</a>> wrote:<br>
>> > Thanks for the detailed report! The only thing you can do more is try and debug this yourself ;)<br>
>> > <br>
>> > <br>
>> > On Mon, Jun 16, 2014 at 8:33 PM, Tobias Hahn <<a href="mailto:tobias.hahn@ableton.com" target="_blank">tobias.hahn@ableton.com</a>> wrote:<br>
>> > Hi all,<br>
>> > <br>
>> > I've run into (what I believe is) a memory bug with clang while producing a precompiled header. In short, under certain circumstances, clang will write a pch that causes a crash when trying to use this pch in a later compilation unit.<br>
>> > <br>
>> > Occasionally, while clang is compiling the pch, malloc complains that one of its checksums has been overwritten; while at other times, clang throws an error that a definition has a different exception specification than the declaration two lines above
it (when both have no exception specification). Both these symptoms lead me to believe that somewhere clang overwrites memory.<br>
>> > <br>
>> > I have stripped the code that reliably causes this crash down to a few hundred lines and have created a little script to reproduce the bug (details at
<a href="http://llvm.org/bugs/show_bug.cgi?id=20026" target="_blank">http://llvm.org/bugs/show_bug.cgi?id=20026</a>). I'm not sure, however, about your process for handling such bugs, which is why I'm cross-posting here. My main question is if there is anything else I could
provide you with to help fixing this issue.<br>
>> > <br>
>> > Thank you very much in advance!<br>
>> > <br>
>> > Best,<br>
>> > Tobias<br>
>> > <br>
>> > <br>
>> > Ableton AG, Schoenhauser Allee 6-7, 10119 Berlin, Germany<br>
>> > Sitz (Registered Office) Berlin, Amtsgericht Berlin-Charlottenburg, HRB 72838<br>
>> > Vorstand (Management Board): Gerhard Behles, Jan Bohl<br>
>> > Vorsitzender des Aufsichtsrats (Chair of the Supervisory Board): Uwe Struck<br>
>> > <br>
>> > <br>
>> > <br>
>> > _______________________________________________<br>
>> > cfe-dev mailing list<br>
>> > <a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>
>> > <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
>> > <br>
>> > <br>
>> <br>
>> Ableton AG, Schoenhauser Allee 6-7, 10119 Berlin, Germany<br>
>> Sitz (Registered Office) Berlin, Amtsgericht Berlin-Charlottenburg, HRB 72838<br>
>> Vorstand (Management Board): Gerhard Behles, Jan Bohl<br>
>> Vorsitzender des Aufsichtsrats (Chair of the Supervisory Board): Uwe Struck<br>
>>
>> <br>
>> <br>
>> <br>
>> <br>
> <br>
<br>
Ableton AG, Schoenhauser Allee 6-7, 10119 Berlin, Germany<br>
Sitz (Registered Office) Berlin, Amtsgericht Berlin-Charlottenburg, HRB 72838<br>
Vorstand (Management Board): Gerhard Behles, Jan Bohl<br>
Vorsitzender des Aufsichtsrats (Chair of the Supervisory Board): Uwe Struck<br>
<br>
<br>
</div></div></div>
</span></font></div>
</div>
</blockquote></div><br></div>