]> granicus.if.org Git - clang/commit
[Modules] Fix creating fake definition data for lambdas.
authorVolodymyr Sapsai <vsapsai@apple.com>
Wed, 21 Mar 2018 21:28:54 +0000 (21:28 +0000)
committerVolodymyr Sapsai <vsapsai@apple.com>
Wed, 21 Mar 2018 21:28:54 +0000 (21:28 +0000)
commit1a384bab8786e08a814ff2459280c6ec295e0e64
tree141708b077be43490ebf695afd927c02dfdb16d2
parentf353d86deb3ea8299f37c5477dcbb9ea30558fb1
[Modules] Fix creating fake definition data for lambdas.

During reading C++ definition data for lambda we can access
CXXRecordDecl representing lambda before we finished reading the
definition data. This can happen by reading a captured variable which is
VarDecl, then reading its decl context which is CXXMethodDecl `operator()`,
then trying to merge redeclarable methods and accessing
enclosing CXXRecordDecl. The call stack looks roughly like

    VisitCXXRecordDecl
      ReadCXXRecordDefinition
        VisitVarDecl
          VisitCXXMethodDecl
            mergeRedeclarable
              getPrimaryContextForMerging

If we add fake definition data at this point, later we'll hit the assertion

    Assertion failed: (!DD.IsLambda && !MergeDD.IsLambda && "faked up lambda definition?"), function MergeDefinitionData, file clang/lib/Serialization/ASTReaderDecl.cpp, line 1675.

The fix is to assign definition data before reading it. Fixes PR32556.

rdar://problem/37461072

Reviewers: rsmith, bruno

Reviewed By: rsmith

Subscribers: cfe-commits, jkorous-apple, aprantl

Differential Revision: https://reviews.llvm.org/D43494

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@328153 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Serialization/ASTReaderDecl.cpp
test/Modules/Inputs/self-referencing-lambda/a.h [new file with mode: 0644]
test/Modules/Inputs/self-referencing-lambda/module.modulemap [new file with mode: 0644]
test/Modules/self-referencing-lambda.cpp [new file with mode: 0644]