Re: [PATCH] D17436: [OpenCL] Add Sema checks for OpenCL 2.0 block

2016-02-23 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL261719: [OpenCL] Add Sema checks for OpenCL 2.0 block 
(authored by pxl).

Changed prior to commit:
  http://reviews.llvm.org/D17436?vs=48774=48880#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D17436

Files:
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/lib/Sema/SemaDecl.cpp
  cfe/trunk/lib/Sema/SemaExpr.cpp
  cfe/trunk/lib/Sema/SemaType.cpp
  cfe/trunk/test/SemaOpenCL/invalid-block.cl

Index: cfe/trunk/test/SemaOpenCL/invalid-block.cl
===
--- cfe/trunk/test/SemaOpenCL/invalid-block.cl
+++ cfe/trunk/test/SemaOpenCL/invalid-block.cl
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -verify -fblocks -cl-std=CL2.0 %s
+
+int (^BlkVariadic)(int, ...) = ^int(int I, ...) { // expected-error {{invalid block prototype, variadic arguments are not allowed in OpenCL}}
+  return 0;
+};
+
+typedef int (^BlkInt)(int);
+void f1(int i) {
+  BlkInt B1 = ^int(int I) {return 1;};
+  BlkInt B2 = ^int(int I) {return 2;};
+  BlkInt Arr[] = {B1, B2}; // expected-error {{array of 'BlkInt' (aka 'int (^)(int)') type is invalid in OpenCL}}
+  int tmp = i ? B1(i)  // expected-error {{block type cannot be used as expression in ternary expression in OpenCL}}
+  : B2(i); // expected-error {{block type cannot be used as expression in ternary expression in OpenCL}}
+}
+
+void f2(BlkInt *BlockPtr) {
+  BlkInt B = ^int(int I) {return 1;};
+  BlkInt *P =  // expected-error {{invalid argument type 'BlkInt' (aka 'int (^)(int)') to unary expression}}
+  B = *BlockPtr;  // expected-error {{dereferencing pointer of type '__generic BlkInt *' (aka 'int (^__generic *)(int)') is not allowed in OpenCL}}
+}
Index: cfe/trunk/lib/Sema/SemaType.cpp
===
--- cfe/trunk/lib/Sema/SemaType.cpp
+++ cfe/trunk/lib/Sema/SemaType.cpp
@@ -2175,6 +2175,15 @@
 Diag(Loc, diag::warn_vla_used);
   }
 
+  // OpenCL v2.0 s6.12.5 - Arrays of blocks are not supported.
+  if (getLangOpts().OpenCL) {
+const QualType ArrType = Context.getBaseElementType(T);
+if (ArrType->isBlockPointerType()) {
+  Diag(Loc, diag::err_opencl_invalid_type_array) << ArrType;
+  return QualType();
+}
+  }
+
   return T;
 }
 
Index: cfe/trunk/lib/Sema/SemaDecl.cpp
===
--- cfe/trunk/lib/Sema/SemaDecl.cpp
+++ cfe/trunk/lib/Sema/SemaDecl.cpp
@@ -6708,6 +6708,19 @@
 NewVD->setInvalidDecl();
 return;
   }
+
+  // OpenCL v2.0 s6.12.5 - Blocks with variadic arguments are not supported.
+  if (LangOpts.OpenCL && T->isBlockPointerType()) {
+const BlockPointerType *BlkTy = T->getAs();
+const FunctionProtoType *FTy =
+BlkTy->getPointeeType()->getAs();
+if (FTy->isVariadic()) {
+  Diag(NewVD->getLocation(), diag::err_opencl_block_proto_variadic)
+  << T << NewVD->getSourceRange();
+  NewVD->setInvalidDecl();
+  return;
+}
+  }
 }
 
 /// \brief Perform semantic checking on a newly-created variable
Index: cfe/trunk/lib/Sema/SemaExpr.cpp
===
--- cfe/trunk/lib/Sema/SemaExpr.cpp
+++ cfe/trunk/lib/Sema/SemaExpr.cpp
@@ -6458,6 +6458,18 @@
   return OpenCLConvertScalarsToVectors(S, LHS, RHS, CondTy, QuestionLoc);
 }
 
+/// \brief Return true if the Expr is block type
+static bool checkBlockType(Sema , const Expr *E) {
+  if (const CallExpr *CE = dyn_cast(E)) {
+QualType Ty = CE->getCallee()->getType();
+if (Ty->isBlockPointerType()) {
+  S.Diag(E->getExprLoc(), diag::err_opencl_ternary_with_block);
+  return true;
+}
+  }
+  return false;
+}
+
 /// Note that LHS is not null here, even if this is the gnu "x ?: y" extension.
 /// In that case, LHS = cond.
 /// C99 6.5.15
@@ -6507,6 +6519,13 @@
   QualType LHSTy = LHS.get()->getType();
   QualType RHSTy = RHS.get()->getType();
 
+  // OpenCL v2.0 s6.12.5 - Blocks cannot be used as expressions of the ternary
+  // selection operator (?:).
+  if (getLangOpts().OpenCL &&
+  (checkBlockType(*this, LHS.get()) | checkBlockType(*this, RHS.get( {
+return QualType();
+  }
+
   // If both operands have arithmetic type, do the usual arithmetic conversions
   // to find a common type: C99 6.5.15p3,5.
   if (LHSTy->isArithmeticType() && RHSTy->isArithmeticType()) {
@@ -10334,6 +10353,14 @@
   // If the operand has type "type", the result has type "pointer to type".
   if (op->getType()->isObjCObjectType())
 return Context.getObjCObjectPointerType(op->getType());
+
+  // OpenCL v2.0 s6.12.5 - The unary operators & cannot be used with a block.
+  if (getLangOpts().OpenCL && OrigOp.get()->getType()->isBlockPointerType()) {
+Diag(OpLoc, diag::err_typecheck_unary_expr) << OrigOp.get()->getType()
+<< op->getSourceRange();
+return QualType();
+  }
+
  

Re: [PATCH] D17436: [OpenCL] Add Sema checks for OpenCL 2.0 block

2016-02-23 Thread Anastasia Stulova via cfe-commits
Anastasia added inline comments.


Comment at: test/SemaOpenCL/invalid-block.cl:17
@@ +16,3 @@
+void f2(BlkInt *BlockPtr) {
+  BlkInt B = ^int(int I) {return 1;};
+  BlkInt *P =  // expected-error {{invalid argument type 'BlkInt' (aka 'int 
(^)(int)') to unary expression}}

Khronos bug: https://cvs.khronos.org/bugzilla/show_bug.cgi?id=15599


http://reviews.llvm.org/D17436



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D17436: [OpenCL] Add Sema checks for OpenCL 2.0 block

2016-02-23 Thread Anastasia Stulova via cfe-commits
Anastasia accepted this revision.
Anastasia added a comment.
This revision is now accepted and ready to land.

LGTM!


http://reviews.llvm.org/D17436



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D17436: [OpenCL] Add Sema checks for OpenCL 2.0 block

2016-02-22 Thread Xiuli PAN via cfe-commits
pxli168 added inline comments.


Comment at: lib/Sema/SemaDecl.cpp:6714
@@ +6713,3 @@
+  if (LangOpts.OpenCLVersion >= 200 && T->isBlockPointerType()) {
+const BlockPointerType *BlkTy = T->getAs();
+const FunctionProtoType *FTy =

Anastasia wrote:
> Yes, but you have to diagnose blocks correctly in all CL versions in which we 
> accept blocks. When you come to this point here you should only care about 
> checking whether blocks have variadic prototype or not. You should assume the 
> parser did the right job to either accept or reject the block declaration 
> earlier and also gave the right diagnostic.
> 
> It will be responsibility of a parser to correctly accept or reject blocks 
> depending on a version. I will prepare a patch for it later on. Please see my 
> related comment on the review: http://reviews.llvm.org/D16928 
I will change these, if we can restrict -fblock with -cl-std=CL2.x then there 
will be no problem by only checking LangOpts.OpenCL


Comment at: lib/Sema/SemaExpr.cpp:6509
@@ +6508,3 @@
+  return QualType();
+  }
+

Anastasia wrote:
> What is the implication of that? Will we get errors in different order then?
I think we should put operands check after condition check to keep the original 
logic.


http://reviews.llvm.org/D17436



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D17436: [OpenCL] Add Sema checks for OpenCL 2.0 block

2016-02-22 Thread Xiuli PAN via cfe-commits
pxli168 updated this revision to Diff 48774.

http://reviews.llvm.org/D17436

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaType.cpp
  test/SemaOpenCL/invalid-block.cl

Index: test/SemaOpenCL/invalid-block.cl
===
--- /dev/null
+++ test/SemaOpenCL/invalid-block.cl
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -verify -fblocks -cl-std=CL2.0 %s
+
+int (^BlkVariadic)(int, ...) = ^int(int I, ...) { // expected-error {{invalid block prototype, variadic arguments are not allowed in OpenCL}}
+  return 0;
+};
+
+typedef int (^BlkInt)(int);
+void f1(int i) {
+  BlkInt B1 = ^int(int I) {return 1;};
+  BlkInt B2 = ^int(int I) {return 2;};
+  BlkInt Arr[] = {B1, B2}; // expected-error {{array of 'BlkInt' (aka 'int (^)(int)') type is invalid in OpenCL}}
+  int tmp = i ? B1(i)  // expected-error {{block type cannot be used as expression in ternary expression in OpenCL}}
+  : B2(i); // expected-error {{block type cannot be used as expression in ternary expression in OpenCL}}
+}
+
+void f2(BlkInt *BlockPtr) {
+  BlkInt B = ^int(int I) {return 1;};
+  BlkInt *P =  // expected-error {{invalid argument type 'BlkInt' (aka 'int (^)(int)') to unary expression}}
+  B = *BlockPtr;  // expected-error {{dereferencing pointer of type '__generic BlkInt *' (aka 'int (^__generic *)(int)') is not allowed in OpenCL}}
+}
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -2175,6 +2175,15 @@
 Diag(Loc, diag::warn_vla_used);
   }
 
+  // OpenCL v2.0 s6.12.5 - Arrays of blocks are not supported.
+  if (getLangOpts().OpenCL) {
+const QualType ArrType = Context.getBaseElementType(T);
+if (ArrType->isBlockPointerType()) {
+  Diag(Loc, diag::err_opencl_invalid_type_array) << ArrType;
+  return QualType();
+}
+  }
+
   return T;
 }
 
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -6440,6 +6440,18 @@
   return OpenCLConvertScalarsToVectors(S, LHS, RHS, CondTy, QuestionLoc);
 }
 
+/// \brief Return true if the Expr is block type
+static bool checkBlockType(Sema , const Expr *E) {
+  if (const CallExpr *CE = dyn_cast(E)) {
+QualType Ty = CE->getCallee()->getType();
+if (Ty->isBlockPointerType()) {
+  S.Diag(E->getExprLoc(), diag::err_opencl_ternary_with_block);
+  return true;
+}
+  }
+  return false;
+}
+
 /// Note that LHS is not null here, even if this is the gnu "x ?: y" extension.
 /// In that case, LHS = cond.
 /// C99 6.5.15
@@ -6489,6 +6501,13 @@
   QualType LHSTy = LHS.get()->getType();
   QualType RHSTy = RHS.get()->getType();
 
+  // OpenCL v2.0 s6.12.5 - Blocks cannot be used as expressions of the ternary
+  // selection operator (?:).
+  if (getLangOpts().OpenCL &&
+  (checkBlockType(*this, LHS.get()) | checkBlockType(*this, RHS.get( {
+return QualType();
+  }
+
   // If both operands have arithmetic type, do the usual arithmetic conversions
   // to find a common type: C99 6.5.15p3,5.
   if (LHSTy->isArithmeticType() && RHSTy->isArithmeticType()) {
@@ -10237,6 +10256,14 @@
   // If the operand has type "type", the result has type "pointer to type".
   if (op->getType()->isObjCObjectType())
 return Context.getObjCObjectPointerType(op->getType());
+
+  // OpenCL v2.0 s6.12.5 - The unary operators & cannot be used with a block.
+  if (getLangOpts().OpenCL && OrigOp.get()->getType()->isBlockPointerType()) {
+Diag(OpLoc, diag::err_typecheck_unary_expr) << OrigOp.get()->getType()
+<< op->getSourceRange();
+return QualType();
+  }
+
   return Context.getPointerType(op->getType());
 }
 
@@ -10278,7 +10305,15 @@
   }
 
   if (const PointerType *PT = OpTy->getAs())
+  {
 Result = PT->getPointeeType();
+// OpenCL v2.0 s6.12.5 - The unary operators * cannot be used with a block.
+if (S.getLangOpts().OpenCLVersion >= 200 && Result->isBlockPointerType()) {
+  S.Diag(OpLoc, diag::err_opencl_dereferencing) << OpTy
+<< Op->getSourceRange();
+  return QualType();
+}
+  }
   else if (const ObjCObjectPointerType *OPT =
  OpTy->getAs())
 Result = OPT->getPointeeType();
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -6708,6 +6708,19 @@
 NewVD->setInvalidDecl();
 return;
   }
+
+  // OpenCL v2.0 s6.12.5 - Blocks with variadic arguments are not supported.
+  if (LangOpts.OpenCL && T->isBlockPointerType()) {
+const BlockPointerType *BlkTy = T->getAs();
+const FunctionProtoType *FTy =
+BlkTy->getPointeeType()->getAs();
+if (FTy->isVariadic()) {
+  Diag(NewVD->getLocation(), 

Re: [PATCH] D17436: [OpenCL] Add Sema checks for OpenCL 2.0 block

2016-02-22 Thread Anastasia Stulova via cfe-commits
Anastasia added inline comments.


Comment at: lib/Sema/SemaDecl.cpp:6714
@@ +6713,3 @@
+  if (LangOpts.OpenCLVersion >= 200 && T->isBlockPointerType()) {
+const BlockPointerType *BlkTy = T->getAs();
+const FunctionProtoType *FTy =

Yes, but you have to diagnose blocks correctly in all CL versions in which we 
accept blocks. When you come to this point here you should only care about 
checking whether blocks have variadic prototype or not. You should assume the 
parser did the right job to either accept or reject the block declaration 
earlier and also gave the right diagnostic.

It will be responsibility of a parser to correctly accept or reject blocks 
depending on a version. I will prepare a patch for it later on. Please see my 
related comment on the review: http://reviews.llvm.org/D16928 


Comment at: lib/Sema/SemaExpr.cpp:6509
@@ +6508,3 @@
+  return QualType();
+  }
+

What is the implication of that? Will we get errors in different order then?


http://reviews.llvm.org/D17436



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D17436: [OpenCL] Add Sema checks for OpenCL 2.0 block

2016-02-21 Thread Xiuli PAN via cfe-commits
pxli168 updated this revision to Diff 48648.

http://reviews.llvm.org/D17436

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaType.cpp
  test/SemaOpenCL/invalid-block.cl

Index: test/SemaOpenCL/invalid-block.cl
===
--- /dev/null
+++ test/SemaOpenCL/invalid-block.cl
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -verify -fblocks -cl-std=CL2.0 %s
+
+int (^BlkVariadic)(int, ...) = ^int(int I, ...) { // expected-error {{invalid block prototype, variadic arguments are not allowed in OpenCL}}
+  return 0;
+};
+
+typedef int (^BlkInt)(int);
+void f1(int i) {
+  BlkInt B1 = ^int(int I) {return 1;};
+  BlkInt B2 = ^int(int I) {return 2;};
+  BlkInt Arr[] = {B1, B2}; // expected-error {{array of block type is invalid in OpenCL}}
+  int tmp = i ? B1(i)  // expected-error {{block type cannot be used as expression in ternary expression in OpenCL}}
+  : B2(i); // expected-error {{block type cannot be used as expression in ternary expression in OpenCL}}
+}
+
+void f2(BlkInt *BlockPtr) {
+  BlkInt B = ^int(int I) {return 1;};
+  BlkInt *P =  // expected-error {{invalid argument type 'BlkInt' (aka 'int (^)(int)') to unary expression}}
+  B = *BlockPtr;  // expected-error {{dereferencing pointer of type '__generic BlkInt *' (aka 'int (^__generic *)(int)') is not allowed in OpenCL}}
+}
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -2175,6 +2175,13 @@
 Diag(Loc, diag::warn_vla_used);
   }
 
+  // OpenCL v2.0 s6.12.5 - Arrays of blocks are not supported.
+  if (getLangOpts().OpenCLVersion >= 200 &&
+  Context.getBaseElementType(T)->isBlockPointerType()) {
+Diag(Loc, diag::err_opencl_invalid_block_array);
+return QualType();
+  }
+
   return T;
 }
 
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -6440,6 +6440,18 @@
   return OpenCLConvertScalarsToVectors(S, LHS, RHS, CondTy, QuestionLoc);
 }
 
+/// \brief Return true if the Expr is block type
+static bool checkBlockType(Sema , const Expr *E) {
+  if (const CallExpr *CE = dyn_cast(E)) {
+QualType Ty = CE->getCallee()->getType();
+if (Ty->isBlockPointerType()) {
+  S.Diag(E->getExprLoc(), diag::err_opencl_ternary_with_block);
+  return true;
+}
+  }
+  return false;
+}
+
 /// Note that LHS is not null here, even if this is the gnu "x ?: y" extension.
 /// In that case, LHS = cond.
 /// C99 6.5.15
@@ -6489,6 +6501,13 @@
   QualType LHSTy = LHS.get()->getType();
   QualType RHSTy = RHS.get()->getType();
 
+  // OpenCL v2.0 s6.12.5 - Blocks cannot be used as expressions of the ternary
+  // selection operator (?:).
+  if (getLangOpts().OpenCLVersion >= 200) {
+if (checkBlockType(*this, LHS.get()) | checkBlockType(*this, RHS.get()))
+  return QualType();
+  }
+
   // If both operands have arithmetic type, do the usual arithmetic conversions
   // to find a common type: C99 6.5.15p3,5.
   if (LHSTy->isArithmeticType() && RHSTy->isArithmeticType()) {
@@ -10237,6 +10256,16 @@
   // If the operand has type "type", the result has type "pointer to type".
   if (op->getType()->isObjCObjectType())
 return Context.getObjCObjectPointerType(op->getType());
+
+  // OpenCL v2.0 s6.12.5 - The unary operators & cannot be used with a block.
+  if (getLangOpts().OpenCLVersion >= 200) {
+if (OrigOp.get()->getType()->isBlockPointerType()) {
+  Diag(OpLoc, diag::err_typecheck_unary_expr) << OrigOp.get()->getType()
+  << op->getSourceRange();
+  return QualType();
+}
+  }
+
   return Context.getPointerType(op->getType());
 }
 
@@ -10278,7 +10307,15 @@
   }
 
   if (const PointerType *PT = OpTy->getAs())
+  {
 Result = PT->getPointeeType();
+// OpenCL v2.0 s6.12.5 - The unary operators * cannot be used with a block.
+if (S.getLangOpts().OpenCLVersion >= 200 && Result->isBlockPointerType()) {
+  S.Diag(OpLoc, diag::err_opencl_dereferencing) << OpTy
+<< Op->getSourceRange();
+  return QualType();
+}
+  }
   else if (const ObjCObjectPointerType *OPT =
  OpTy->getAs())
 Result = OPT->getPointeeType();
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -6708,6 +6708,19 @@
 NewVD->setInvalidDecl();
 return;
   }
+
+  // OpenCL v2.0 s6.12.5 - Blocks with variadic arguments are not supported.
+  if (LangOpts.OpenCLVersion >= 200 && T->isBlockPointerType()) {
+const BlockPointerType *BlkTy = T->getAs();
+const FunctionProtoType *FTy =
+BlkTy->getPointeeType()->getAs();
+if (FTy->isVariadic()) {
+  Diag(NewVD->getLocation(), 

Re: [PATCH] D17436: [OpenCL] Add Sema checks for OpenCL 2.0 block

2016-02-21 Thread Xiuli PAN via cfe-commits
pxli168 marked 11 inline comments as done.
pxli168 added a comment.

Block is an OpenCL v2.0 feature, I think all test should be handled only for 
CL2.0 or newer version.



Comment at: lib/Sema/SemaDecl.cpp:6714
@@ +6713,3 @@
+  // supported in OpenCL C: Blocks with variadic arguments.
+  if (getLangOpts().OpenCL && LangOpts.OpenCLVersion >= 200 &&
+  T->isBlockPointerType()) {

Anastasia wrote:
> getLangOpts() -> LangOpts
> 
> Could you remove 'LangOpts.OpenCLVersion >= 200' because we can also enable 
> Blocks with -fblocks flag.
But this is a OpenCL v2.0 restriction, if we do not check about OpenCL version 
it seems meaningless.


Comment at: lib/Sema/SemaExpr.cpp:6525
@@ +6524,3 @@
+// should output error for both LHS and RHS, use | instead ||
+if (checkBlockType(*this, LHS.get()) | checkBlockType(*this, RHS.get()))
+  return QualType();

Anastasia wrote:
> I suggest to unify with another check for OpenCL on line 6497 to have OpenCL 
> bits all in one place.
It seems move it to there may change the order of checking condition first.


Comment at: test/SemaOpenCL/invalid-block.cl:16
@@ +15,3 @@
+
+void f2(BlkInt *BlockPtr) {
+  BlkInt B = ^int(int I) {return 1;};

Anastasia wrote:
> Actually I think pointers to blocks have to be disallowed too, but spec 
> doesn't mention that although it forbids the dereferencing.
> 
> I will submit a bug to Khronos to clarify this.
I think it is reasonable, please add me in cc list. I will try to make a change 
here. But this may make deference test case hard to write.

BTW, the qualifier to workgroup pipe builtin functions is resolved by 
https://cvs.khronos.org/bugzilla/show_bug.cgi?id=15541.



http://reviews.llvm.org/D17436



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D17436: [OpenCL] Add Sema checks for OpenCL 2.0 block

2016-02-19 Thread Anastasia Stulova via cfe-commits
Anastasia added inline comments.


Comment at: include/clang/Basic/DiagnosticSemaKinds.td:7719
@@ +7718,3 @@
+def err_opencl_block_proto_variadic : Error<
+  "invalid block prototype, variadic arguments are not allowed in opencl">;
+def err_opencl_invalid_block_array : Error<

opencl -> OpenCL


Comment at: include/clang/Basic/DiagnosticSemaKinds.td:7723
@@ -7716,1 +7722,3 @@
+def err_opencl_ternary_with_block : Error<
+  "blocks cannot be used as expressions in ternary expressions in opencl">;
 

opencl -> OpenCL


Comment at: lib/Sema/SemaDecl.cpp:6712
@@ +6711,3 @@
+
+  // OpenCL v2.0 s6.12.5 - The following Blocks features are currently not
+  // supported in OpenCL C: Blocks with variadic arguments.

Could you write it a bit shorter, may be: Blocks with variadic arguments are 
not allowed.


Comment at: lib/Sema/SemaDecl.cpp:6714
@@ +6713,3 @@
+  // supported in OpenCL C: Blocks with variadic arguments.
+  if (getLangOpts().OpenCL && LangOpts.OpenCLVersion >= 200 &&
+  T->isBlockPointerType()) {

getLangOpts() -> LangOpts

Could you remove 'LangOpts.OpenCLVersion >= 200' because we can also enable 
Blocks with -fblocks flag.


Comment at: lib/Sema/SemaDecl.cpp:6717
@@ +6716,3 @@
+const BlockPointerType *BlkTy = T->getAs();
+assert(BlkTy && "Not a block pointer.");
+

This seems redundant with T->isBlockPointerType() from above


Comment at: lib/Sema/SemaExpr.cpp:6520
@@ -6507,1 +6519,3 @@
 
+  // OpenCL v2.0 s6.12.5 - To support these behaviors, additional
+  // restrictions in addition to the above feature restrictions are: Blocks

Can you shorten this comment too. I would just remove:  "To support these 
behaviors, additional restrictions in addition to the above feature 
restrictions are:".


Comment at: lib/Sema/SemaExpr.cpp:6523
@@ +6522,3 @@
+  // cannot be used as expressions of the ternary selection operator (?:).
+  if (getLangOpts().OpenCL && getLangOpts().OpenCLVersion >= 200) {
+// should output error for both LHS and RHS, use | instead ||

Also could you remove 'getLangOpts().OpenCLVersion >= 200', see similar comment 
above.


Comment at: lib/Sema/SemaExpr.cpp:6525
@@ +6524,3 @@
+// should output error for both LHS and RHS, use | instead ||
+if (checkBlockType(*this, LHS.get()) | checkBlockType(*this, RHS.get()))
+  return QualType();

I suggest to unify with another check for OpenCL on line 6497 to have OpenCL 
bits all in one place.


Comment at: lib/Sema/SemaExpr.cpp:10358
@@ +10357,3 @@
+  // OpenCL v2.0 s6.12.5 - The unary operators (* and &) cannot be used with a
+  // Block
+  if (getLangOpts().OpenCL && getLangOpts().OpenCLVersion >= 200) {

Block -> block


Comment at: lib/Sema/SemaExpr.cpp:10359
@@ +10358,3 @@
+  // Block
+  if (getLangOpts().OpenCL && getLangOpts().OpenCLVersion >= 200) {
+if (OrigOp.get()->getType()->isBlockPointerType()) {

Could you remove 'getLangOpts().OpenCLVersion >= 200' here too!


Comment at: lib/Sema/SemaExpr.cpp:10411
@@ +10410,3 @@
+// OpenCL v2.0 s6.12.5 - The unary operators (* and &) cannot be used with 
a
+// Block.
+if (S.getLangOpts().OpenCL && S.getLangOpts().OpenCLVersion >= 200 &&

Block -> block


Comment at: lib/Sema/SemaType.cpp:2178
@@ -2177,1 +2177,3 @@
 
+  // OpenCL v2.0 s6.12.5 - The following Blocks features are currently not
+  // supported in OpenCL C: Arrays of Blocks.

Could you change to "Arrays of blocks are not supported.".




Comment at: test/SemaOpenCL/invalid-block.cl:11
@@ +10,3 @@
+  BlkInt B2 = ^int(int I) {return 2;};
+  BlkInt Arr[] = {B1, B2}; // expected-error {{array of block is invalid in 
OpenCL}}
+  int tmp = i ? B1(i)  // expected-error {{blocks cannot be used as 
expressions in ternary expressions}}

array of block type ...


Comment at: test/SemaOpenCL/invalid-block.cl:12
@@ +11,3 @@
+  BlkInt Arr[] = {B1, B2}; // expected-error {{array of block is invalid in 
OpenCL}}
+  int tmp = i ? B1(i)  // expected-error {{blocks cannot be used as 
expressions in ternary expressions}}
+  : B2(i); // expected-error {{blocks cannot be used as 
expressions in ternary expressions}}

block type cannot ...


Comment at: test/SemaOpenCL/invalid-block.cl:13
@@ +12,3 @@
+  int tmp = i ? B1(i)  // expected-error {{blocks cannot be used as 
expressions in ternary expressions}}
+  : B2(i); // expected-error {{blocks cannot be used as 
expressions in ternary expressions}}
+}

block type cannot ...


Comment at: test/SemaOpenCL/invalid-block.cl:16
@@ +15,3