r296656 - [PCH] Avoid VarDecl emission attempt if no owning module avaiable

Hans Wennborg via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 2 08:59:52 PST 2017


Merged to 4.0 in r296762.

On Wed, Mar 1, 2017 at 11:18 AM, Bruno Cardoso Lopes via cfe-commits
<cfe-commits at lists.llvm.org> wrote:
> Author: bruno
> Date: Wed Mar  1 13:18:42 2017
> New Revision: 296656
>
> URL: http://llvm.org/viewvc/llvm-project?rev=296656&view=rev
> Log:
> [PCH] Avoid VarDecl emission attempt if no owning module avaiable
>
> This is a stopgap fix for PR31863, a regression introduced in r276159.
>
> Consider this snippet:
>
> struct FVector;
> struct FVector {};
> struct FBox {
>   FVector Min;
>   FBox(int);
> };
> namespace {
> FBox InvalidBoundingBox(0);
> }
>
> While parsing the DECL_VAR for 'struct FBox', clang recursively read all the
> dep decls until it finds the DECL_CXX_RECORD forward declaration for 'struct
> FVector'. Then, it resumes all the way up back to DECL_VAR handling in
> `ReadDeclRecord`, where it checks if `isConsumerInterestedIn` for the decl.
>
> One of the condition for `isConsumerInterestedIn` to return false is if the
> VarDecl is imported from a module `D->getImportedOwningModule()`, because it
> will get emitted when we import the relevant module. However, before checking
> if it comes from a module, clang checks if `Ctx.DeclMustBeEmitted(D)`, which
> triggers the emission of 'struct FBox'. Since one of its fields is still
> incomplete, it crashes.
>
> Instead, check if `D->getImportedOwningModule()` is true before calling
> `Ctx.DeclMustBeEmitted(D)`.
>
> Differential Revision: https://reviews.llvm.org/D29753
>
> rdar://problem/30173654
>
> Added:
>     cfe/trunk/test/PCH/empty-def-fwd-struct.h
> Modified:
>     cfe/trunk/lib/Serialization/ASTReaderDecl.cpp


More information about the cfe-commits mailing list