<table><tr><td style="">aaronpuchert added a comment.
</td><a style="text-decoration: none; padding: 4px 8px; margin: 0 8px 8px; float: right; color: #464C5C; font-weight: bold; border-radius: 3px; background-color: #F7F7F9; background-image: linear-gradient(to bottom,#fff,#f1f0f1); display: inline-block; border: 1px solid rgba(71,87,120,.2);" href="https://phabricator.kde.org/D17289">View Revision</a></tr></table><br /><div><div><p>I've had a look at the Clang code. They actually go to some lengths to make sure all temporary files are deleted on a clean exit — they register all open temporary files and clean them up in an exit-time destructor. (See <tt style="background: #ebebeb; font-size: 13px;">TemporaryFiles</tt> in <a href="https://github.com/llvm-mirror/clang/blob/master/lib/Frontend/PrecompiledPreamble.cpp" class="remarkup-link" target="_blank" rel="noreferrer">lib/Frontend/PrecompiledPreamble.cpp</a>.) However, this won't work in the case of a crash. They have some mechanisms for cleanup in the case of crashes, but I suspect that this works by setting a signal handler and is thus only available in the stand-alone executable. There are mechanisms to ensure cleanup in any event by removing an open file on POSIX compatibles (close will then automatically delete it), or <a href="https://blogs.msdn.microsoft.com/oldnewthing/20160108-00/?p=92821" class="remarkup-link" target="_blank" rel="noreferrer">FILE_FLAG_DELETE_ON_CLOSE</a> on Windows. But that doesn't work for Clang, because they work with paths and don't pass file descriptors around.</p>
<p>By the way, does someone know why we are using <tt style="background: #ebebeb; font-size: 13px;">CXTranslationUnit_CreatePreambleOnFirstParse</tt>? This seems overly wasteful to me — most of these preambles are not reused again. It was introduced by <a href="https://phabricator.kde.org/R32:f14a8fc9ceb38a91c2d718552779da666d509bf1" style="background-color: #e7e7e7;
border-color: #e7e7e7;
border-radius: 3px;
padding: 0 4px;
font-weight: bold;
color: black;text-decoration: none;">f14a8fc9ceb38a91c2d718552779da666d509bf1</a>, but I fail to see how this relates to the problem the commit message describes. The documentation for <tt style="background: #ebebeb; font-size: 13px;">CXTranslationUnit_PrecompiledPreamble</tt> says that “An implicit precompiled header is used as an optimization when a particular translation unit is likely to be reparsed many times when the sources aren't changing that often.” For <tt style="background: #ebebeb; font-size: 13px;">CXTranslationUnit_CreatePreambleOnFirstParse</tt> it says “Used to indicate that the precompiled preamble should be created on the first parse. Otherwise it will be created on the first <em>reparse</em>. This trades runtime on the first parse (serializing the preamble takes time) for reduced runtime on the second parse (can now reuse the preamble).” I don't understand why we are doing this - we're creating preambles for all files in a project, although most of them are probably not even open in the editor at the time.</p></div></div><br /><div><strong>REPOSITORY</strong><div><div>R32 KDevelop</div></div></div><br /><div><strong>REVISION DETAIL</strong><div><a href="https://phabricator.kde.org/D17289">https://phabricator.kde.org/D17289</a></div></div><br /><div><strong>To: </strong>rjvbb, KDevelop, kfunk, mwolff<br /><strong>Cc: </strong>aaronpuchert, mwolff, pino, kfunk, kdevelop-devel, glebaccon, hase, antismap, iodelay, geetamc, Pilzschaf, akshaydeo, surgenight, arrowd<br /></div>