[cfe-commits] [PATCH] PR 12746: Code generation of variables reference expressions when mixing blocks and lambdas

Meador Inge meadori at gmail.com
Tue May 8 18:18:33 PDT 2012


Hi All,

In PR 12746 a failing assertion was reported when mixing blocks and lambdas.
The original reproduction case looked something like:

void foo(int *x)
{
  ^() {
    [&]() {
      return x == 0;
    }();
  }();
}

The following assert in 'clang::CodeGenFunction::EmitDeclRefLValue' was failing
because the variable declaration referenced in 'E' was not in the 'LocalDeclMap'
and was not marked as referring to an enclosing local:

      assert(isa<BlockDecl>(CurCodeDecl) && E->refersToEnclosingLocal());

This problem has been fixed by ensuring that the 'DeclRefExpr' gets marked as
referring to an enclosing local as it should be.

While investigating this issue I noticed that the reverse nesting fails too,
but for a different reason:

void foo(int *x)
{
  [&]() {
    ^() {
      return x == 0;
    }();
  }();
}

This time 'clang::CodeGen::CodeGenFunction::EmitBlockLiteral' goes to lookup
the capture information for the nested parameter 'x', but crashes because it
is actually nested in a lambda and the  'BlockInfo' is NULL.  This was fixed by
adding a check to ensure 'BlockInfo' is not NULL.

OK?

-- Meador

P.S.  If it is OK, then can someone commit for me?  (I don't have
commit rights.)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr12746.patch
Type: application/octet-stream
Size: 6185 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120508/bbdda394/attachment.obj>


More information about the cfe-commits mailing list