[PATCH/RFC] Fix -fdelayed-template-parsing leaks with enableIncrementalProcessing

Brad King brad.king at kitware.com
Tue Aug 19 12:43:16 PDT 2014

Hi Folks,

I'm working on a Clang-based tool that wants to detect whether
implicit class members may be safely called.  It needs to be able
to declare and define implicit members in HandleTranslationUnit,
so it calls CI.getPreprocessor().enableIncrementalProcessing() to
prevent Parser::ParseTopLevelDecl from tearing down infrastructure
with Sema::ActOnEndOfTranslationUnit.  When my HandleTranslationUnit
is done adding the members it calls ActOnEndOfTranslationUnit to
finish things up.  This works well without -fdelayed-template-parsing.

With -fdelayed-template-parsing enabled (for MSVC compat) then late
template parsing allocates TemplateIdAnnotation instances that are
never freed.  The CleanupRAII guard in ParseTopLevelDecl is no longer
in scope while ActOnEndOfTranslationUnit is called.  The late template
parsing implementation lacks a place to cleanup such resources as
required by the change in r154743 (Parser: Don't manage
TemplateAnnotationIds in a delayed cleanup pool, 2012-04-14).

Here is a patch series to add a test for this case and propose a
possible fix.  It applies on trunk as of r215995.  Patch 0001 modifies
unittests/Frontend/FrontendActionTest.cpp to add a test case showing
the problem.  Patch 0002 proposes to fix this by adding a second
callback to perform cleanup after late template parsing.  See commit
messages for details.  Can anyone familiar with the lifetime needed
for TemplateIdAnnotation instances suggest another approach?


-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Demonstrate-late-template-parsing-leak-with-incremen.patch
Type: text/x-diff
Size: 4891 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140819/f9792a9e/attachment.patch>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-Fix-late-template-parsing-leak-with-incremental-proc.patch
Type: text/x-diff
Size: 4087 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140819/f9792a9e/attachment-0001.patch>

More information about the cfe-commits mailing list