diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp index 0f6ceedb25cd..8fcec30c6a99 100644 --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/lib/CodeGen/CGDecl.cpp @@ -879,9 +879,25 @@ static bool isCapturedBy(const VarDecl &var, const Expr *e) { const CompoundStmt *CS = SE->getSubStmt(); for (CompoundStmt::const_body_iterator BI = CS->body_begin(), BE = CS->body_end(); BI != BE; ++BI) - if (Expr *E = dyn_cast((*BI))) + if (Expr *E = dyn_cast((*BI))) { if (isCapturedBy(var, E)) return true; + } + else if (DeclStmt *DS = dyn_cast((*BI))) { + // special case declarations + for (DeclStmt::decl_iterator I = DS->decl_begin(), E = DS->decl_end(); + I != E; ++I) { + if (VarDecl *VD = dyn_cast((*I))) { + Expr *Init = VD->getInit(); + if (Init && isCapturedBy(var, Init)) + return true; + } + } + } + else + // FIXME. Make safe assumption assuming arbitrary statements cause capturing. + // Later, provide code to poke into statements for capture analysis. + return true; return false; }