r267186 - Fix a bug involving deferred decl emission and PCH

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 22 13:58:38 PDT 2016


On Fri, Apr 22, 2016 at 12:59 PM, Reid Kleckner via cfe-commits <
cfe-commits at lists.llvm.org> wrote:

> On Fri, Apr 22, 2016 at 12:29 PM, Richard Smith <richard at metafoo.co.uk>
> wrote:
>
>> On Fri, Apr 22, 2016 at 11:46 AM, Reid Kleckner via cfe-commits <
>> cfe-commits at lists.llvm.org> wrote:
>>
>>> Author: rnk
>>> Date: Fri Apr 22 13:46:33 2016
>>> New Revision: 267186
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=267186&view=rev
>>> Log:
>>> Fix a bug involving deferred decl emission and PCH
>>>
>>> For various reasons, involving dllexport and class linkage compuations,
>>> we have to wait until after the semicolon after a class declaration to
>>> emit inline methods. These are "deferred" decls. Before this change,
>>> finishing the tag decl would trigger us to deserialize some PCH so that
>>> we could make a "pretty" IR-level type. Deserializing the PCH triggered
>>> calls to HandleTopLevelDecl, which, when done, checked the deferred decl
>>> list, and emitted some dllexported decls that weren't ready.
>>>
>>> Avoid this re-entrancy. Deferred decls should not get emitted when a tag
>>> is finished, they should only be emitted after a real top level decl in
>>> the main file.
>>>
>>
>> What if there is no subsequent top-level decl after such a call? It seems
>> like the deferred decls won't be emitted at all in that case. Is that
>> acceptable?
>>
>
> I think what happens is that we finish the tag declaration, and then call
> HandleTopLevelDecl on it directly, and that is supposed to flush the
> deferred methods.
>
> I can't think of any ways to create a C++ tag definition in a way that
> doesn't create a top level decl.
>

This seems like a fragile thing to rely on. What about template
instantiation performed at end of TU? (I /think/ that case is currently
fine because all the kinds of template we instantiate ultimately do result
in a call to HandleTopLevelDecl or some other ASTConsumer callback, but I
don't really like relying on that.)

Could we trigger processing of any remaining deferred declarations in
HandleTranslationUnit?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160422/7ae2b0f3/attachment.html>


More information about the cfe-commits mailing list