Index: lib/Sema/SemaExpr.cpp =================================================================== --- lib/Sema/SemaExpr.cpp +++ lib/Sema/SemaExpr.cpp @@ -13477,13 +13477,16 @@ bool ByRef = false; // Blocks are not allowed to capture arrays. - if (CaptureType->isArrayType()) { - if (BuildAndDiagnose) { - S.Diag(Loc, diag::err_ref_array_type); - S.Diag(Var->getLocation(), diag::note_previous_decl) - << Var->getDeclName(); + // Only if it's not OpenCL 2.0. + if (!(S.getLangOpts().OpenCL && S.getLangOpts().OpenCLVersion >= 200)) { + if (CaptureType->isArrayType()) { + if (BuildAndDiagnose) { + S.Diag(Loc, diag::err_ref_array_type); + S.Diag(Var->getLocation(), diag::note_previous_decl) + << Var->getDeclName(); + } + return false; } - return false; } // Forbid the block-capture of autoreleasing variables. Index: test/SemaOpenCL/blocks_with_arrays.cl =================================================================== --- /dev/null +++ test/SemaOpenCL/blocks_with_arrays.cl @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -O0 -cl-std=CL2.0 -triple spir64-unkown-unkown -emit-llvm %s -o -| FileCheck %s + +typedef int (^block_t)(); + +int block_typedef_kernel(global int* res) { + int a[3] = {1, 2, 3}; + block_t b = ^() { +// CHECK: %{{.*}} = getelementptr inbounds [3 x i32], [3 x i32]* %{{.*}}, i64 0, i64 0 + return a[0]; + }; + return b(); +}