[cfe-commits] [patch] Fix crash when referring from a closure to an enclosing local in a function returning void

Nico Weber thakis at chromium.org
Wed Jul 11 08:35:15 PDT 2012


the attached patch fixes PR13314, clang crashing on code like this:

void f() {
  Foo foo;
  [=]() {
    return foo;

This crash was introduced in r152491, which replaced BlockDeclRefExpr
with a bit on DeclRefExpr. getCopyElisionCandidate() wasn't taught
about the new bit, so the the `return foo;` in the closure marks `foo`
as a NRVO candidate, but codegen for f() then looks at the return type
of f for NRVO. Since the function returns void, this results in a
failing assert somewhere down the line (see the bug for more details).
The attached patch makes getCopyElisionCandidate() ignore DeclRefExprs
that return to enclosing locals, which is I believe what happened
before r152491 too.



ps: A coworker tells me that this is a regression in the latest Xcode
DP, so you might want to merge the fix to the next Xcode release
-------------- next part --------------
A non-text attachment was scrubbed...
Name: clang-pr13314.patch
Type: application/octet-stream
Size: 1719 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120711/a5c36551/attachment.obj>

More information about the cfe-commits mailing list