r302125 - [OpenCL] Add intel_reqd_sub_group_size attribute support

2017-05-04 Thread Xiuli Pan via cfe-commits
Author: pxl
Date: Thu May  4 02:31:20 2017
New Revision: 302125

URL: http://llvm.org/viewvc/llvm-project?rev=302125=rev
Log:
[OpenCL] Add intel_reqd_sub_group_size attribute support

Summary:
Add intel_reqd_sub_group_size attribute support as intel extension  
cl_intel_required_subgroup_size from
https://www.khronos.org/registry/OpenCL/extensions/intel/cl_intel_required_subgroup_size.txt

Reviewers: Anastasia, bader, hfinkel, pxli168

Reviewed By: Anastasia, bader, pxli168

Subscribers: cfe-commits, yaxunl

Differential Revision: https://reviews.llvm.org/D30805

Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/include/clang/Basic/AttrDocs.td
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/test/CodeGenOpenCL/kernel-attributes.cl
cfe/trunk/test/Misc/pragma-attribute-supported-attributes-list.test
cfe/trunk/test/SemaOpenCL/invalid-kernel-attrs.cl

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=302125=302124=302125=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Thu May  4 02:31:20 2017
@@ -864,6 +864,13 @@ def OpenCLUnrollHint : InheritableAttr {
   let Documentation = [OpenCLUnrollHintDocs];
 }
 
+def OpenCLIntelReqdSubGroupSize: InheritableAttr {
+  let Spellings = [GNU<"intel_reqd_sub_group_size">];
+  let Args = [UnsignedArgument<"SubGroupSize">];
+  let Subjects = SubjectList<[Function], ErrorDiag>;
+  let Documentation = [OpenCLIntelReqdSubGroupSizeDocs];
+}
+
 // This attribute is both a type attribute, and a declaration attribute (for
 // parameter variables).
 def OpenCLAccess : Attr {

Modified: cfe/trunk/include/clang/Basic/AttrDocs.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/AttrDocs.td?rev=302125=302124=302125=diff
==
--- cfe/trunk/include/clang/Basic/AttrDocs.td (original)
+++ cfe/trunk/include/clang/Basic/AttrDocs.td Thu May  4 02:31:20 2017
@@ -2216,6 +2216,21 @@ s6.11.5 for details.
   }];
 }
 
+def OpenCLIntelReqdSubGroupSizeDocs : Documentation {
+  let Category = DocCatStmt;
+  let Heading = "__attribute__((intel_reqd_sub_group_size))";
+  let Content = [{
+The optional attribute intel_reqd_sub_group_size can be used to indicate that
+the kernel must be compiled and executed with the specified subgroup size. When
+this attribute is present, get_max_sub_group_size() is guaranteed to return the
+specified integer value. This is important for the correctness of many subgroup
+algorithms, and in some cases may be used by the compiler to generate more 
optimal
+code. See `cl_intel_required_subgroup_size
+`
+for details.
+  }];
+}
+
 def OpenCLAccessDocs : Documentation {
   let Category = DocCatStmt;
   let Heading = "__read_only, __write_only, __read_write (read_only, 
write_only, read_write)";

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=302125=302124=302125=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Thu May  4 02:31:20 2017
@@ -658,34 +658,42 @@ void CodeGenFunction::EmitOpenCLKernelMe
   GenOpenCLArgMetadata(FD, Fn, CGM, Context, Builder, getContext());
 
   if (const VecTypeHintAttr *A = FD->getAttr()) {
-QualType hintQTy = A->getTypeHint();
-const ExtVectorType *hintEltQTy = hintQTy->getAs();
-bool isSignedInteger =
-hintQTy->isSignedIntegerType() ||
-(hintEltQTy && hintEltQTy->getElementType()->isSignedIntegerType());
-llvm::Metadata *attrMDArgs[] = {
+QualType HintQTy = A->getTypeHint();
+const ExtVectorType *HintEltQTy = HintQTy->getAs();
+bool IsSignedInteger =
+HintQTy->isSignedIntegerType() ||
+(HintEltQTy && HintEltQTy->getElementType()->isSignedIntegerType());
+llvm::Metadata *AttrMDArgs[] = {
 llvm::ConstantAsMetadata::get(llvm::UndefValue::get(
 CGM.getTypes().ConvertType(A->getTypeHint(,
 llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
 llvm::IntegerType::get(Context, 32),
-llvm::APInt(32, (uint64_t)(isSignedInteger ? 1 : 0};
-Fn->setMetadata("vec_type_hint", llvm::MDNode::get(Context, attrMDArgs));
+llvm::APInt(32, (uint64_t)(IsSignedInteger ? 1 : 0};
+Fn->setMetadata("vec_type_hint", llvm::MDNode::get(Context, AttrMDArgs));
   }
 
   if (const WorkGroupSizeHintAttr *A = FD->getAttr()) {
-llvm::Metadata *attrMDArgs[] = {
+llvm::Metadata *AttrMDArgs[] = 

Re: [PATCH] D21744: [OpenCL] Fix code generation of kernel pipe parameters.

2016-07-11 Thread Xiuli PAN via cfe-commits
pxli168 accepted this revision.
pxli168 added a comment.

Sorry for the late reply, I was busy with some backend problem.
LGTM, thanks for the fix!


http://reviews.llvm.org/D21744



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


Re: [PATCH] D20133: [OpenCL] Fix __builtin_astype for vec3 types.

2016-06-11 Thread Xiuli PAN via cfe-commits
pxli168 added a comment.

I was on a vecation. LGTM, thanks!


Repository:
  rL LLVM

http://reviews.llvm.org/D20133



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


r271978 - [OPENCL] Fix wrongly vla error for OpenCL array.

2016-06-06 Thread Xiuli Pan via cfe-commits
Author: pxl
Date: Mon Jun  6 23:34:00 2016
New Revision: 271978

URL: http://llvm.org/viewvc/llvm-project?rev=271978=rev
Log:
[OPENCL] Fix wrongly vla error for OpenCL array.

Summary:
OpenCL should support array with const value size length, those const
varibale in global and constant address space and variable in constant
address space.

Fixed test case error.

Reviewers: Anastasia, yaxunl, bader

Subscribers: bader, cfe-commits

Differential Revision: http://reviews.llvm.org/D20090

Added:
cfe/trunk/test/CodeGenOpenCL/vla.cl
Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/Sema/SemaType.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=271978=271977=271978=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Mon Jun  6 23:34:00 2016
@@ -2745,7 +2745,10 @@ static CompleteObject findCompleteObject
   } else if (VD->isConstexpr()) {
 // OK, we can read this variable.
   } else if (BaseType->isIntegralOrEnumerationType()) {
-if (!BaseType.isConstQualified()) {
+// In OpenCL if a variable is in constant address space it is a const 
value.
+if (!(BaseType.isConstQualified() ||
+  (Info.getLangOpts().OpenCL &&
+   BaseType.getAddressSpace() == LangAS::opencl_constant))) {
   if (Info.getLangOpts().CPlusPlus) {
 Info.Diag(E, diag::note_constexpr_ltor_non_const_int, 1) << VD;
 Info.Note(VD->getLocation(), diag::note_declared_at);

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=271978=271977=271978=diff
==
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Mon Jun  6 23:34:00 2016
@@ -2063,7 +2063,8 @@ static bool isArraySizeVLA(Sema , Expr
   } Diagnoser;
 
   return S.VerifyIntegerConstantExpression(ArraySize, , Diagnoser,
-   S.LangOpts.GNUMode).isInvalid();
+   S.LangOpts.GNUMode ||
+   S.LangOpts.OpenCL).isInvalid();
 }
 
 /// \brief Build an array type.

Added: cfe/trunk/test/CodeGenOpenCL/vla.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/vla.cl?rev=271978=auto
==
--- cfe/trunk/test/CodeGenOpenCL/vla.cl (added)
+++ cfe/trunk/test/CodeGenOpenCL/vla.cl Mon Jun  6 23:34:00 2016
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -emit-llvm -triple "spir-unknown-unknown" -O0 -cl-std=CL2.0 
-o - %s | FileCheck %s
+
+constant int sz0 = 5;
+// CHECK: @sz0 = addrspace(2) constant i32 5
+const global int sz1 = 16;
+// CHECK: @sz1 = addrspace(1) constant i32 16
+const constant int sz2 = 8;
+// CHECK: @sz2 = addrspace(2) constant i32 8
+// CHECK: @testvla.vla2 = internal addrspace(3) global [8 x i16] undef
+
+kernel void testvla()
+{
+  int vla0[sz0];
+// CHECK: %vla0 = alloca [5 x i32]
+  char vla1[sz1];
+// CHECK: %vla1 = alloca [16 x i8]
+  local short vla2[sz2];
+}


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


r271975 - Revert "[OPENCL] Fix wrongly vla error for OpenCL array."

2016-06-06 Thread Xiuli Pan via cfe-commits
Author: pxl
Date: Mon Jun  6 22:41:07 2016
New Revision: 271975

URL: http://llvm.org/viewvc/llvm-project?rev=271975=rev
Log:
Revert "[OPENCL] Fix wrongly vla error for OpenCL array."

Test case break on system-z.

This reverts commit 9a7212e1e87f1396952d74f8c62314a775ccbb1c.

Removed:
cfe/trunk/test/CodeGenOpenCL/vla.cl
Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/Sema/SemaType.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=271975=271974=271975=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Mon Jun  6 22:41:07 2016
@@ -2745,10 +2745,7 @@ static CompleteObject findCompleteObject
   } else if (VD->isConstexpr()) {
 // OK, we can read this variable.
   } else if (BaseType->isIntegralOrEnumerationType()) {
-// In OpenCL if a variable is in constant address space it is a const 
value.
-if (!(BaseType.isConstQualified() ||
-  (Info.getLangOpts().OpenCL &&
-   BaseType.getAddressSpace() == LangAS::opencl_constant))) {
+if (!BaseType.isConstQualified()) {
   if (Info.getLangOpts().CPlusPlus) {
 Info.Diag(E, diag::note_constexpr_ltor_non_const_int, 1) << VD;
 Info.Note(VD->getLocation(), diag::note_declared_at);

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=271975=271974=271975=diff
==
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Mon Jun  6 22:41:07 2016
@@ -2063,8 +2063,7 @@ static bool isArraySizeVLA(Sema , Expr
   } Diagnoser;
 
   return S.VerifyIntegerConstantExpression(ArraySize, , Diagnoser,
-   S.LangOpts.GNUMode ||
-   S.LangOpts.OpenCL).isInvalid();
+   S.LangOpts.GNUMode).isInvalid();
 }
 
 /// \brief Build an array type.

Removed: cfe/trunk/test/CodeGenOpenCL/vla.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/vla.cl?rev=271974=auto
==
--- cfe/trunk/test/CodeGenOpenCL/vla.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/vla.cl (removed)
@@ -1,18 +0,0 @@
-// RUN: %clang_cc1 -emit-llvm -O0 -cl-std=CL2.0 -o - %s | FileCheck %s
-
-constant int sz0 = 5;
-// CHECK: @sz0 = constant i32 5, align 4
-const global int sz1 = 16;
-// CHECK: @sz1 = constant i32 16, align 4
-const constant int sz2 = 8;
-// CHECK: @sz2 = constant i32 8, align 4
-// CHECK: @testvla.vla2 = internal global [8 x i16] undef, align 16
-
-kernel void testvla()
-{
-  int vla0[sz0];
-// CHECK: %vla0 = alloca [5 x i32], align 16
-  char vla1[sz1];
-// CHECK: %vla1 = alloca [16 x i8], align 16
-  local short vla2[sz2];
-}


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


r271971 - [OPENCL] Fix wrongly vla error for OpenCL array.

2016-06-06 Thread Xiuli Pan via cfe-commits
Author: pxl
Date: Mon Jun  6 22:13:39 2016
New Revision: 271971

URL: http://llvm.org/viewvc/llvm-project?rev=271971=rev
Log:
[OPENCL] Fix wrongly vla error for OpenCL array.

Summary:
OpenCL should support array with const value size length, those const varibale 
in global and constant address space and variable in constant address space.

Reviewers: Anastasia, yaxunl, bader

Subscribers: bader, cfe-commits

Differential Revision: http://reviews.llvm.org/D20090

Added:
cfe/trunk/test/CodeGenOpenCL/vla.cl
Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/Sema/SemaType.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=271971=271970=271971=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Mon Jun  6 22:13:39 2016
@@ -2745,7 +2745,10 @@ static CompleteObject findCompleteObject
   } else if (VD->isConstexpr()) {
 // OK, we can read this variable.
   } else if (BaseType->isIntegralOrEnumerationType()) {
-if (!BaseType.isConstQualified()) {
+// In OpenCL if a variable is in constant address space it is a const 
value.
+if (!(BaseType.isConstQualified() ||
+  (Info.getLangOpts().OpenCL &&
+   BaseType.getAddressSpace() == LangAS::opencl_constant))) {
   if (Info.getLangOpts().CPlusPlus) {
 Info.Diag(E, diag::note_constexpr_ltor_non_const_int, 1) << VD;
 Info.Note(VD->getLocation(), diag::note_declared_at);

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=271971=271970=271971=diff
==
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Mon Jun  6 22:13:39 2016
@@ -2063,7 +2063,8 @@ static bool isArraySizeVLA(Sema , Expr
   } Diagnoser;
 
   return S.VerifyIntegerConstantExpression(ArraySize, , Diagnoser,
-   S.LangOpts.GNUMode).isInvalid();
+   S.LangOpts.GNUMode ||
+   S.LangOpts.OpenCL).isInvalid();
 }
 
 /// \brief Build an array type.

Added: cfe/trunk/test/CodeGenOpenCL/vla.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/vla.cl?rev=271971=auto
==
--- cfe/trunk/test/CodeGenOpenCL/vla.cl (added)
+++ cfe/trunk/test/CodeGenOpenCL/vla.cl Mon Jun  6 22:13:39 2016
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -emit-llvm -O0 -cl-std=CL2.0 -o - %s | FileCheck %s
+
+constant int sz0 = 5;
+// CHECK: @sz0 = constant i32 5, align 4
+const global int sz1 = 16;
+// CHECK: @sz1 = constant i32 16, align 4
+const constant int sz2 = 8;
+// CHECK: @sz2 = constant i32 8, align 4
+// CHECK: @testvla.vla2 = internal global [8 x i16] undef, align 16
+
+kernel void testvla()
+{
+  int vla0[sz0];
+// CHECK: %vla0 = alloca [5 x i32], align 16
+  char vla1[sz1];
+// CHECK: %vla1 = alloca [16 x i8], align 16
+  local short vla2[sz2];
+}


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


Re: [PATCH] D20090: [OPENCL] Fix wrongly vla error for OpenCL array.

2016-05-29 Thread Xiuli PAN via cfe-commits
pxli168 updated this revision to Diff 58932.
pxli168 added a comment.

Make all tests in OpenCL 2.0.


http://reviews.llvm.org/D20090

Files:
  lib/AST/ExprConstant.cpp
  lib/Sema/SemaType.cpp
  test/CodeGenOpenCL/vla.cl

Index: test/CodeGenOpenCL/vla.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/vla.cl
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -emit-llvm -O0 -cl-std=CL2.0 -o - %s | FileCheck %s
+
+constant int sz0 = 5;
+// CHECK: @sz0 = constant i32 5, align 4
+const global int sz1 = 16;
+// CHECK: @sz1 = constant i32 16, align 4
+const constant int sz2 = 8;
+// CHECK: @sz2 = constant i32 8, align 4
+// CHECK: @testvla.vla2 = internal global [8 x i16] undef, align 16
+
+kernel void testvla()
+{
+  int vla0[sz0];
+// CHECK: %vla0 = alloca [5 x i32], align 16
+  char vla1[sz1];
+// CHECK: %vla1 = alloca [16 x i8], align 16
+  local short vla2[sz2];
+}
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -2063,7 +2063,8 @@
   } Diagnoser;
 
   return S.VerifyIntegerConstantExpression(ArraySize, , Diagnoser,
-   S.LangOpts.GNUMode).isInvalid();
+   S.LangOpts.GNUMode ||
+   S.LangOpts.OpenCL).isInvalid();
 }
 
 /// \brief Build an array type.
Index: lib/AST/ExprConstant.cpp
===
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -2740,7 +2740,10 @@
   } else if (VD->isConstexpr()) {
 // OK, we can read this variable.
   } else if (BaseType->isIntegralOrEnumerationType()) {
-if (!BaseType.isConstQualified()) {
+// In OpenCL if a variable is in constant address space it is a const 
value.
+if (!(BaseType.isConstQualified() ||
+  (Info.getLangOpts().OpenCL &&
+   BaseType.getAddressSpace() == LangAS::opencl_constant))) {
   if (Info.getLangOpts().CPlusPlus) {
 Info.Diag(E, diag::note_constexpr_ltor_non_const_int, 1) << VD;
 Info.Note(VD->getLocation(), diag::note_declared_at);


Index: test/CodeGenOpenCL/vla.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/vla.cl
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -emit-llvm -O0 -cl-std=CL2.0 -o - %s | FileCheck %s
+
+constant int sz0 = 5;
+// CHECK: @sz0 = constant i32 5, align 4
+const global int sz1 = 16;
+// CHECK: @sz1 = constant i32 16, align 4
+const constant int sz2 = 8;
+// CHECK: @sz2 = constant i32 8, align 4
+// CHECK: @testvla.vla2 = internal global [8 x i16] undef, align 16
+
+kernel void testvla()
+{
+  int vla0[sz0];
+// CHECK: %vla0 = alloca [5 x i32], align 16
+  char vla1[sz1];
+// CHECK: %vla1 = alloca [16 x i8], align 16
+  local short vla2[sz2];
+}
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -2063,7 +2063,8 @@
   } Diagnoser;
 
   return S.VerifyIntegerConstantExpression(ArraySize, , Diagnoser,
-   S.LangOpts.GNUMode).isInvalid();
+   S.LangOpts.GNUMode ||
+   S.LangOpts.OpenCL).isInvalid();
 }
 
 /// \brief Build an array type.
Index: lib/AST/ExprConstant.cpp
===
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -2740,7 +2740,10 @@
   } else if (VD->isConstexpr()) {
 // OK, we can read this variable.
   } else if (BaseType->isIntegralOrEnumerationType()) {
-if (!BaseType.isConstQualified()) {
+// In OpenCL if a variable is in constant address space it is a const value.
+if (!(BaseType.isConstQualified() ||
+  (Info.getLangOpts().OpenCL &&
+   BaseType.getAddressSpace() == LangAS::opencl_constant))) {
   if (Info.getLangOpts().CPlusPlus) {
 Info.Diag(E, diag::note_constexpr_ltor_non_const_int, 1) << VD;
 Info.Note(VD->getLocation(), diag::note_declared_at);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20444: [OpenCL] Include opencl-c.h by default as a clang module

2016-05-29 Thread Xiuli PAN via cfe-commits
pxli168 accepted this revision.
pxli168 added a comment.
This revision is now accepted and ready to land.

LGTM!
Thanks!


http://reviews.llvm.org/D20444



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


Re: [PATCH] D20090: [OPENCL] Fix wrongly vla error for OpenCL array.

2016-05-26 Thread Xiuli PAN via cfe-commits
pxli168 added inline comments.


Comment at: lib/Sema/SemaType.cpp:2055
@@ -2054,3 +2054,3 @@
 
-  return S.VerifyIntegerConstantExpression(ArraySize, , Diagnoser,
-   S.LangOpts.GNUMode).isInvalid();
+  return S
+  .VerifyIntegerConstantExpression(ArraySize, , Diagnoser,

Anastasia wrote:
> pxli168 wrote:
> > Anastasia wrote:
> > > Formatting looks weird though... may be better to leave the first line 
> > > unmodified?
> > I felt very strange, too. But this is what clang-format gives me.
> I see. clang-format doesn't take readability into account unfortunately. :)
> 
> Let's just leave the first line of this change unmodified at least to make it 
> more readable.
OK, I also found the clang-format can do some strange thing.


Comment at: test/CodeGenOpenCL/vla.cl:1
@@ +1,2 @@
+// RUN: %clang_cc1 -emit-llvm -O0 -o - %s | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -O0 -cl-std=CL2.0 -DCL20 -o - %s | FileCheck %s 
--check-prefix=CL20

Anastasia wrote:
> pxli168 wrote:
> > Anastasia wrote:
> > > Could we have a Sema test instead where we accept the VLA if constant AS 
> > > object is used and give an error otherwise?
> > > 
> > > Also do we need to test CL2.0? We don't seem to be doing anything 
> > > different for that version. 
> > In earier than OpenCL1.2  program scope variable must reside in constant 
> > address space and no
> > ```
> > const global int
> > ```
> > can be here.
> > But const global value should also not be seen as VLA either.
> Why not? Could you write a complete example perhaps? I am not sure I 
> understand your point.
> 
> Thanks!
Oh, I mean that in OpenCL 1.2 there will be some error message with
```
const global int
```
But I want to have a test with something that not only with the constant 
address space.
Or what you suggest is that I make all the test in OpenCL 2.0?


http://reviews.llvm.org/D20090



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


Re: [PATCH] D17578: [OpenCL]Allowing explicit conversion of "0" to event_t type

2016-05-19 Thread Xiuli PAN via cfe-commits
pxli168 accepted this revision.
pxli168 added a comment.

Sorry about late reply.
LGTM!


http://reviews.llvm.org/D17578



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


Re: [PATCH] D18369: [OpenCL] Upstreaming khronos OpenCL header file.

2016-05-19 Thread Xiuli PAN via cfe-commits
pxli168 accepted this revision.
pxli168 added a comment.

LGTM!
I think we may add optimization on this base later.


http://reviews.llvm.org/D18369



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


Re: [PATCH] D18369: [OpenCL] Upstreaming khronos OpenCL header file.

2016-05-15 Thread Xiuli PAN via cfe-commits
pxli168 added a comment.





Comment at: lib/Headers/opencl-c.h:9110
@@ +9109,3 @@
+ */
+float __const_func remainder(float x, float y);
+float2 __const_func remainder(float2 x, float2 y);

Anastasia wrote:
> Overloadable here and in other places too?
It seems macro __const_func has overloadable attribute.

> #define __const_func __attribute__((const, overloadable))



Comment at: lib/Headers/opencl-c.h:13534
@@ +13533,3 @@
+/**
+ * For n = 1, 2, 4, 8 and 16 read sizeof (halfn)
+ * bytes of data from address (p + (offset * n)).

I have seen a lot of comments with such few words in one line. It seems very 
strange here.


Comment at: lib/Headers/opencl-c.h:14484
@@ +14483,3 @@
+long __attribute__((overloadable)) atom_sub(volatile __global long *p, long 
val);
+unsigned long __attribute__((overloadable)) atom_sub(volatile __global 
unsigned long *p, unsigned long val);
+long __attribute__((overloadable)) atom_sub(volatile __local long *p, long 
val);

Anastasia wrote:
> btw, perhaps it's a good idea to have a macro for 
> __attribute__((overloadable)). This should be relatively simple to replace 
> everywhere.
Agree, it seems a lot of functions need overloable attribute.


Comment at: lib/Headers/opencl-c.h:14766
@@ +14765,3 @@
+
+ATOMIC_INIT_PROTOTYPE(int)
+ATOMIC_INIT_PROTOTYPE(uint)

Anastasia wrote:
> Let's not have macros for function declarations. As commented earlier they 
> can break proper diagnostics reporting (ie. diagnostics will display macro 
> instead of actual function).
So maybe we could use see script to generate the header when build? It will 
save space and avoid macro break readability and  diagnostics reporting. The 
clang builtin functions are defined in some .def files, or maybe we could try 
something like that?
This can be done after we have a stable version of what is need for header, we 
may just decide what should be in this header and don't focus on the 
performance. 


http://reviews.llvm.org/D18369



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


Re: [PATCH] D19932: [OpenCL] Add to_{global|local|private} builtin functions.

2016-05-12 Thread Xiuli PAN via cfe-commits
pxli168 accepted this revision.
pxli168 added a comment.
This revision is now accepted and ready to land.

LGTM



Comment at: test/SemaOpenCL/to_addr_builtin.cl:26
@@ +25,3 @@
+#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+  // expected-error@-2{{'to_global' needs OpenCL version 2.0 or above}}
+#else

Anastasia wrote:
> @Xiuli, I think Sam is right. Passing constant to generic violates AS 
> conversion rules from s6.5.5. So error would be correct behavior of the 
> compiler.
Yes, I think I just misunderstand some address space problem.


http://reviews.llvm.org/D19932



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


Re: [PATCH] D20090: [OPENCL] Fix wrongly vla error for OpenCL array.

2016-05-10 Thread Xiuli PAN via cfe-commits
pxli168 added inline comments.


Comment at: lib/Sema/SemaType.cpp:2055
@@ -2054,3 +2054,3 @@
 
-  return S.VerifyIntegerConstantExpression(ArraySize, , Diagnoser,
-   S.LangOpts.GNUMode).isInvalid();
+  return S
+  .VerifyIntegerConstantExpression(ArraySize, , Diagnoser,

Anastasia wrote:
> Formatting looks weird though... may be better to leave the first line 
> unmodified?
I felt very strange, too. But this is what clang-format gives me.


Comment at: test/CodeGenOpenCL/vla.cl:1
@@ +1,2 @@
+// RUN: %clang_cc1 -emit-llvm -O0 -o - %s | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -O0 -cl-std=CL2.0 -DCL20 -o - %s | FileCheck %s 
--check-prefix=CL20

Anastasia wrote:
> Could we have a Sema test instead where we accept the VLA if constant AS 
> object is used and give an error otherwise?
> 
> Also do we need to test CL2.0? We don't seem to be doing anything different 
> for that version. 
In earier than OpenCL1.2  program scope variable must reside in constant 
address space and no
```
const global int
```
can be here.
But const global value should also not be seen as VLA either.


http://reviews.llvm.org/D20090



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


Re: [PATCH] D19932: [OpenCL] Add to_{global|local|private} builtin functions.

2016-05-10 Thread Xiuli PAN via cfe-commits
pxli168 added inline comments.


Comment at: test/SemaOpenCL/to_addr_builtin.cl:25
@@ +24,3 @@
+  glob = to_global(con);
+#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+  // expected-error@-2{{'to_global' needs OpenCL version 2.0 or above}}

yaxunl wrote:
> pxli168 wrote:
> > But in Spec OpenCL V2.0 s6.13.9 the description for to_global is:
> > 
> > > Returns a pointer that points to a region in the global address space if 
> > > to_global can cast ptr to the global address space. Otherwise it returns 
> > > NULL.
> > 
> I think this is only for valid call expression. For constant pointer, it is 
> an invalid call expression due to s6.5.5, so an error of invalid argument 
> should be emitted.
> 
> If we allow passing constant pointer to this function, we violates s6.5.5.
>A pointer that points to the constant address space cannot be cast or 
>implicitly converted to the generic address space.
 
So if we can not cast, we maybe should return NULL?
@Anastasia What do you think about this?




http://reviews.llvm.org/D19932



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


[PATCH] D20090: [OPENCL] Fix wrongly vla error for OpenCL array.

2016-05-10 Thread Xiuli PAN via cfe-commits
pxli168 created this revision.
pxli168 added reviewers: Anastasia, yaxunl.
pxli168 added subscribers: cfe-commits, bader.

OpenCL should support array with const value size length, those const varibale 
in global and constant address space and variable in constant address space.


http://reviews.llvm.org/D20090

Files:
  lib/AST/ExprConstant.cpp
  lib/Sema/SemaType.cpp
  test/CodeGenOpenCL/vla.cl

Index: test/CodeGenOpenCL/vla.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/vla.cl
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -emit-llvm -O0 -o - %s | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -O0 -cl-std=CL2.0 -DCL20 -o - %s | FileCheck %s 
--check-prefix=CL20
+
+constant int sz0 = 5;
+// CHECK: @sz0 = constant i32 5, align 4
+#ifdef CL20
+const global int sz1 = 16;
+// CL20: @sz1 = constant i32 16, align 4
+const constant int sz2 = 8;
+// CL20: @sz2 = constant i32 8, align 4
+// CL20: @testvla.vla2 = internal global [8 x i16] undef, align 16
+#endif
+
+kernel void testvla()
+{
+  int vla0[sz0];
+// CHECK: %vla0 = alloca [5 x i32], align 16
+#ifdef CL20
+  char vla1[sz1];
+// CL20: %vla1 = alloca [16 x i8], align 16
+  local short vla2[sz2];
+#endif
+}
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -2052,8 +2052,10 @@
 }
   } Diagnoser;
 
-  return S.VerifyIntegerConstantExpression(ArraySize, , Diagnoser,
-   S.LangOpts.GNUMode).isInvalid();
+  return S
+  .VerifyIntegerConstantExpression(ArraySize, , Diagnoser,
+   S.LangOpts.GNUMode || S.LangOpts.OpenCL)
+  .isInvalid();
 }
 
 /// \brief Build an array type.
Index: lib/AST/ExprConstant.cpp
===
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -2685,7 +2685,10 @@
   } else if (VD->isConstexpr()) {
 // OK, we can read this variable.
   } else if (BaseType->isIntegralOrEnumerationType()) {
-if (!BaseType.isConstQualified()) {
+// In OpenCL if a variable is in constant address space it is a const 
value.
+if (!(BaseType.isConstQualified() ||
+  (Info.getLangOpts().OpenCL &&
+   BaseType.getAddressSpace() == LangAS::opencl_constant))) {
   if (Info.getLangOpts().CPlusPlus) {
 Info.Diag(E, diag::note_constexpr_ltor_non_const_int, 1) << VD;
 Info.Note(VD->getLocation(), diag::note_declared_at);


Index: test/CodeGenOpenCL/vla.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/vla.cl
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -emit-llvm -O0 -o - %s | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -O0 -cl-std=CL2.0 -DCL20 -o - %s | FileCheck %s --check-prefix=CL20
+
+constant int sz0 = 5;
+// CHECK: @sz0 = constant i32 5, align 4
+#ifdef CL20
+const global int sz1 = 16;
+// CL20: @sz1 = constant i32 16, align 4
+const constant int sz2 = 8;
+// CL20: @sz2 = constant i32 8, align 4
+// CL20: @testvla.vla2 = internal global [8 x i16] undef, align 16
+#endif
+
+kernel void testvla()
+{
+  int vla0[sz0];
+// CHECK: %vla0 = alloca [5 x i32], align 16
+#ifdef CL20
+  char vla1[sz1];
+// CL20: %vla1 = alloca [16 x i8], align 16
+  local short vla2[sz2];
+#endif
+}
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -2052,8 +2052,10 @@
 }
   } Diagnoser;
 
-  return S.VerifyIntegerConstantExpression(ArraySize, , Diagnoser,
-   S.LangOpts.GNUMode).isInvalid();
+  return S
+  .VerifyIntegerConstantExpression(ArraySize, , Diagnoser,
+   S.LangOpts.GNUMode || S.LangOpts.OpenCL)
+  .isInvalid();
 }
 
 /// \brief Build an array type.
Index: lib/AST/ExprConstant.cpp
===
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -2685,7 +2685,10 @@
   } else if (VD->isConstexpr()) {
 // OK, we can read this variable.
   } else if (BaseType->isIntegralOrEnumerationType()) {
-if (!BaseType.isConstQualified()) {
+// In OpenCL if a variable is in constant address space it is a const value.
+if (!(BaseType.isConstQualified() ||
+  (Info.getLangOpts().OpenCL &&
+   BaseType.getAddressSpace() == LangAS::opencl_constant))) {
   if (Info.getLangOpts().CPlusPlus) {
 Info.Diag(E, diag::note_constexpr_ltor_non_const_int, 1) << VD;
 Info.Note(VD->getLocation(), diag::note_declared_at);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19932: [OpenCL] Add to_{global|local|private} builtin functions.

2016-05-10 Thread Xiuli PAN via cfe-commits
pxli168 added a comment.

You can update the SUMMARY of this diff as we are now using generic codegen 
output.
And there are some inline comments about spec.



Comment at: test/SemaOpenCL/to_addr_builtin.cl:25
@@ +24,3 @@
+  glob = to_global(con);
+#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+  // expected-error@-2{{'to_global' needs OpenCL version 2.0 or above}}

But in Spec OpenCL V2.0 s6.13.9 the description for to_global is:

> Returns a pointer that points to a region in the global address space if 
> to_global can cast ptr to the global address space. Otherwise it returns NULL.



http://reviews.llvm.org/D19932



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


Re: [PATCH] D19932: [OpenCL] Add to_{global|local|private} builtin functions.

2016-05-08 Thread Xiuli PAN via cfe-commits
pxli168 added a comment.

The pointer type seems to be not that important, we can just cast it to any 
type we want.



Comment at: test/SemaOpenCL/to_addr_builtin.cl:24
@@ +23,3 @@
+
+  glob = to_global(con);
+#if __OPENCL_C_VERSION__ < CL_VERSION_2_0

should this return a NULL or a build error?


Comment at: test/SemaOpenCL/to_addr_builtin.cl:35
@@ +34,3 @@
+#else
+  // expected-error@-4{{assigning '__global int *' to '__local int *' changes 
address space of pointer}}
+#endif

I think this will be handled by pointer bitcast if we used some void* as well, 
the address space is the important thing of these built-ins.


http://reviews.llvm.org/D19932



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


Re: [PATCH] D19780: Output OpenCL version in Clang diagnostics

2016-05-08 Thread Xiuli PAN via cfe-commits
pxli168 accepted this revision.
pxli168 added a comment.
This revision is now accepted and ready to land.

LGTM, thanks!


http://reviews.llvm.org/D19780



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


Re: [PATCH] D18369: [OpenCL] Upstreaming khronos OpenCL header file.

2016-05-08 Thread Xiuli PAN via cfe-commits
pxli168 added a comment.

In http://reviews.llvm.org/D18369#422367, @yaxunl wrote:

> In http://reviews.llvm.org/D18369#421963, @pxli168 wrote:
>
> > If we want to save some space, could we use some macro to expand the 
> > gentype or some script to expand the gentype into each types when the clang 
> > is build?
>
>
> We need to balance between space and readability. When I absorbed 
> __attribute__((overloadable)) into __const_func to save space, it did not 
> sacrifice readability. However using macro with gentype will cause the header 
> file more difficult to read.


But I don't think this kind of so long header is easy to read, it contains full 
pages of the same function with different types and it is hard to see if anyone 
is missing or find where these functions end. In spec builtin functions can be 
represented by

> gentype ctz (gentype x)

>  gentype max (gentype x, gentype y)

>  gentype max (gentype x, sgentype y)


If we could use some macro or script to generate the actual builtin functions, 
it seems more likely spec and clear to read, also will avoid missing or typo.


http://reviews.llvm.org/D18369



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


Re: [PATCH] D18369: [OpenCL] Upstreaming khronos OpenCL header file.

2016-05-04 Thread Xiuli PAN via cfe-commits
pxli168 added a comment.

If we want to save some space, could we use some macro to expand the gentype or 
some script to expand the gentype into each types when the clang is build?


http://reviews.llvm.org/D18369



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


Re: [PATCH] D19932: [OpenCL] Add to_{global|local|private} builtin functions.

2016-05-04 Thread Xiuli PAN via cfe-commits
pxli168 added a comment.

Could we output a generic function in CodeGen?
This seems to have no big difference to have a lot of declaration in an opencl 
c header file.


http://reviews.llvm.org/D19932



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


r268364 - [OpenCL] Fix pipe type dump.

2016-05-02 Thread Xiuli Pan via cfe-commits
Author: pxl
Date: Tue May  3 00:37:07 2016
New Revision: 268364

URL: http://llvm.org/viewvc/llvm-project?rev=268364=rev
Log:
[OpenCL] Fix pipe type dump.

Summary:
Fix the dump of PipeType.
Now we will have "pipe int" and element type.

Reviewers: yaxunl, Anastasia

Subscribers: cfe-commits, bader

Differential Revision: http://reviews.llvm.org/D19524

Added:
cfe/trunk/test/Misc/ast-dump-pipe.cl
Modified:
cfe/trunk/lib/AST/ASTDumper.cpp
cfe/trunk/lib/AST/TypePrinter.cpp
cfe/trunk/test/SemaOpenCL/invalid-access-qualifier.cl
cfe/trunk/test/SemaOpenCL/invalid-pipes-cl2.0.cl

Modified: cfe/trunk/lib/AST/ASTDumper.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTDumper.cpp?rev=268364=268363=268364=diff
==
--- cfe/trunk/lib/AST/ASTDumper.cpp (original)
+++ cfe/trunk/lib/AST/ASTDumper.cpp Tue May  3 00:37:07 2016
@@ -404,6 +404,9 @@ namespace  {
 void VisitAtomicType(const AtomicType *T) {
   dumpTypeAsChild(T->getValueType());
 }
+void VisitPipeType(const PipeType *T) {
+  dumpTypeAsChild(T->getElementType());
+}
 void VisitAdjustedType(const AdjustedType *T) {
   dumpTypeAsChild(T->getOriginalType());
 }

Modified: cfe/trunk/lib/AST/TypePrinter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TypePrinter.cpp?rev=268364=268363=268364=diff
==
--- cfe/trunk/lib/AST/TypePrinter.cpp (original)
+++ cfe/trunk/lib/AST/TypePrinter.cpp Tue May  3 00:37:07 2016
@@ -895,7 +895,8 @@ void TypePrinter::printAtomicAfter(const
 void TypePrinter::printPipeBefore(const PipeType *T, raw_ostream ) {
   IncludeStrongLifetimeRAII Strong(Policy);
 
-  OS << "pipe";
+  OS << "pipe ";
+  print(T->getElementType(), OS, StringRef());
   spaceBeforePlaceHolder(OS);
 }
 

Added: cfe/trunk/test/Misc/ast-dump-pipe.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/ast-dump-pipe.cl?rev=268364=auto
==
--- cfe/trunk/test/Misc/ast-dump-pipe.cl (added)
+++ cfe/trunk/test/Misc/ast-dump-pipe.cl Tue May  3 00:37:07 2016
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -triple spir64 -cl-std=CL2.0 -ast-dump -ast-dump-filter 
pipetype %s | FileCheck -strict-whitespace %s
+typedef pipe int pipetype;
+// CHECK:  PipeType {{.*}} 'pipe int'
+// CHECK-NEXT:   BuiltinType {{.*}} 'int'

Modified: cfe/trunk/test/SemaOpenCL/invalid-access-qualifier.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/invalid-access-qualifier.cl?rev=268364=268363=268364=diff
==
--- cfe/trunk/test/SemaOpenCL/invalid-access-qualifier.cl (original)
+++ cfe/trunk/test/SemaOpenCL/invalid-access-qualifier.cl Tue May  3 00:37:07 
2016
@@ -8,7 +8,7 @@ void test2(read_only write_only image1d_
 void test3(read_only read_only image1d_t i){} // expected-error{{multiple 
access qualifiers}}
 
 #ifdef CL20
-void test4(read_write pipe int i){} // expected-error{{access qualifier 
'read_write' can not be used for 'pipe'}}
+void test4(read_write pipe int i){} // expected-error{{access qualifier 
'read_write' can not be used for 'pipe int'}}
 #else
 void test4(__read_write image1d_t i) {} // expected-error{{access qualifier 
'__read_write' can not be used for '__read_write image1d_t' earlier than 
OpenCL2.0 version}}
 #endif

Modified: cfe/trunk/test/SemaOpenCL/invalid-pipes-cl2.0.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/invalid-pipes-cl2.0.cl?rev=268364=268363=268364=diff
==
--- cfe/trunk/test/SemaOpenCL/invalid-pipes-cl2.0.cl (original)
+++ cfe/trunk/test/SemaOpenCL/invalid-pipes-cl2.0.cl Tue May  3 00:37:07 2016
@@ -7,5 +7,5 @@ void test2(pipe p){// expected-error {{m
 void test3(int pipe p){// expected-error {{cannot combine with previous 'int' 
declaration specifier}}
 }
 void test4() {
-  pipe int p; // expected-error {{type 'pipe' can only be used as a function 
parameter}}
+  pipe int p; // expected-error {{type 'pipe int' can only be used as a 
function parameter}}
 }


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


Re: [PATCH] D19524: [OpenCL] Fix pipe type dump.

2016-04-26 Thread Xiuli PAN via cfe-commits
pxli168 updated this revision to Diff 55161.
pxli168 added a comment.

Add test and fix some old test.


http://reviews.llvm.org/D19524

Files:
  lib/AST/ASTDumper.cpp
  lib/AST/TypePrinter.cpp
  test/Misc/ast-dump-pipe.cl
  test/SemaOpenCL/invalid-access-qualifier.cl
  test/SemaOpenCL/invalid-pipes-cl2.0.cl

Index: test/SemaOpenCL/invalid-pipes-cl2.0.cl
===
--- test/SemaOpenCL/invalid-pipes-cl2.0.cl
+++ test/SemaOpenCL/invalid-pipes-cl2.0.cl
@@ -7,5 +7,5 @@
 void test3(int pipe p){// expected-error {{cannot combine with previous 'int' 
declaration specifier}}
 }
 void test4() {
-  pipe int p; // expected-error {{type 'pipe' can only be used as a function 
parameter}}
+  pipe int p; // expected-error {{type 'pipe int' can only be used as a 
function parameter}}
 }
Index: test/SemaOpenCL/invalid-access-qualifier.cl
===
--- test/SemaOpenCL/invalid-access-qualifier.cl
+++ test/SemaOpenCL/invalid-access-qualifier.cl
@@ -8,7 +8,7 @@
 void test3(read_only read_only image1d_t i){} // expected-error{{multiple 
access qualifiers}}
 
 #ifdef CL20
-void test4(read_write pipe int i){} // expected-error{{access qualifier 
'read_write' can not be used for 'pipe'}}
+void test4(read_write pipe int i){} // expected-error{{access qualifier 
'read_write' can not be used for 'pipe int'}}
 #else
 void test4(__read_write image1d_t i) {} // expected-error{{access qualifier 
'__read_write' can not be used for '__read_write image1d_t' earlier than 
OpenCL2.0 version}}
 #endif
Index: test/Misc/ast-dump-pipe.cl
===
--- /dev/null
+++ test/Misc/ast-dump-pipe.cl
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -triple spir64 -cl-std=CL2.0 -ast-dump -ast-dump-filter 
pipetype %s | FileCheck -strict-whitespace %s
+typedef pipe int pipetype;
+// CHECK:  PipeType {{.*}} 'pipe int'
+// CHECK-NEXT:   BuiltinType {{.*}} 'int'
Index: lib/AST/TypePrinter.cpp
===
--- lib/AST/TypePrinter.cpp
+++ lib/AST/TypePrinter.cpp
@@ -895,7 +895,8 @@
 void TypePrinter::printPipeBefore(const PipeType *T, raw_ostream ) {
   IncludeStrongLifetimeRAII Strong(Policy);
 
-  OS << "pipe";
+  OS << "pipe ";
+  print(T->getElementType(), OS, StringRef());
   spaceBeforePlaceHolder(OS);
 }
 
Index: lib/AST/ASTDumper.cpp
===
--- lib/AST/ASTDumper.cpp
+++ lib/AST/ASTDumper.cpp
@@ -404,6 +404,9 @@
 void VisitAtomicType(const AtomicType *T) {
   dumpTypeAsChild(T->getValueType());
 }
+void VisitPipeType(const PipeType *T) {
+  dumpTypeAsChild(T->getElementType());
+}
 void VisitAdjustedType(const AdjustedType *T) {
   dumpTypeAsChild(T->getOriginalType());
 }


Index: test/SemaOpenCL/invalid-pipes-cl2.0.cl
===
--- test/SemaOpenCL/invalid-pipes-cl2.0.cl
+++ test/SemaOpenCL/invalid-pipes-cl2.0.cl
@@ -7,5 +7,5 @@
 void test3(int pipe p){// expected-error {{cannot combine with previous 'int' declaration specifier}}
 }
 void test4() {
-  pipe int p; // expected-error {{type 'pipe' can only be used as a function parameter}}
+  pipe int p; // expected-error {{type 'pipe int' can only be used as a function parameter}}
 }
Index: test/SemaOpenCL/invalid-access-qualifier.cl
===
--- test/SemaOpenCL/invalid-access-qualifier.cl
+++ test/SemaOpenCL/invalid-access-qualifier.cl
@@ -8,7 +8,7 @@
 void test3(read_only read_only image1d_t i){} // expected-error{{multiple access qualifiers}}
 
 #ifdef CL20
-void test4(read_write pipe int i){} // expected-error{{access qualifier 'read_write' can not be used for 'pipe'}}
+void test4(read_write pipe int i){} // expected-error{{access qualifier 'read_write' can not be used for 'pipe int'}}
 #else
 void test4(__read_write image1d_t i) {} // expected-error{{access qualifier '__read_write' can not be used for '__read_write image1d_t' earlier than OpenCL2.0 version}}
 #endif
Index: test/Misc/ast-dump-pipe.cl
===
--- /dev/null
+++ test/Misc/ast-dump-pipe.cl
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -triple spir64 -cl-std=CL2.0 -ast-dump -ast-dump-filter pipetype %s | FileCheck -strict-whitespace %s
+typedef pipe int pipetype;
+// CHECK:  PipeType {{.*}} 'pipe int'
+// CHECK-NEXT:   BuiltinType {{.*}} 'int'
Index: lib/AST/TypePrinter.cpp
===
--- lib/AST/TypePrinter.cpp
+++ lib/AST/TypePrinter.cpp
@@ -895,7 +895,8 @@
 void TypePrinter::printPipeBefore(const PipeType *T, raw_ostream ) {
   IncludeStrongLifetimeRAII Strong(Policy);
 
-  OS << "pipe";
+  OS << "pipe ";
+  print(T->getElementType(), OS, StringRef());
   spaceBeforePlaceHolder(OS);
 }
 
Index: 

Re: [PATCH] D19524: [OpenCL] Fix pipe type dump.

2016-04-26 Thread Xiuli PAN via cfe-commits
pxli168 added a comment.

I will add a test and send a new version.


http://reviews.llvm.org/D19524



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


[PATCH] D19524: [OpenCL] Fix pipe type dump.

2016-04-26 Thread Xiuli PAN via cfe-commits
pxli168 created this revision.
pxli168 added reviewers: Anastasia, yaxunl.
pxli168 added subscribers: bader, cfe-commits.

Fix the dump of PipeType.
Now we will have "pipe int" and element type.

http://reviews.llvm.org/D19524

Files:
  lib/AST/ASTDumper.cpp
  lib/AST/TypePrinter.cpp

Index: lib/AST/TypePrinter.cpp
===
--- lib/AST/TypePrinter.cpp
+++ lib/AST/TypePrinter.cpp
@@ -895,7 +895,8 @@
 void TypePrinter::printPipeBefore(const PipeType *T, raw_ostream ) {
   IncludeStrongLifetimeRAII Strong(Policy);
 
-  OS << "pipe";
+  OS << "pipe ";
+  print(T->getElementType(), OS, StringRef());
   spaceBeforePlaceHolder(OS);
 }
 
Index: lib/AST/ASTDumper.cpp
===
--- lib/AST/ASTDumper.cpp
+++ lib/AST/ASTDumper.cpp
@@ -404,6 +404,9 @@
 void VisitAtomicType(const AtomicType *T) {
   dumpTypeAsChild(T->getValueType());
 }
+void VisitPipeType(const PipeType *T) {
+  dumpTypeAsChild(T->getElementType());
+}
 void VisitAdjustedType(const AdjustedType *T) {
   dumpTypeAsChild(T->getOriginalType());
 }


Index: lib/AST/TypePrinter.cpp
===
--- lib/AST/TypePrinter.cpp
+++ lib/AST/TypePrinter.cpp
@@ -895,7 +895,8 @@
 void TypePrinter::printPipeBefore(const PipeType *T, raw_ostream ) {
   IncludeStrongLifetimeRAII Strong(Policy);
 
-  OS << "pipe";
+  OS << "pipe ";
+  print(T->getElementType(), OS, StringRef());
   spaceBeforePlaceHolder(OS);
 }
 
Index: lib/AST/ASTDumper.cpp
===
--- lib/AST/ASTDumper.cpp
+++ lib/AST/ASTDumper.cpp
@@ -404,6 +404,9 @@
 void VisitAtomicType(const AtomicType *T) {
   dumpTypeAsChild(T->getValueType());
 }
+void VisitPipeType(const PipeType *T) {
+  dumpTypeAsChild(T->getElementType());
+}
 void VisitAdjustedType(const AdjustedType *T) {
   dumpTypeAsChild(T->getOriginalType());
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18369: [OpenCL] Upstreaming khronos OpenCL 1.2/2.0 header files.

2016-04-13 Thread Xiuli PAN via cfe-commits
pxli168 added inline comments.


Comment at: lib/Headers/opencl.h:13721-13726
@@ +13720,8 @@
+
+/**
+ * Queue a memory fence to ensure correct ordering of memory
+ * operations between work-items of a work-group to
+ * image memory.
+ */
+#define CLK_IMAGE_MEM_FENCE  0x04
+

Move this to the barrier part with worg_group_barrier maybe better.


Comment at: lib/Headers/opencl.h:15636-15637
@@ +15635,4 @@
+#if defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ >= 200
+#define PIPE_RESERVE_ID_VALID_BIT (1U << 30)
+#define CLK_NULL_RESERVE_ID 
(__builtin_astype(((void*)(~PIPE_RESERVE_ID_VALID_BIT)), reserve_id_t))
+bool __attribute__((overloadable)) is_valid_reserve_id(reserve_id_t 
reserve_id);

Is this macro needed in this header?
And what happens to spir32 and spir64 difference?


Comment at: lib/Headers/opencl.h:15661
@@ +15660,3 @@
+#define CLK_NULL_QUEUE  0
+#define CLK_NULL_EVENT (__builtin_astype(((void*)(UINT32MAX)), clk_event_t))
+

What is this UINT32MAX?
And what about spir64?


Comment at: lib/Headers/opencl.h:15675
@@ +15674,3 @@
+#define MAX_WORK_DIM3
+#if defined(__clang__) && (__clang_major__ < 3 || (__clang_major__ == 3 && 
__clang_minor__ < 9))
+typedef struct {

Is this part necessary for up-streaming to the llvm3.9? It will never be hint.


http://reviews.llvm.org/D18369



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


Re: [PATCH] D19071: [OpenCL] Add predefined macros.

2016-04-13 Thread Xiuli PAN via cfe-commits
pxli168 added inline comments.


Comment at: lib/Frontend/InitPreprocessor.cpp:421
@@ +420,3 @@
+switch (LangOpts.OpenCLVersion) {
+case 0:
+case 100:

What is 0 stand for as OpenCLVersion, it seems the default OpenCLVersion if we 
did not pass any -cl-std=CLXX is 100.
So maybe we did not need this case 0:


Comment at: lib/Frontend/InitPreprocessor.cpp:439
@@ +438,3 @@
+if (LangOpts.OpenCLVersion >= 110)
+  Builder.defineMacro("CL_VERSION_1_1", "110");
+if (LangOpts.OpenCLVersion >= 120)

These macros maybe need for all cl version, and in the header we should compare 
 __OPENCL_C_VERSION__ with CL_VERSION_2_0 instead of the integer 200 in the 
header of  http://reviews.llvm.org/D18369? 


http://reviews.llvm.org/D19071



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


Re: [PATCH] D18369: [OpenCL] Upstreaming khronos OpenCL 1.2/2.0 header files.

2016-04-11 Thread Xiuli PAN via cfe-commits
pxli168 added a comment.

I think merge them into one file is a good idea.
And the layout by sepc order is OK, is will makes the review easy.


http://reviews.llvm.org/D18369



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


Re: [PATCH] D17412: PR19957: [OpenCL] incorrectly accepts implicit address space conversion with ternary operator

2016-04-05 Thread Xiuli PAN via cfe-commits
pxli168 accepted this revision.
pxli168 added a comment.

LGTM!
Thanks!


http://reviews.llvm.org/D17412



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


r264825 - [OpenCL] Fix pipe builtin bugs

2016-03-29 Thread Xiuli Pan via cfe-commits
Author: pxl
Date: Tue Mar 29 23:46:32 2016
New Revision: 264825

URL: http://llvm.org/viewvc/llvm-project?rev=264825=rev
Log:
[OpenCL] Fix pipe builtin bugs

Summary:
1. Diag should be output if types are not the same.
2. Should compare using canonical type.
3. Refine the diag to be more clear.

Reviewers: yaxunl, Anastasia

Subscribers: MatsPetersson, pekka.jaaskelainen, cfe-commits

Differential Revision: http://reviews.llvm.org/D17955

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=264825=264824=264825=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Mar 29 23:46:32 
2016
@@ -7776,7 +7776,7 @@ def err_opencl_builtin_pipe_first_arg :
 def err_opencl_builtin_pipe_arg_num : Error<
   "invalid number of arguments to function: %0">;
 def err_opencl_builtin_pipe_invalid_arg : Error<
-  "invalid argument type to function %0 (expecting %1)">;
+  "invalid argument type to function %0 (expecting %1 having %2)">;
 def err_opencl_builtin_pipe_invalid_access_modifier : Error<
   "invalid pipe access modifier (expecting %0)">;
 

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=264825=264824=264825=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Mar 29 23:46:32 2016
@@ -325,10 +325,12 @@ static bool checkOpenCLPipePacketType(Se
   const PointerType *ArgTy = ArgIdx->getType()->getAs();
   // The Idx argument should be a pointer and the type of the pointer and
   // the type of pipe element should also be the same.
-  if (!ArgTy || S.Context.hasSameType(EltTy, ArgTy->getPointeeType())) {
+  if (!ArgTy ||
+  !S.Context.hasSameType(
+  EltTy, ArgTy->getPointeeType()->getCanonicalTypeInternal())) {
 S.Diag(Call->getLocStart(), diag::err_opencl_builtin_pipe_invalid_arg)
 << Call->getDirectCallee() << S.Context.getPointerType(EltTy)
-<< ArgIdx->getSourceRange();
+<< ArgIdx->getType() << ArgIdx->getSourceRange();
 return true;
   }
   return false;
@@ -361,7 +363,7 @@ static bool SemaBuiltinRWPipe(Sema , C
 if (!Call->getArg(1)->getType()->isReserveIDT()) {
   S.Diag(Call->getLocStart(), diag::err_opencl_builtin_pipe_invalid_arg)
   << Call->getDirectCallee() << S.Context.OCLReserveIDTy
-  << Call->getArg(1)->getSourceRange();
+  << Call->getArg(1)->getType() << Call->getArg(1)->getSourceRange();
   return true;
 }
 
@@ -371,7 +373,7 @@ static bool SemaBuiltinRWPipe(Sema , C
 !Arg2->getType()->isUnsignedIntegerType()) {
   S.Diag(Call->getLocStart(), diag::err_opencl_builtin_pipe_invalid_arg)
   << Call->getDirectCallee() << S.Context.UnsignedIntTy
-  << Arg2->getSourceRange();
+  << Arg2->getType() << Arg2->getSourceRange();
   return true;
 }
 
@@ -405,7 +407,7 @@ static bool SemaBuiltinReserveRWPipe(Sem
   !Call->getArg(1)->getType()->isUnsignedIntegerType()) {
 S.Diag(Call->getLocStart(), diag::err_opencl_builtin_pipe_invalid_arg)
 << Call->getDirectCallee() << S.Context.UnsignedIntTy
-<< Call->getArg(1)->getSourceRange();
+<< Call->getArg(1)->getType() << Call->getArg(1)->getSourceRange();
 return true;
   }
 
@@ -428,7 +430,7 @@ static bool SemaBuiltinCommitRWPipe(Sema
   if (!Call->getArg(1)->getType()->isReserveIDT()) {
 S.Diag(Call->getLocStart(), diag::err_opencl_builtin_pipe_invalid_arg)
 << Call->getDirectCallee() << S.Context.OCLReserveIDTy
-<< Call->getArg(1)->getSourceRange();
+<< Call->getArg(1)->getType() << Call->getArg(1)->getSourceRange();
 return true;
   }
 

Modified: cfe/trunk/test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl?rev=264825=264824=264825=diff
==
--- cfe/trunk/test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl (original)
+++ cfe/trunk/test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl Tue Mar 29 23:46:32 
2016
@@ -5,22 +5,27 @@ void test1(read_only pipe int p, global
   reserve_id_t rid;
 
   // read/write_pipe
+  read_pipe(p, );
+  read_pipe(p, ptr);
   read_pipe(tmp, p);// expected-error {{first argument to 'read_pipe' must 
be a pipe type}}
   read_pipe(p);   // expected-error {{invalid number of arguments to function: 
'read_pipe'}}
-  read_pipe(p, tmp, tmp, ptr);   // expected-error 

Re: [PATCH] D17438: [OpenCL] Add Sema checks for atomics and implicit declaration

2016-03-28 Thread Xiuli PAN via cfe-commits
pxli168 added a comment.

Hi Anastasia,
https://cvs.khronos.org/bugzilla/show_bug.cgi?id=15603
Now we got clarify from khronos. I will continue on this patch.
BTW, https://cvs.khronos.org/bugzilla/show_bug.cgi?id=15599 is also fixed in 
the same revision. 
Thanks
Xiuli


http://reviews.llvm.org/D17438



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


Re: [PATCH] D17955: [OpenCL] Fix pipe builtin bugs

2016-03-24 Thread Xiuli PAN via cfe-commits
pxli168 updated this revision to Diff 51629.
pxli168 added a comment.

Add test for correct case.


http://reviews.llvm.org/D17955

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaChecking.cpp
  test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl

Index: test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl
===
--- test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl
+++ test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl
@@ -5,46 +5,56 @@
   reserve_id_t rid;
 
   // read/write_pipe
+  read_pipe(p, );
+  read_pipe(p, ptr);
   read_pipe(tmp, p);// expected-error {{first argument to 'read_pipe' must be a pipe type}}
   read_pipe(p);   // expected-error {{invalid number of arguments to function: 'read_pipe'}}
-  read_pipe(p, tmp, tmp, ptr);   // expected-error {{invalid argument type to function 'read_pipe' (expecting 'reserve_id_t')}}
-  read_pipe(p, rid, rid, ptr);   // expected-error {{invalid argument type to function 'read_pipe' (expecting 'unsigned int')}}
-  read_pipe(p, tmp);   // expected-error {{invalid argument type to function 'read_pipe' (expecting 'int *')}}
+  read_pipe(p, rid, tmp, ptr);
+  read_pipe(p, tmp, tmp, ptr);   // expected-error {{invalid argument type to function 'read_pipe' (expecting 'reserve_id_t' having 'int')}}
+  read_pipe(p, rid, rid, ptr);   // expected-error {{invalid argument type to function 'read_pipe' (expecting 'unsigned int' having 'reserve_id_t')}}
+  read_pipe(p, tmp);   // expected-error {{invalid argument type to function 'read_pipe' (expecting 'int *' having 'int')}}
   write_pipe(p, ptr);// expected-error {{invalid pipe access modifier (expecting write_only)}}
   write_pipe(p, rid, tmp, ptr);// expected-error {{invalid pipe access modifier (expecting write_only)}}
 
   // reserve_read/write_pipe
-  reserve_read_pipe(p, ptr);// expected-error{{invalid argument type to function 'reserve_read_pipe' (expecting 'unsigned int')}}
+  reserve_read_pipe(p, tmp);
+  reserve_read_pipe(p, ptr);// expected-error{{invalid argument type to function 'reserve_read_pipe' (expecting 'unsigned int' having '__global int *')}}
   work_group_reserve_read_pipe(tmp, tmp);// expected-error{{first argument to 'work_group_reserve_read_pipe' must be a pipe type}}
   sub_group_reserve_write_pipe(p, tmp);// expected-error{{invalid pipe access modifier (expecting write_only)}}
 
   // commit_read/write_pipe
+  commit_read_pipe(p, rid);
   commit_read_pipe(tmp, rid);// expected-error{{first argument to 'commit_read_pipe' must be a pipe type}}
-  work_group_commit_read_pipe(p, tmp);// expected-error{{invalid argument type to function 'work_group_commit_read_pipe' (expecting 'reserve_id_t')}}
+  work_group_commit_read_pipe(p, tmp);// expected-error{{invalid argument type to function 'work_group_commit_read_pipe' (expecting 'reserve_id_t' having 'int')}}
   sub_group_commit_write_pipe(p, tmp);// expected-error{{invalid pipe access modifier (expecting write_only)}}
 }
 
 void test2(write_only pipe int p, global int* ptr){
   int tmp;
   reserve_id_t rid;
 
   // read/write_pipe
+  write_pipe(p, );
+  write_pipe(p, ptr);
   write_pipe(tmp, p);// expected-error {{first argument to 'write_pipe' must be a pipe type}}
   write_pipe(p);   // expected-error {{invalid number of arguments to function: 'write_pipe'}}
-  write_pipe(p, tmp, tmp, ptr);   // expected-error {{invalid argument type to function 'write_pipe' (expecting 'reserve_id_t')}}
-  write_pipe(p, rid, rid, ptr);   // expected-error {{invalid argument type to function 'write_pipe' (expecting 'unsigned int')}}
-  write_pipe(p, tmp);   // expected-error {{invalid argument type to function 'write_pipe' (expecting 'int *')}}
+  write_pipe(p, rid, tmp, ptr);
+  write_pipe(p, tmp, tmp, ptr);   // expected-error {{invalid argument type to function 'write_pipe' (expecting 'reserve_id_t' having 'int')}}
+  write_pipe(p, rid, rid, ptr);   // expected-error {{invalid argument type to function 'write_pipe' (expecting 'unsigned int' having 'reserve_id_t')}}
+  write_pipe(p, tmp);   // expected-error {{invalid argument type to function 'write_pipe' (expecting 'int *' having 'int')}}
   read_pipe(p, ptr);// expected-error {{invalid pipe access modifier (expecting read_only)}}
   read_pipe(p, rid, tmp, ptr);// expected-error {{invalid pipe access modifier (expecting read_only)}}
 
   // reserve_read/write_pipe
-  reserve_write_pipe(p, ptr);// expected-error{{invalid argument type to function 'reserve_write_pipe' (expecting 'unsigned int')}}
+  reserve_write_pipe(p, tmp);
+  reserve_write_pipe(p, ptr);// expected-error{{invalid argument type to function 'reserve_write_pipe' (expecting 'unsigned int' having '__global int *')}}
   work_group_reserve_write_pipe(tmp, tmp);// expected-error{{first argument to 'work_group_reserve_write_pipe' must be a pipe type}}
   sub_group_reserve_read_pipe(p, tmp);// expected-error{{invalid pipe 

r264241 - [OpenCL] Add ocl and spir version for spir target

2016-03-23 Thread Xiuli Pan via cfe-commits
Author: pxl
Date: Wed Mar 23 22:57:17 2016
New Revision: 264241

URL: http://llvm.org/viewvc/llvm-project?rev=264241=rev
Log:
[OpenCL] Add ocl and spir version for spir target

Summary: Add opencl.spir.version and opencl.ocl.version metadata for CodeGen to 
identify OpenCL version. 

Reviewers: yaxunl, Anastasia

Subscribers: cfe-commits, pekka.jaaskelainen

Differential Revision: http://reviews.llvm.org/D17596

Added:
cfe/trunk/test/CodeGenOpenCL/spir_version.cl
Modified:
cfe/trunk/lib/CodeGen/TargetInfo.cpp

Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=264241=264240=264241=diff
==
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Wed Mar 23 22:57:17 2016
@@ -7217,6 +7217,47 @@ void XCoreTargetCodeGenInfo::emitTargetM
   }
 }
 
+//===--===//
+// SPIR ABI Implementation
+//===--===//
+
+namespace {
+class SPIRTargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  SPIRTargetCodeGenInfo(CodeGen::CodeGenTypes )
+: TargetCodeGenInfo(new DefaultABIInfo(CGT)) {}
+  void emitTargetMD(const Decl *D, llvm::GlobalValue *GV,
+CodeGen::CodeGenModule ) const override;
+};
+} // End anonymous namespace.
+
+/// Emit SPIR specific metadata: OpenCL and SPIR version.
+void SPIRTargetCodeGenInfo::emitTargetMD(const Decl *D, llvm::GlobalValue *GV,
+ CodeGen::CodeGenModule ) const {
+  assert(CGM.getLangOpts().OpenCL && "SPIR is only for OpenCL");
+  llvm::LLVMContext  = CGM.getModule().getContext();
+  llvm::Type *Int32Ty = llvm::Type::getInt32Ty(Ctx);
+  llvm::Module  = CGM.getModule();
+  // SPIR v2.0 s2.12 - The SPIR version used by the module is stored in the
+  // opencl.spir.version named metadata.
+  llvm::Metadata *SPIRVerElts[] = {
+  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(Int32Ty, 2)),
+  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(Int32Ty, 0))};
+  llvm::NamedMDNode *SPIRVerMD =
+  M.getOrInsertNamedMetadata("opencl.spir.version");
+  SPIRVerMD->addOperand(llvm::MDNode::get(Ctx, SPIRVerElts));
+  // SPIR v2.0 s2.13 - The OpenCL version used by the module is stored in the
+  // opencl.ocl.version named metadata node.
+  llvm::Metadata *OCLVerElts[] = {
+  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
+  Int32Ty, CGM.getLangOpts().OpenCLVersion / 100)),
+  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
+  Int32Ty, (CGM.getLangOpts().OpenCLVersion % 100) / 10))};
+  llvm::NamedMDNode *OCLVerMD =
+  M.getOrInsertNamedMetadata("opencl.ocl.version");
+  OCLVerMD->addOperand(llvm::MDNode::get(Ctx, OCLVerElts));
+}
+
 static bool appendType(SmallStringEnc , QualType QType,
const CodeGen::CodeGenModule ,
TypeStringCache );
@@ -7707,5 +7748,8 @@ const TargetCodeGenInfo ::
 return *(TheTargetCodeGenInfo = new SparcV9TargetCodeGenInfo(Types));
   case llvm::Triple::xcore:
 return *(TheTargetCodeGenInfo = new XCoreTargetCodeGenInfo(Types));
+  case llvm::Triple::spir:
+  case llvm::Triple::spir64:
+return *(TheTargetCodeGenInfo = new SPIRTargetCodeGenInfo(Types));
   }
 }

Added: cfe/trunk/test/CodeGenOpenCL/spir_version.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/spir_version.cl?rev=264241=auto
==
--- cfe/trunk/test/CodeGenOpenCL/spir_version.cl (added)
+++ cfe/trunk/test/CodeGenOpenCL/spir_version.cl Wed Mar 23 22:57:17 2016
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 %s -triple "spir-unknown-unknown" -emit-llvm -o - | 
FileCheck %s --check-prefix=CL10
+// RUN: %clang_cc1 %s -triple "spir-unknown-unknown" -emit-llvm -o - 
-cl-std=CL1.2 | FileCheck %s --check-prefix=CL12
+// RUN: %clang_cc1 %s -triple "spir-unknown-unknown" -emit-llvm -o - 
-cl-std=CL2.0 | FileCheck %s --check-prefix=CL20
+// RUN: %clang_cc1 %s -triple "spir64-unknown-unknown" -emit-llvm -o - | 
FileCheck %s --check-prefix=CL10
+// RUN: %clang_cc1 %s -triple "spir64-unknown-unknown" -emit-llvm -o - 
-cl-std=CL1.2 | FileCheck %s --check-prefix=CL12
+// RUN: %clang_cc1 %s -triple "spir64-unknown-unknown" -emit-llvm -o - 
-cl-std=CL2.0 | FileCheck %s --check-prefix=CL20
+kernel void foo() {}
+// CL10: !opencl.spir.version = !{[[SPIR:![0-9]+]]}
+// CL10: !opencl.ocl.version = !{[[OCL:![0-9]+]]}
+// CL10: [[SPIR]] = !{i32 2, i32 0}
+// CL10: [[OCL]] = !{i32 1, i32 0}
+// CL12: !opencl.spir.version = !{[[SPIR:![0-9]+]]}
+// CL12: !opencl.ocl.version = !{[[OCL:![0-9]+]]}
+// CL12: [[SPIR]] = !{i32 2, i32 0}
+// CL12: [[OCL]] = !{i32 1, i32 2}
+// CL20: !opencl.spir.version = !{[[SPIR:![0-9]+]]}
+// CL20: !opencl.ocl.version = 

Re: [PATCH] D17596: [OpenCL] Add ocl and spir version for spir target

2016-03-21 Thread Xiuli PAN via cfe-commits
pxli168 updated this revision to Diff 51253.
pxli168 added a comment.

Add test for spir64.


http://reviews.llvm.org/D17596

Files:
  lib/CodeGen/TargetInfo.cpp
  test/CodeGenOpenCL/spir_version.cl

Index: test/CodeGenOpenCL/spir_version.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/spir_version.cl
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 %s -triple "spir-unknown-unknown" -emit-llvm -o - | 
FileCheck %s --check-prefix=CL10
+// RUN: %clang_cc1 %s -triple "spir-unknown-unknown" -emit-llvm -o - 
-cl-std=CL1.2 | FileCheck %s --check-prefix=CL12
+// RUN: %clang_cc1 %s -triple "spir-unknown-unknown" -emit-llvm -o - 
-cl-std=CL2.0 | FileCheck %s --check-prefix=CL20
+// RUN: %clang_cc1 %s -triple "spir64-unknown-unknown" -emit-llvm -o - | 
FileCheck %s --check-prefix=CL10
+// RUN: %clang_cc1 %s -triple "spir64-unknown-unknown" -emit-llvm -o - 
-cl-std=CL1.2 | FileCheck %s --check-prefix=CL12
+// RUN: %clang_cc1 %s -triple "spir64-unknown-unknown" -emit-llvm -o - 
-cl-std=CL2.0 | FileCheck %s --check-prefix=CL20
+kernel void foo() {}
+// CL10: !opencl.spir.version = !{[[SPIR:![0-9]+]]}
+// CL10: !opencl.ocl.version = !{[[OCL:![0-9]+]]}
+// CL10: [[SPIR]] = !{i32 2, i32 0}
+// CL10: [[OCL]] = !{i32 1, i32 0}
+// CL12: !opencl.spir.version = !{[[SPIR:![0-9]+]]}
+// CL12: !opencl.ocl.version = !{[[OCL:![0-9]+]]}
+// CL12: [[SPIR]] = !{i32 2, i32 0}
+// CL12: [[OCL]] = !{i32 1, i32 2}
+// CL20: !opencl.spir.version = !{[[SPIR:![0-9]+]]}
+// CL20: !opencl.ocl.version = !{[[SPIR:![0-9]+]]}
+// CL20: [[SPIR]] = !{i32 2, i32 0}
Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -7217,6 +7217,47 @@
   }
 }
 
+//===--===//
+// SPIR ABI Implementation
+//===--===//
+
+namespace {
+class SPIRTargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  SPIRTargetCodeGenInfo(CodeGen::CodeGenTypes )
+: TargetCodeGenInfo(new DefaultABIInfo(CGT)) {}
+  void emitTargetMD(const Decl *D, llvm::GlobalValue *GV,
+CodeGen::CodeGenModule ) const override;
+};
+} // End anonymous namespace.
+
+/// Emit SPIR specific metadata: OpenCL and SPIR version.
+void SPIRTargetCodeGenInfo::emitTargetMD(const Decl *D, llvm::GlobalValue *GV,
+ CodeGen::CodeGenModule ) const {
+  assert(CGM.getLangOpts().OpenCL && "SPIR is only for OpenCL");
+  llvm::LLVMContext  = CGM.getModule().getContext();
+  llvm::Type *Int32Ty = llvm::Type::getInt32Ty(Ctx);
+  llvm::Module  = CGM.getModule();
+  // SPIR v2.0 s2.12 - The SPIR version used by the module is stored in the
+  // opencl.spir.version named metadata.
+  llvm::Metadata *SPIRVerElts[] = {
+  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(Int32Ty, 2)),
+  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(Int32Ty, 0))};
+  llvm::NamedMDNode *SPIRVerMD =
+  M.getOrInsertNamedMetadata("opencl.spir.version");
+  SPIRVerMD->addOperand(llvm::MDNode::get(Ctx, SPIRVerElts));
+  // SPIR v2.0 s2.13 - The OpenCL version used by the module is stored in the
+  // opencl.ocl.version named metadata node.
+  llvm::Metadata *OCLVerElts[] = {
+  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
+  Int32Ty, CGM.getLangOpts().OpenCLVersion / 100)),
+  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
+  Int32Ty, (CGM.getLangOpts().OpenCLVersion % 100) / 10))};
+  llvm::NamedMDNode *OCLVerMD =
+  M.getOrInsertNamedMetadata("opencl.ocl.version");
+  OCLVerMD->addOperand(llvm::MDNode::get(Ctx, OCLVerElts));
+}
+
 static bool appendType(SmallStringEnc , QualType QType,
const CodeGen::CodeGenModule ,
TypeStringCache );
@@ -7707,5 +7748,8 @@
 return *(TheTargetCodeGenInfo = new SparcV9TargetCodeGenInfo(Types));
   case llvm::Triple::xcore:
 return *(TheTargetCodeGenInfo = new XCoreTargetCodeGenInfo(Types));
+  case llvm::Triple::spir:
+  case llvm::Triple::spir64:
+return *(TheTargetCodeGenInfo = new SPIRTargetCodeGenInfo(Types));
   }
 }


Index: test/CodeGenOpenCL/spir_version.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/spir_version.cl
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 %s -triple "spir-unknown-unknown" -emit-llvm -o - | FileCheck %s --check-prefix=CL10
+// RUN: %clang_cc1 %s -triple "spir-unknown-unknown" -emit-llvm -o - -cl-std=CL1.2 | FileCheck %s --check-prefix=CL12
+// RUN: %clang_cc1 %s -triple "spir-unknown-unknown" -emit-llvm -o - -cl-std=CL2.0 | FileCheck %s --check-prefix=CL20
+// RUN: %clang_cc1 %s -triple "spir64-unknown-unknown" -emit-llvm -o - | FileCheck %s --check-prefix=CL10
+// RUN: %clang_cc1 %s -triple "spir64-unknown-unknown" -emit-llvm -o - -cl-std=CL1.2 | 

Re: [PATCH] D17955: [OpenCL] Fix pipe builtin bugs

2016-03-21 Thread Xiuli PAN via cfe-commits
pxli168 updated this revision to Diff 51140.
pxli168 added a comment.

Refine other check using the changed diag.
Change test as well.


http://reviews.llvm.org/D17955

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaChecking.cpp
  test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl

Index: test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl
===
--- test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl
+++ test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl
@@ -7,20 +7,20 @@
   // read/write_pipe
   read_pipe(tmp, p);// expected-error {{first argument to 'read_pipe' must be a pipe type}}
   read_pipe(p);   // expected-error {{invalid number of arguments to function: 'read_pipe'}}
-  read_pipe(p, tmp, tmp, ptr);   // expected-error {{invalid argument type to function 'read_pipe' (expecting 'reserve_id_t')}}
-  read_pipe(p, rid, rid, ptr);   // expected-error {{invalid argument type to function 'read_pipe' (expecting 'unsigned int')}}
-  read_pipe(p, tmp);   // expected-error {{invalid argument type to function 'read_pipe' (expecting 'int *')}}
+  read_pipe(p, tmp, tmp, ptr);   // expected-error {{invalid argument type to function 'read_pipe' (expecting 'reserve_id_t' having 'int')}}
+  read_pipe(p, rid, rid, ptr);   // expected-error {{invalid argument type to function 'read_pipe' (expecting 'unsigned int' having 'reserve_id_t')}}
+  read_pipe(p, tmp);   // expected-error {{invalid argument type to function 'read_pipe' (expecting 'int *' having 'int')}}
   write_pipe(p, ptr);// expected-error {{invalid pipe access modifier (expecting write_only)}}
   write_pipe(p, rid, tmp, ptr);// expected-error {{invalid pipe access modifier (expecting write_only)}}
 
   // reserve_read/write_pipe
-  reserve_read_pipe(p, ptr);// expected-error{{invalid argument type to function 'reserve_read_pipe' (expecting 'unsigned int')}}
+  reserve_read_pipe(p, ptr);// expected-error{{invalid argument type to function 'reserve_read_pipe' (expecting 'unsigned int' having '__global int *')}}
   work_group_reserve_read_pipe(tmp, tmp);// expected-error{{first argument to 'work_group_reserve_read_pipe' must be a pipe type}}
   sub_group_reserve_write_pipe(p, tmp);// expected-error{{invalid pipe access modifier (expecting write_only)}}
 
   // commit_read/write_pipe
   commit_read_pipe(tmp, rid);// expected-error{{first argument to 'commit_read_pipe' must be a pipe type}}
-  work_group_commit_read_pipe(p, tmp);// expected-error{{invalid argument type to function 'work_group_commit_read_pipe' (expecting 'reserve_id_t')}}
+  work_group_commit_read_pipe(p, tmp);// expected-error{{invalid argument type to function 'work_group_commit_read_pipe' (expecting 'reserve_id_t' having 'int')}}
   sub_group_commit_write_pipe(p, tmp);// expected-error{{invalid pipe access modifier (expecting write_only)}}
 }
 
@@ -31,20 +31,20 @@
   // read/write_pipe
   write_pipe(tmp, p);// expected-error {{first argument to 'write_pipe' must be a pipe type}}
   write_pipe(p);   // expected-error {{invalid number of arguments to function: 'write_pipe'}}
-  write_pipe(p, tmp, tmp, ptr);   // expected-error {{invalid argument type to function 'write_pipe' (expecting 'reserve_id_t')}}
-  write_pipe(p, rid, rid, ptr);   // expected-error {{invalid argument type to function 'write_pipe' (expecting 'unsigned int')}}
-  write_pipe(p, tmp);   // expected-error {{invalid argument type to function 'write_pipe' (expecting 'int *')}}
+  write_pipe(p, tmp, tmp, ptr);   // expected-error {{invalid argument type to function 'write_pipe' (expecting 'reserve_id_t' having 'int')}}
+  write_pipe(p, rid, rid, ptr);   // expected-error {{invalid argument type to function 'write_pipe' (expecting 'unsigned int' having 'reserve_id_t')}}
+  write_pipe(p, tmp);   // expected-error {{invalid argument type to function 'write_pipe' (expecting 'int *' having 'int')}}
   read_pipe(p, ptr);// expected-error {{invalid pipe access modifier (expecting read_only)}}
   read_pipe(p, rid, tmp, ptr);// expected-error {{invalid pipe access modifier (expecting read_only)}}
 
   // reserve_read/write_pipe
-  reserve_write_pipe(p, ptr);// expected-error{{invalid argument type to function 'reserve_write_pipe' (expecting 'unsigned int')}}
+  reserve_write_pipe(p, ptr);// expected-error{{invalid argument type to function 'reserve_write_pipe' (expecting 'unsigned int' having '__global int *')}}
   work_group_reserve_write_pipe(tmp, tmp);// expected-error{{first argument to 'work_group_reserve_write_pipe' must be a pipe type}}
   sub_group_reserve_read_pipe(p, tmp);// expected-error{{invalid pipe access modifier (expecting read_only)}}
 
   // commit_read/write_pipe
   commit_write_pipe(tmp, rid);// expected-error{{first argument to 'commit_write_pipe' must be a pipe type}}
-  work_group_commit_write_pipe(p, tmp);// expected-error{{invalid argument type to function 

Re: [PATCH] D17596: [OpenCL] Add ocl and spir version for spir target

2016-03-20 Thread Xiuli PAN via cfe-commits
pxli168 updated this revision to Diff 51126.

http://reviews.llvm.org/D17596

Files:
  lib/CodeGen/TargetInfo.cpp
  test/CodeGenOpenCL/spir_version.cl

Index: test/CodeGenOpenCL/spir_version.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/spir_version.cl
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 %s -triple "spir-unknown-unknown" -emit-llvm -o - | 
FileCheck %s --check-prefix=CL10
+// RUN: %clang_cc1 %s -triple "spir-unknown-unknown" -emit-llvm -o - 
-cl-std=CL1.2 | FileCheck %s --check-prefix=CL12
+// RUN: %clang_cc1 %s -triple "spir-unknown-unknown" -emit-llvm -o - 
-cl-std=CL2.0 | FileCheck %s --check-prefix=CL20
+kernel void foo() {}
+// CL10: !opencl.spir.version = !{[[SPIR:![0-9]+]]}
+// CL10: !opencl.ocl.version = !{[[OCL:![0-9]+]]}
+// CL10: [[SPIR]] = !{i32 2, i32 0}
+// CL10: [[OCL]] = !{i32 1, i32 0}
+// CL12: !opencl.spir.version = !{[[SPIR:![0-9]+]]}
+// CL12: !opencl.ocl.version = !{[[OCL:![0-9]+]]}
+// CL12: [[SPIR]] = !{i32 2, i32 0}
+// CL12: [[OCL]] = !{i32 1, i32 2}
+// CL20: !opencl.spir.version = !{[[SPIR:![0-9]+]]}
+// CL20: !opencl.ocl.version = !{[[SPIR:![0-9]+]]}
+// CL20: [[SPIR]] = !{i32 2, i32 0}
Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -7217,6 +7217,47 @@
   }
 }
 
+//===--===//
+// SPIR ABI Implementation
+//===--===//
+
+namespace {
+class SPIRTargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  SPIRTargetCodeGenInfo(CodeGen::CodeGenTypes )
+: TargetCodeGenInfo(new DefaultABIInfo(CGT)) {}
+  void emitTargetMD(const Decl *D, llvm::GlobalValue *GV,
+CodeGen::CodeGenModule ) const override;
+};
+} // End anonymous namespace.
+
+/// Emit SPIR specific metadata: OpenCL and SPIR version.
+void SPIRTargetCodeGenInfo::emitTargetMD(const Decl *D, llvm::GlobalValue *GV,
+ CodeGen::CodeGenModule ) const {
+  assert(CGM.getLangOpts().OpenCL && "SPIR is only for OpenCL");
+  llvm::LLVMContext  = CGM.getModule().getContext();
+  llvm::Type *Int32Ty = llvm::Type::getInt32Ty(Ctx);
+  llvm::Module  = CGM.getModule();
+  // SPIR v2.0 s2.12 - The SPIR version used by the module is stored in the
+  // opencl.spir.version named metadata.
+  llvm::Metadata *SPIRVerElts[] = {
+  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(Int32Ty, 2)),
+  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(Int32Ty, 0))};
+  llvm::NamedMDNode *SPIRVerMD =
+  M.getOrInsertNamedMetadata("opencl.spir.version");
+  SPIRVerMD->addOperand(llvm::MDNode::get(Ctx, SPIRVerElts));
+  // SPIR v2.0 s2.13 - The OpenCL version used by the module is stored in the
+  // opencl.ocl.version named metadata node.
+  llvm::Metadata *OCLVerElts[] = {
+  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
+  Int32Ty, CGM.getLangOpts().OpenCLVersion / 100)),
+  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
+  Int32Ty, (CGM.getLangOpts().OpenCLVersion % 100) / 10))};
+  llvm::NamedMDNode *OCLVerMD =
+  M.getOrInsertNamedMetadata("opencl.ocl.version");
+  OCLVerMD->addOperand(llvm::MDNode::get(Ctx, OCLVerElts));
+}
+
 static bool appendType(SmallStringEnc , QualType QType,
const CodeGen::CodeGenModule ,
TypeStringCache );
@@ -7707,5 +7748,8 @@
 return *(TheTargetCodeGenInfo = new SparcV9TargetCodeGenInfo(Types));
   case llvm::Triple::xcore:
 return *(TheTargetCodeGenInfo = new XCoreTargetCodeGenInfo(Types));
+  case llvm::Triple::spir:
+  case llvm::Triple::spir64:
+return *(TheTargetCodeGenInfo = new SPIRTargetCodeGenInfo(Types));
   }
 }


Index: test/CodeGenOpenCL/spir_version.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/spir_version.cl
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 %s -triple "spir-unknown-unknown" -emit-llvm -o - | FileCheck %s --check-prefix=CL10
+// RUN: %clang_cc1 %s -triple "spir-unknown-unknown" -emit-llvm -o - -cl-std=CL1.2 | FileCheck %s --check-prefix=CL12
+// RUN: %clang_cc1 %s -triple "spir-unknown-unknown" -emit-llvm -o - -cl-std=CL2.0 | FileCheck %s --check-prefix=CL20
+kernel void foo() {}
+// CL10: !opencl.spir.version = !{[[SPIR:![0-9]+]]}
+// CL10: !opencl.ocl.version = !{[[OCL:![0-9]+]]}
+// CL10: [[SPIR]] = !{i32 2, i32 0}
+// CL10: [[OCL]] = !{i32 1, i32 0}
+// CL12: !opencl.spir.version = !{[[SPIR:![0-9]+]]}
+// CL12: !opencl.ocl.version = !{[[OCL:![0-9]+]]}
+// CL12: [[SPIR]] = !{i32 2, i32 0}
+// CL12: [[OCL]] = !{i32 1, i32 2}
+// CL20: !opencl.spir.version = !{[[SPIR:![0-9]+]]}
+// CL20: !opencl.ocl.version = !{[[SPIR:![0-9]+]]}
+// CL20: [[SPIR]] = !{i32 2, i32 0}
Index: lib/CodeGen/TargetInfo.cpp

Re: [PATCH] D17596: [OpenCL] Add ocl and spir version for spir target

2016-03-20 Thread Xiuli PAN via cfe-commits
pxli168 marked 2 inline comments as done.
pxli168 added a comment.

http://reviews.llvm.org/D17596



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


Re: [PATCH] D17596: [OpenCL] Add ocl and spir version for spir target

2016-03-20 Thread Xiuli PAN via cfe-commits
pxli168 added inline comments.


Comment at: test/CodeGenOpenCL/spir_version.cl:15
@@ +14,2 @@
+// CL20: !opencl.ocl.version = !{[[SPIR:![0-9]+]]}
+// CL20: [[SPIR]] = !{i32 2, i32 0}

Anastasia wrote:
> Forgotten to check OpenCL version here?
The metadate will be merged into the same one, so there will be only one 2.0 
here.


http://reviews.llvm.org/D17596



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


RE: r257254 - [OpenCL] Pipe type support

2016-03-16 Thread xiuli pan via cfe-commits
I will look into this bug and find out why this happen.

-Original Message-
From: Anastasia Stulova [mailto:anastasia.stul...@arm.com] 
Sent: Tuesday, March 15, 2016 5:56 PM
To: Xiuli Pan <xiuli...@outlook.com>; cfe-commits@lists.llvm.org
Cc: nd <n...@arm.com>
Subject: RE: r257254 - [OpenCL] Pipe type support

It seems we are not printing and dumping the type correctly.

Currently we get this if we call PipeType::dump():
PipeType 0x9b14ce0 'pipe'

But we should have something like (for 'pipe int p'):
PipeType 0x9b14ce0 'pipe int'
`-BuiltinType 0x9adeed0 'int'

It should be similar to atomic or pointer types.

Cheer,
Anastasia

-Original Message-
From: cfe-commits [mailto:cfe-commits-boun...@lists.llvm.org] On Behalf Of 
Xiuli Pan via cfe-commits
Sent: 09 January 2016 12:53
To: cfe-commits@lists.llvm.org
Subject: r257254 - [OpenCL] Pipe type support

Author: pxl
Date: Sat Jan  9 06:53:17 2016
New Revision: 257254

URL: http://llvm.org/viewvc/llvm-project?rev=257254=rev
Log:
[OpenCL] Pipe type support

Summary:
Support for OpenCL 2.0 pipe type.
This is a bug-fix version for bader's patch reviews.llvm.org/D14441


Reviewers: pekka.jaaskelainen, Anastasia

Subscribers: bader, Anastasia, cfe-commits

Differential Revision: http://reviews.llvm.org/D15603

Added:
cfe/trunk/test/CodeGenOpenCL/pipe_types.cl
cfe/trunk/test/SemaOpenCL/invalid-pipes-cl2.0.cl
cfe/trunk/test/SemaOpenCL/pipes-1.2-negative.cl
Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/include/clang/AST/TypeLoc.h
cfe/trunk/include/clang/AST/TypeNodes.def
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Basic/Specifiers.h
cfe/trunk/include/clang/Basic/TokenKinds.def
cfe/trunk/include/clang/Sema/DeclSpec.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/include/clang/Serialization/ASTBitCodes.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/lib/AST/ItaniumMangle.cpp
cfe/trunk/lib/AST/MicrosoftMangle.cpp
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/lib/AST/TypePrinter.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.h
cfe/trunk/lib/CodeGen/CGOpenCLRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenCLRuntime.h
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Sema/DeclSpec.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaLookup.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/lib/Sema/TreeTransform.h
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/test/PCH/ocl_types.cl
cfe/trunk/test/PCH/ocl_types.h
cfe/trunk/tools/libclang/CIndex.cpp

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=257254=257253=257254=diff
==
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Sat Jan  9 06:53:17 2016
@@ -131,6 +131,7 @@ class ASTContext : public RefCountedBase
   mutable llvm::FoldingSet AutoTypes;
   mutable llvm::FoldingSet AtomicTypes;
   llvm::FoldingSet AttributedTypes;
+  mutable llvm::FoldingSet PipeTypes;
 
   mutable llvm::FoldingSet QualifiedTemplateNames;
   mutable llvm::FoldingSet DependentTemplateNames;
@@ -1079,6 +1080,9 @@ public:
   /// blocks.
   QualType getBlockDescriptorType() const;
 
+  /// \brief Return pipe type for the specified type.
+  QualType getPipeType(QualType T) const;
+
   /// Gets the struct used to keep track of the extended descriptor for
   /// pointer to blocks.
   QualType getBlockDescriptorExtendedType() const;

Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=257254=257253=257254=diff
==
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original)
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Sat Jan  9 06:53:17 2016
@@ -978,6 +978,8 @@ DEF_TRAVERSE_TYPE(ObjCObjectPointerType,
 
 DEF_TRAVERSE_TYPE(AtomicType, { TRY_TO(TraverseType(T->getValueType())); })
 
+DEF_TRAVERSE_TYPE(PipeType, { TRY_TO(TraverseType(T->getElementType())); })
+
 #undef DEF_TRAVERSE_TYPE
 
 // - TypeLoc traversal -
@@ -1206,6 +1208,8 @@ DEF_TRAVERSE_TYPELOC(ObjCObjectPointerTy
 
 DEF_TRAVERSE_TYPELOC(At

Re: [PATCH] D17412: PR19957: [OpenCL] incorrectly accepts implicit address space conversion with ternary operator

2016-03-15 Thread Xiuli PAN via cfe-commits
pxli168 added inline comments.


Comment at: lib/AST/ASTContext.cpp:7613
@@ +7612,3 @@
+if (getLangOpts().OpenCL) {
+  if (LHS.getUnqualifiedType() != RHS.getUnqualifiedType() ||
+  LQuals.getCVRQualifiers() != RQuals.getCVRQualifiers())

Anastasia wrote:
> Do you think we should check the types here? I was thinking we should do the 
> check exactly as below apart from AS specific part.
I think the mergeType function it very complex, too. It seems to check type can 
be merged recursively later.


Comment at: lib/Sema/SemaExpr.cpp:6168
@@ -6168,3 +6167,3 @@
   QualType CompositeTy = S.Context.mergeTypes(lhptee, rhptee);
 
   if (CompositeTy.isNull()) {

Anastasia wrote:
> Could we instead add a comment explaining different cases with AS we can have 
> here i.e. 1(a-c)&2(a-c)!
> 
> And may be we could refer to each case by adding comments in code below.
Good idea.


Comment at: lib/Sema/SemaExpr.cpp:6222-6227
@@ -6188,1 +6221,8 @@
+auto ResultAddrSpace = ResultTy.getQualifiers().getAddressSpace();
+LHSCastKind = lhQual.getAddressSpace() == ResultAddrSpace
+  ? CK_BitCast
+  : CK_AddressSpaceConversion;
+RHSCastKind = rhQual.getAddressSpace() == ResultAddrSpace
+  ? CK_BitCast
+  : CK_AddressSpaceConversion;
 ResultTy = S.Context.getPointerType(ResultTy);

Anastasia wrote:
> pxli168 wrote:
> > What will mergetypes return?
> > It seems the LHS and RHS are compatibel here, and may be they did not need 
> > bitcast?
> I think we always need a cast here, because types are not exactly the same at 
> this point!
I tried to figure out what mergetypes will return and find it seems to have 
logic far more complex than this.


Repository:
  rL LLVM

http://reviews.llvm.org/D17412



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


Re: [PATCH] D17412: PR19957: [OpenCL] incorrectly accepts implicit address space conversion with ternary operator

2016-03-09 Thread Xiuli PAN via cfe-commits
pxli168 added a comment.

The logic is still to complex and I hope it can be optimized.



Comment at: lib/Sema/SemaExpr.cpp:6222-6227
@@ -6188,1 +6221,8 @@
+auto ResultAddrSpace = ResultTy.getQualifiers().getAddressSpace();
+LHSCastKind = lhQual.getAddressSpace() == ResultAddrSpace
+  ? CK_BitCast
+  : CK_AddressSpaceConversion;
+RHSCastKind = rhQual.getAddressSpace() == ResultAddrSpace
+  ? CK_BitCast
+  : CK_AddressSpaceConversion;
 ResultTy = S.Context.getPointerType(ResultTy);

What will mergetypes return?
It seems the LHS and RHS are compatibel here, and may be they did not need 
bitcast?


Repository:
  rL LLVM

http://reviews.llvm.org/D17412



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


[PATCH] D17955: [OpenCL] Fix piep builtin bug

2016-03-08 Thread Xiuli PAN via cfe-commits
pxli168 created this revision.
pxli168 added reviewers: Anastasia, yaxunl.
pxli168 added subscribers: cfe-commits, pekka.jaaskelainen.

1. Diag should be output if types are not the same.
2. Should compare using canonical type.
3. Refine the diag to be more clear.

http://reviews.llvm.org/D17955

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaChecking.cpp

Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -323,10 +323,12 @@
   const PointerType *ArgTy = ArgIdx->getType()->getAs();
   // The Idx argument should be a pointer and the type of the pointer and
   // the type of pipe element should also be the same.
-  if (!ArgTy || S.Context.hasSameType(EltTy, ArgTy->getPointeeType())) {
+  if (!ArgTy ||
+  !S.Context.hasSameType(
+  EltTy, ArgTy->getPointeeType()->getCanonicalTypeInternal())) {
 S.Diag(Call->getLocStart(), diag::err_opencl_builtin_pipe_invalid_arg)
 << Call->getDirectCallee() << S.Context.getPointerType(EltTy)
-<< ArgIdx->getSourceRange();
+<< ArgIdx->getType() << ArgIdx->getSourceRange();
 return true;
   }
   return false;
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -7753,7 +7753,7 @@
 def err_opencl_builtin_pipe_arg_num : Error<
   "invalid number of arguments to function: %0">;
 def err_opencl_builtin_pipe_invalid_arg : Error<
-  "invalid argument type to function %0 (expecting %1)">;
+  "invalid argument type to function %0 (expecting %1 having %2)">;
 def err_opencl_builtin_pipe_invalid_access_modifier : Error<
   "invalid pipe access modifier (expecting %0)">;
 


Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -323,10 +323,12 @@
   const PointerType *ArgTy = ArgIdx->getType()->getAs();
   // The Idx argument should be a pointer and the type of the pointer and
   // the type of pipe element should also be the same.
-  if (!ArgTy || S.Context.hasSameType(EltTy, ArgTy->getPointeeType())) {
+  if (!ArgTy ||
+  !S.Context.hasSameType(
+  EltTy, ArgTy->getPointeeType()->getCanonicalTypeInternal())) {
 S.Diag(Call->getLocStart(), diag::err_opencl_builtin_pipe_invalid_arg)
 << Call->getDirectCallee() << S.Context.getPointerType(EltTy)
-<< ArgIdx->getSourceRange();
+<< ArgIdx->getType() << ArgIdx->getSourceRange();
 return true;
   }
   return false;
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -7753,7 +7753,7 @@
 def err_opencl_builtin_pipe_arg_num : Error<
   "invalid number of arguments to function: %0">;
 def err_opencl_builtin_pipe_invalid_arg : Error<
-  "invalid argument type to function %0 (expecting %1)">;
+  "invalid argument type to function %0 (expecting %1 having %2)">;
 def err_opencl_builtin_pipe_invalid_access_modifier : Error<
   "invalid pipe access modifier (expecting %0)">;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r262692 - [OpenCL] Refine pipe builtin support

2016-03-03 Thread Xiuli Pan via cfe-commits
Author: pxl
Date: Fri Mar  4 01:11:16 2016
New Revision: 262692

URL: http://llvm.org/viewvc/llvm-project?rev=262692=rev
Log:
[OpenCL] Refine pipe builtin support

Summary:
Refine the type builtin support as the request with
http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20160201/148637.html

Reviewers: pekka.jaaskelainen, Anastasia, yaxunl

Subscribers: rsmith, cfe-commits

Differential Revision: http://reviews.llvm.org/D16876

Modified:
cfe/trunk/include/clang/Basic/Builtins.h
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl

Modified: cfe/trunk/include/clang/Basic/Builtins.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.h?rev=262692=262691=262692=diff
==
--- cfe/trunk/include/clang/Basic/Builtins.h (original)
+++ cfe/trunk/include/clang/Basic/Builtins.h Fri Mar  4 01:11:16 2016
@@ -31,12 +31,12 @@ class QualType;
 class LangOptions;
 
 enum LanguageID {
-  GNU_LANG = 0x1,  // builtin requires GNU mode.
-  C_LANG = 0x2,// builtin for c only.
-  CXX_LANG = 0x4,  // builtin for cplusplus only.
-  OBJC_LANG = 0x8, // builtin for objective-c and objective-c++
-  MS_LANG = 0x10,  // builtin requires MS mode.
-  OCLC_LANG = 0x20,// builtin for OpenCL C only.
+  GNU_LANG = 0x1, // builtin requires GNU mode.
+  C_LANG = 0x2,   // builtin for c only.
+  CXX_LANG = 0x4, // builtin for cplusplus only.
+  OBJC_LANG = 0x8,// builtin for objective-c and objective-c++
+  MS_LANG = 0x10, // builtin requires MS mode.
+  OCLC_LANG = 0x20,   // builtin for OpenCL C only.
   ALL_LANGUAGES = C_LANG | CXX_LANG | OBJC_LANG, // builtin for all languages.
   ALL_GNU_LANGUAGES = ALL_LANGUAGES | GNU_LANG,  // builtin requires GNU mode.
   ALL_MS_LANGUAGES = ALL_LANGUAGES | MS_LANG // builtin requires MS mode.

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=262692=262691=262692=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Mar  4 01:11:16 
2016
@@ -7746,7 +7746,7 @@ def err_opencl_type_can_only_be_used_as_
 def err_opencl_builtin_pipe_first_arg : Error<
   "first argument to %0 must be a pipe type">;
 def err_opencl_builtin_pipe_arg_num : Error<
-"invalid number of arguments to function: %0">;
+  "invalid number of arguments to function: %0">;
 def err_opencl_builtin_pipe_invalid_arg : Error<
   "invalid argument type to function %0 (expecting %1)">;
 def err_opencl_builtin_pipe_invalid_access_modifier : Error<

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=262692=262691=262692=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Fri Mar  4 01:11:16 2016
@@ -259,16 +259,9 @@ static bool SemaBuiltinSEHScopeCheck(Sem
   return false;
 }
 
-/// Returns readable name for a call.
-static StringRef getFunctionName(CallExpr *Call) {
-  return cast(Call->getCalleeDecl())->getName();
-}
-
 /// Returns OpenCL access qual.
 static OpenCLAccessAttr *getOpenCLArgAccess(const Decl *D) {
-  if (D->hasAttr())
 return D->getAttr();
-  return nullptr;
 }
 
 /// Returns true if pipe element type is different from the pointer.
@@ -277,7 +270,7 @@ static bool checkOpenCLPipeArg(Sema ,
   // First argument type should always be pipe.
   if (!Arg0->getType()->isPipeType()) {
 S.Diag(Call->getLocStart(), diag::err_opencl_builtin_pipe_first_arg)
-<< getFunctionName(Call) << Arg0->getSourceRange();
+<< Call->getDirectCallee() << Arg0->getSourceRange();
 return true;
   }
   OpenCLAccessAttr *AccessQual =
@@ -286,20 +279,38 @@ static bool checkOpenCLPipeArg(Sema ,
   // OpenCL v2.0 s6.13.16 - The access qualifiers for pipe should only be
   // read_only and write_only, and assumed to be read_only if no qualifier is
   // specified.
-  bool isValid = true;
-  bool ReadOnly = getFunctionName(Call).find("read") != StringRef::npos;
-  if (ReadOnly)
-isValid = AccessQual == nullptr || AccessQual->isReadOnly();
-  else
-isValid = AccessQual != nullptr && AccessQual->isWriteOnly();
-  if (!isValid) {
-const char *AM = ReadOnly ? "read_only" : "write_only";
-S.Diag(Arg0->getLocStart(),
-   diag::err_opencl_builtin_pipe_invalid_access_modifier)
-<< AM << Arg0->getSourceRange();
-return true;
+  switch (Call->getDirectCallee()->getBuiltinID()) {
+  case Builtin::BIread_pipe:
+  case Builtin::BIreserve_read_pipe:
+  case Builtin::BIcommit_read_pipe:
+  case 

Re: [PATCH] D17412: PR19957: [OpenCL] incorrectly accepts implicit address space conversion with ternary operator

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


Comment at: lib/Sema/SemaExpr.cpp:6194-6203
@@ +6193,12 @@
+
+  incompatTy = S.Context.getPointerType(
+  S.Context.getAddrSpaceQualType(S.Context.VoidTy, ResultAddrSpace));
+  LHS = S.ImpCastExprToType(LHS.get(), incompatTy,
+(lhQual.getAddressSpace() != ResultAddrSpace)
+? CK_AddressSpaceConversion
+: CK_BitCast);
+  RHS = S.ImpCastExprToType(RHS.get(), incompatTy,
+(rhQual.getAddressSpace() != ResultAddrSpace)
+? CK_AddressSpaceConversion
+: CK_BitCast);
+} else {

I am quite confused by these codes. It seems in some situations you need both 
BitCast and AddressSpaceConversion.
It seems the logic here is too complex. Maybe you can try to simplify it



Comment at: lib/Sema/SemaExpr.cpp:6220-6232
@@ -6186,7 +6219,15 @@
 ResultTy = S.Context.getBlockPointerType(ResultTy);
-  else
+  else {
+auto ResultAddrSpace = ResultTy.getQualifiers().getAddressSpace();
+LHSCastKind = lhQual.getAddressSpace() == ResultAddrSpace
+  ? CK_BitCast
+  : CK_AddressSpaceConversion;
+RHSCastKind = rhQual.getAddressSpace() == ResultAddrSpace
+  ? CK_BitCast
+  : CK_AddressSpaceConversion;
 ResultTy = S.Context.getPointerType(ResultTy);
+  }
 
-  LHS = S.ImpCastExprToType(LHS.get(), ResultTy, CK_BitCast);
-  RHS = S.ImpCastExprToType(RHS.get(), ResultTy, CK_BitCast);
+  LHS = S.ImpCastExprToType(LHS.get(), ResultTy, LHSCastKind);
+  RHS = S.ImpCastExprToType(RHS.get(), ResultTy, RHSCastKind);
   return ResultTy;

Why change about block pointer?
Block can not be used with ternary selection operator (?:) in OpenCL.


Repository:
  rL LLVM

http://reviews.llvm.org/D17412



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


r261961 - [OpenCL] Refine OpenCLImageAccessAttr to OpenCLAccessAttr

2016-02-25 Thread Xiuli Pan via cfe-commits
Author: pxl
Date: Thu Feb 25 21:13:03 2016
New Revision: 261961

URL: http://llvm.org/viewvc/llvm-project?rev=261961=rev
Log:
[OpenCL] Refine OpenCLImageAccessAttr to OpenCLAccessAttr

Summary:
OpenCL access qualifiers are now not only used for image types, refine it to 
avoid misleading,

Add semacheck for OpenCL access qualifier as well as test caees.

Reviewers: pekka.jaaskelainen, Anastasia, aaron.ballman

Subscribers: aaron.ballman, cfe-commits

Differential Revision: http://reviews.llvm.org/D16040

Added:
cfe/trunk/test/SemaOpenCL/invalid-access-qualifier.cl
Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/include/clang/Basic/AttrDocs.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/Parser/opencl-image-access.cl
cfe/trunk/test/SemaOpenCL/invalid-kernel-attrs.cl
cfe/trunk/test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=261961=261960=261961=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Thu Feb 25 21:13:03 2016
@@ -664,7 +664,7 @@ def OpenCLUnrollHint : InheritableAttr {
 
 // This attribute is both a type attribute, and a declaration attribute (for
 // parameter variables).
-def OpenCLImageAccess : Attr {
+def OpenCLAccess : Attr {
   let Spellings = [Keyword<"__read_only">, Keyword<"read_only">,
Keyword<"__write_only">, Keyword<"write_only">,
Keyword<"__read_write">, Keyword<"read_write">];
@@ -675,7 +675,7 @@ def OpenCLImageAccess : Attr {
 Keyword<"read_write">]>,
Accessor<"isWriteOnly", [Keyword<"__write_only">,
 Keyword<"write_only">]>];
-  let Documentation = [Undocumented];
+  let Documentation = [OpenCLAccessDocs];
 }
 
 def OpenCLPrivateAddressSpace : TypeAttr {

Modified: cfe/trunk/include/clang/Basic/AttrDocs.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/AttrDocs.td?rev=261961=261960=261961=diff
==
--- cfe/trunk/include/clang/Basic/AttrDocs.td (original)
+++ cfe/trunk/include/clang/Basic/AttrDocs.td Thu Feb 25 21:13:03 2016
@@ -1581,6 +1581,32 @@ s6.11.5 for details.
   }];
 }
 
+def OpenCLAccessDocs : Documentation {
+  let Category = DocCatStmt;
+  let Content = [{
+The access qualifiers must be used with image object arguments or pipe 
arguments
+to declare if they are being read or written by a kernel or function.
+
+The read_only/__read_only, write_only/__write_only and read_write/__read_write
+names are reserved for use as access qualifiers and shall not be used 
otherwise.
+
+  .. code-block:: c
+  kernel void
+  foo (read_only image2d_t imageA,
+  write_only image2d_t imageB)
+  {
+  ...
+  }
+
+In the above example imageA is a read-only 2D image object, and imageB is a
+write-only 2D image object.
+
+The read_write (or __read_write) qualifier can not be used with pipe.
+
+More details can be found in the OpenCL C language Spec v2.0, Section 6.6.
+  }];
+}
+
 def DocOpenCLAddressSpaces : DocumentationCategory<"OpenCL Address Spaces"> {
   let Content = [{
 The address space qualifier may be used to specify the region of memory that is

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=261961=261960=261961=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Feb 25 21:13:03 
2016
@@ -7735,6 +7735,14 @@ def err_opencl_builtin_pipe_invalid_arg
 def err_opencl_builtin_pipe_invalid_access_modifier : Error<
   "invalid pipe access modifier (expecting %0)">;
 
+// OpenCL access qualifier
+def err_opencl_invalid_access_qualifier : Error<
+  "access qualifier can only be used for pipe and image type">;
+def err_opencl_invalid_read_write : Error<
+  "access qualifier %0 can not be used for %1 %select{|earlier than OpenCL2.0 
version}2">;
+def err_opencl_multiple_access_qualifiers : Error<
+  "multiple access qualifiers">;
+
 // OpenCL Section 6.8.g
 def err_opencl_unknown_type_specifier : Error<
   "OpenCL does not support the '%0' %select{type qualifier|storage class 
specifier}1">;

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=261961=261960=261961=diff

Re: [PATCH] D17596: [OpenCL] Add ocl and spir version for spir target

2016-02-25 Thread Xiuli PAN via cfe-commits
pxli168 marked an inline comment as done.
pxli168 added a comment.

I think this is just a small change to help identify the which standard llvm-ir 
is using.

And there is a SPIRV branch from Khronos
https://github.com/KhronosGroup/SPIRV-LLVM
We can start there and try to merge the spir-v support into the llvm.org trunk.


http://reviews.llvm.org/D17596



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


Re: [PATCH] D17596: [OpenCL] Add ocl and spir version for spir target

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

http://reviews.llvm.org/D17596

Files:
  lib/CodeGen/TargetInfo.cpp
  test/CodeGenOpenCL/spir_version.cl

Index: test/CodeGenOpenCL/spir_version.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/spir_version.cl
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 %s -triple "spir-unknown-unknown" -emit-llvm -o - | 
FileCheck %s --check-prefix=CL10
+// RUN: %clang_cc1 %s -triple "spir-unknown-unknown" -emit-llvm -o - 
-cl-std=CL1.2 | FileCheck %s --check-prefix=CL12
+// RUN: %clang_cc1 %s -triple "spir-unknown-unknown" -emit-llvm -o - 
-cl-std=CL2.0 | FileCheck %s --check-prefix=CL20
+kernel void foo() {}
+// CL10: !opencl.spir.version = !{[[SPIR:![0-9]+]]}
+// CL10: !opencl.ocl.version = !{[[OCL:![0-9]+]]}
+// CL10: [[SPIR]] = !{i32 2, i32 0}
+// CL10: [[OCL]] = !{i32 1, i32 0} 
+// CL12: !opencl.spir.version = !{[[SPIR:![0-9]+]]}
+// CL12: !opencl.ocl.version = !{[[OCL:![0-9]+]]}
+// CL12: [[SPIR]] = !{i32 2, i32 0}
+// CL12: [[OCL]] = !{i32 1, i32 2} 
+// CL20: !opencl.spir.version = !{[[SPIR:![0-9]+]]}
+// CL20: !opencl.ocl.version = !{[[SPIR:![0-9]+]]}
+// CL20: [[SPIR]] = !{i32 2, i32 0}
Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -7194,6 +7194,47 @@
   }
 }
 
+//===--===//
+// SPIR ABI Implementation
+//===--===//
+
+namespace {
+class SPIRTargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  SPIRTargetCodeGenInfo(CodeGen::CodeGenTypes )
+: TargetCodeGenInfo(new DefaultABIInfo(CGT)) {}
+  void emitTargetMD(const Decl *D, llvm::GlobalValue *GV,
+CodeGen::CodeGenModule ) const override;
+};
+} // End anonymous namespace.
+
+/// SPIR uses emitTargetMD to emit spir spec requried metadate.
+void SPIRTargetCodeGenInfo::emitTargetMD(const Decl *D, llvm::GlobalValue *GV,
+ CodeGen::CodeGenModule ) const {
+  assert(CGM.getLangOpts().OpenCL && "SPIR is only for OpenCL\n");
+  llvm::LLVMContext  = CGM.getModule().getContext();
+  llvm::Type *Int32Ty = llvm::Type::getInt32Ty(Ctx);
+  llvm::Module  = CGM.getModule();
+  // SPIR v2.0 s2.12 - The SPIR version used by the module is stored in the
+  // opencl.spir.version named metadata.
+  llvm::Metadata *SPIRVerElts[] = {
+  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(Int32Ty, 2)),
+  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(Int32Ty, 0))};
+  llvm::NamedMDNode *SPIRVerMD =
+  M.getOrInsertNamedMetadata("opencl.spir.version");
+  SPIRVerMD->addOperand(llvm::MDNode::get(Ctx, SPIRVerElts));
+  // SPIR v2.0 s2.13 - The OpenCL version used by the module is stored in the
+  // opencl.ocl.version named metadata node.
+  llvm::Metadata *OCLVerElts[] = {
+  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
+  Int32Ty, CGM.getLangOpts().OpenCLVersion / 100)),
+  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
+  Int32Ty, (CGM.getLangOpts().OpenCLVersion % 100) / 10))};
+  llvm::NamedMDNode *OCLVerMD =
+  M.getOrInsertNamedMetadata("opencl.ocl.version");
+  OCLVerMD->addOperand(llvm::MDNode::get(Ctx, OCLVerElts));
+}
+
 static bool appendType(SmallStringEnc , QualType QType,
const CodeGen::CodeGenModule ,
TypeStringCache );
@@ -7684,5 +7725,8 @@
 return *(TheTargetCodeGenInfo = new SparcV9TargetCodeGenInfo(Types));
   case llvm::Triple::xcore:
 return *(TheTargetCodeGenInfo = new XCoreTargetCodeGenInfo(Types));
+  case llvm::Triple::spir:
+  case llvm::Triple::spir64:
+return *(TheTargetCodeGenInfo = new SPIRTargetCodeGenInfo(Types));
   }
 }


Index: test/CodeGenOpenCL/spir_version.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/spir_version.cl
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 %s -triple "spir-unknown-unknown" -emit-llvm -o - | FileCheck %s --check-prefix=CL10
+// RUN: %clang_cc1 %s -triple "spir-unknown-unknown" -emit-llvm -o - -cl-std=CL1.2 | FileCheck %s --check-prefix=CL12
+// RUN: %clang_cc1 %s -triple "spir-unknown-unknown" -emit-llvm -o - -cl-std=CL2.0 | FileCheck %s --check-prefix=CL20
+kernel void foo() {}
+// CL10: !opencl.spir.version = !{[[SPIR:![0-9]+]]}
+// CL10: !opencl.ocl.version = !{[[OCL:![0-9]+]]}
+// CL10: [[SPIR]] = !{i32 2, i32 0}
+// CL10: [[OCL]] = !{i32 1, i32 0} 
+// CL12: !opencl.spir.version = !{[[SPIR:![0-9]+]]}
+// CL12: !opencl.ocl.version = !{[[OCL:![0-9]+]]}
+// CL12: [[SPIR]] = !{i32 2, i32 0}
+// CL12: [[OCL]] = !{i32 1, i32 2} 
+// CL20: !opencl.spir.version = !{[[SPIR:![0-9]+]]}
+// CL20: !opencl.ocl.version = !{[[SPIR:![0-9]+]]}
+// CL20: [[SPIR]] = !{i32 2, i32 0}
Index: lib/CodeGen/TargetInfo.cpp

Re: [PATCH] D17438: [OpenCL] Add Sema checks for atomics and implicit declaration

2016-02-25 Thread Xiuli PAN via cfe-commits
pxli168 added a comment.

https://cvs.khronos.org/bugzilla/show_bug.cgi?id=15603
Bug reported.


http://reviews.llvm.org/D17438



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


Re: [PATCH] D17578: [OpenCL]Allowing explicit conversion of "0" to event_t type

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


Comment at: lib/Sema/SemaCast.cpp:2324-2326
@@ +2323,5 @@
+} else {
+Self.Diag(OpRange.getBegin(),
+  diag::error_opencl_cast_non_zero_to_event_t)
+  << intValue.toString(10) << SrcExpr.get()->getSourceRange();
+SrcExpr = ExprError();

pxli168 wrote:
> Indent.
> You can try to use clang-format to help keep these right.
Need a test case for this.


http://reviews.llvm.org/D17578



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


Re: [PATCH] D17578: [OpenCL]Allowing explicit conversion of "0" to event_t type

2016-02-24 Thread Xiuli PAN via cfe-commits
pxli168 added a comment.

  foo((event_t)0);

Is above use have been hint by some test cases?



Comment at: include/clang/Basic/DiagnosticSemaKinds.td:7679
@@ -7678,2 +7678,3 @@
 def err_wrong_sampler_addressspace: Error<
-  "sampler type cannot be used with the __local and __global address space 
qualifiers">;
+  "sampler type cannot be used with the __local and __global address space 
qualifiers">;
+def error_opencl_cast_non_zero_to_event_t : Error<

Please do not use DOS format.


Comment at: lib/Sema/SemaCast.cpp:2316
@@ -2315,1 +2315,3 @@
 
+// for OpenCL, allow casts from '0' to event_t type
+if ((Self.getLangOpts().OpenCL) && DestType->isEventT()) {

1. Comments start with capital.
2. End a sentence with a period.
3. Give spec reference here, start with:
OpenCL v2.0 s6.13.10 - 


Comment at: lib/Sema/SemaCast.cpp:2317
@@ +2316,3 @@
+// for OpenCL, allow casts from '0' to event_t type
+if ((Self.getLangOpts().OpenCL) && DestType->isEventT()) {
+  llvm::APSInt intValue;

(Self.getLangOpts().OpenCL) -> Self.getLangOpts().OpenCL


Comment at: lib/Sema/SemaCast.cpp:2318
@@ +2317,3 @@
+if ((Self.getLangOpts().OpenCL) && DestType->isEventT()) {
+  llvm::APSInt intValue;
+  if(SrcExpr.get()->EvaluateAsInt(intValue, Self.getASTContext())) {

Indent.


Comment at: lib/Sema/SemaCast.cpp:2319
@@ +2318,3 @@
+  llvm::APSInt intValue;
+  if(SrcExpr.get()->EvaluateAsInt(intValue, Self.getASTContext())) {
+if(0 == intValue) {

Sema has a context.
Self.getASTContext() ->Self.Context


Comment at: lib/Sema/SemaCast.cpp:2321
@@ +2320,3 @@
+if(0 == intValue) {
+  Kind = CK_IntegralToPointer;
+  return;

There is a CK_ZeroToOCLEvent, why not use that?


Comment at: lib/Sema/SemaCast.cpp:2324-2328
@@ +2323,7 @@
+} else {
+Self.Diag(OpRange.getBegin(),
+  diag::error_opencl_cast_non_zero_to_event_t)
+  << intValue.toString(10) << SrcExpr.get()->getSourceRange();
+SrcExpr = ExprError();
+return;
+}

Indent.
You can try to use clang-format to help keep these right.


http://reviews.llvm.org/D17578



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


Re: [PATCH] D16876: [OpenCL] Refine pipe builtin support

2016-02-24 Thread Xiuli PAN via cfe-commits
pxli168 updated this revision to Diff 49008.
pxli168 added a comment.

1. Make new indent and leave space for the incoming OpenCL C++.
2. Check for the index to see if they are integers.


http://reviews.llvm.org/D16876

Files:
  include/clang/Basic/Builtins.h
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaChecking.cpp
  test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl

Index: test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl
===
--- test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl
+++ test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl
@@ -5,51 +5,51 @@
   reserve_id_t rid;
 
   // read/write_pipe
-  read_pipe(tmp, p);// expected-error {{first argument to read_pipe must be a pipe type}}
-  read_pipe(p);   // expected-error {{invalid number of arguments to function: read_pipe}}
-  read_pipe(p, tmp, tmp, ptr);   // expected-error {{invalid argument type to function read_pipe (expecting 'reserve_id_t')}}
-  read_pipe(p, rid, rid, ptr);   // expected-error {{invalid argument type to function read_pipe (expecting 'unsigned int')}}
-  read_pipe(p, tmp);   // expected-error {{invalid argument type to function read_pipe (expecting 'int *')}}
+  read_pipe(tmp, p);// expected-error {{first argument to 'read_pipe' must be a pipe type}}
+  read_pipe(p);   // expected-error {{invalid number of arguments to function: 'read_pipe'}}
+  read_pipe(p, tmp, tmp, ptr);   // expected-error {{invalid argument type to function 'read_pipe' (expecting 'reserve_id_t')}}
+  read_pipe(p, rid, rid, ptr);   // expected-error {{invalid argument type to function 'read_pipe' (expecting 'unsigned int')}}
+  read_pipe(p, tmp);   // expected-error {{invalid argument type to function 'read_pipe' (expecting 'int *')}}
   write_pipe(p, ptr);// expected-error {{invalid pipe access modifier (expecting write_only)}}
   write_pipe(p, rid, tmp, ptr);// expected-error {{invalid pipe access modifier (expecting write_only)}}
 
   // reserve_read/write_pipe
-  reserve_read_pipe(p, ptr);// expected-error{{invalid argument type to function reserve_read_pipe (expecting 'unsigned int')}}
-  work_group_reserve_read_pipe(tmp, tmp);// expected-error{{first argument to work_group_reserve_read_pipe must be a pipe type}}
+  reserve_read_pipe(p, ptr);// expected-error{{invalid argument type to function 'reserve_read_pipe' (expecting 'unsigned int')}}
+  work_group_reserve_read_pipe(tmp, tmp);// expected-error{{first argument to 'work_group_reserve_read_pipe' must be a pipe type}}
   sub_group_reserve_write_pipe(p, tmp);// expected-error{{invalid pipe access modifier (expecting write_only)}}
 
   // commit_read/write_pipe
-  commit_read_pipe(tmp, rid);// expected-error{{first argument to commit_read_pipe must be a pipe type}}
-  work_group_commit_read_pipe(p, tmp);// expected-error{{invalid argument type to function work_group_commit_read_pipe (expecting 'reserve_id_t')}}
+  commit_read_pipe(tmp, rid);// expected-error{{first argument to 'commit_read_pipe' must be a pipe type}}
+  work_group_commit_read_pipe(p, tmp);// expected-error{{invalid argument type to function 'work_group_commit_read_pipe' (expecting 'reserve_id_t')}}
   sub_group_commit_write_pipe(p, tmp);// expected-error{{nvalid pipe access modifier (expecting write_only)}}
 }
 
 void test2(write_only pipe int p, global int* ptr){
   int tmp;
   reserve_id_t rid;
 
   // read/write_pipe
-  write_pipe(tmp, p);// expected-error {{first argument to write_pipe must be a pipe type}}
-  write_pipe(p);   // expected-error {{invalid number of arguments to function: write_pipe}}
-  write_pipe(p, tmp, tmp, ptr);   // expected-error {{invalid argument type to function write_pipe (expecting 'reserve_id_t')}}
-  write_pipe(p, rid, rid, ptr);   // expected-error {{invalid argument type to function write_pipe (expecting 'unsigned int')}}
-  write_pipe(p, tmp);   // expected-error {{invalid argument type to function write_pipe (expecting 'int *')}}
+  write_pipe(tmp, p);// expected-error {{first argument to 'write_pipe' must be a pipe type}}
+  write_pipe(p);   // expected-error {{invalid number of arguments to function: 'write_pipe'}}
+  write_pipe(p, tmp, tmp, ptr);   // expected-error {{invalid argument type to function 'write_pipe' (expecting 'reserve_id_t')}}
+  write_pipe(p, rid, rid, ptr);   // expected-error {{invalid argument type to function 'write_pipe' (expecting 'unsigned int')}}
+  write_pipe(p, tmp);   // expected-error {{invalid argument type to function 'write_pipe' (expecting 'int *')}}
   read_pipe(p, ptr);// expected-error {{invalid pipe access modifier (expecting read_only)}}
   read_pipe(p, rid, tmp, ptr);// expected-error {{invalid pipe access modifier (expecting read_only)}}
 
   // reserve_read/write_pipe
-  reserve_write_pipe(p, ptr);// expected-error{{invalid argument type to function reserve_write_pipe (expecting 'unsigned int')}}
-  

Re: [PATCH] D16040: [OpenCL] Refine OpenCLImageAccessAttr to OpenCLAccessAttr

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

http://reviews.llvm.org/D16040

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/CodeGen/CodeGenFunction.cpp
  lib/Parse/ParseDecl.cpp
  lib/Sema/SemaChecking.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaType.cpp
  test/Parser/opencl-image-access.cl
  test/SemaOpenCL/invalid-access-qualifier.cl
  test/SemaOpenCL/invalid-kernel-attrs.cl
  test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl

Index: test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl
===
--- test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl
+++ test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl
@@ -21,7 +21,7 @@
   // commit_read/write_pipe
   commit_read_pipe(tmp, rid);// expected-error{{first argument to commit_read_pipe must be a pipe type}}
   work_group_commit_read_pipe(p, tmp);// expected-error{{invalid argument type to function work_group_commit_read_pipe (expecting 'reserve_id_t')}}
-  sub_group_commit_write_pipe(p, tmp);// expected-error{{nvalid pipe access modifier (expecting write_only)}}
+  sub_group_commit_write_pipe(p, tmp);// expected-error{{invalid pipe access modifier (expecting write_only)}}
 }
 
 void test2(write_only pipe int p, global int* ptr){
@@ -45,7 +45,7 @@
   // commit_read/write_pipe
   commit_write_pipe(tmp, rid);// expected-error{{first argument to commit_write_pipe must be a pipe type}}
   work_group_commit_write_pipe(p, tmp);// expected-error{{invalid argument type to function work_group_commit_write_pipe (expecting 'reserve_id_t')}}
-  sub_group_commit_read_pipe(p, tmp);// expected-error{{nvalid pipe access modifier (expecting read_only)}}
+  sub_group_commit_read_pipe(p, tmp);// expected-error{{invalid pipe access modifier (expecting read_only)}}
 }
 
 void test3(){
Index: test/SemaOpenCL/invalid-kernel-attrs.cl
===
--- test/SemaOpenCL/invalid-kernel-attrs.cl
+++ test/SemaOpenCL/invalid-kernel-attrs.cl
@@ -28,8 +28,6 @@
 
 void f_kernel_image2d_t( kernel image2d_t image ) { // expected-error {{'kernel' attribute only applies to functions}}
   int __kernel x; // expected-error {{'__kernel' attribute only applies to functions}}
-  read_only int i; // expected-error {{'read_only' attribute only applies to parameters}}
-  __write_only int j; // expected-error {{'__write_only' attribute only applies to parameters}}
 }
 
 kernel __attribute__((reqd_work_group_size(1,2,0))) void kernel11(){} // expected-error {{'reqd_work_group_size' attribute must be greater than 0}}
Index: test/SemaOpenCL/invalid-access-qualifier.cl
===
--- /dev/null
+++ test/SemaOpenCL/invalid-access-qualifier.cl
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -verify %s
+// RUN: %clang_cc1 -verify -cl-std=CL2.0 -DCL20 %s
+
+void test1(read_only int i){} // expected-error{{access qualifier can only be used for pipe and image type}}
+
+void test2(read_only write_only image1d_t i){} // expected-error{{multiple access qualifiers}}
+
+void test3(read_only read_only image1d_t i){} // expected-error{{multiple access qualifiers}}
+
+#ifdef CL20
+void test4(read_write pipe int i){} // expected-error{{access qualifier 'read_write' can not be used for 'pipe'}}
+#else
+void test4(__read_write image1d_t i){} // expected-error{{access qualifier '__read_write' can not be used for 'image1d_t' earlier than OpenCL2.0 version}}
+#endif
Index: test/Parser/opencl-image-access.cl
===
--- test/Parser/opencl-image-access.cl
+++ test/Parser/opencl-image-access.cl
@@ -1,14 +1,19 @@
-// RUN: %clang_cc1 %s -fsyntax-only
+// RUN: %clang_cc1 %s -fsyntax-only -verify
+// RUN: %clang_cc1 %s -fsyntax-only -verify -cl-std=CL2.0 -DCL20
+// expected-no-diagnostics
 
 __kernel void f__ro(__read_only image2d_t a) { }
 
 __kernel void f__wo(__write_only image2d_t a) { }
 
+#if CL20
 __kernel void f__rw(__read_write image2d_t a) { }
-
+#endif
 
 __kernel void fro(read_only image2d_t a) { }
 
 __kernel void fwo(write_only image2d_t a) { }
 
+#if CL20
 __kernel void frw(read_write image2d_t a) { }
+#endif
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -6237,6 +6237,17 @@
   CurType = S.Context.getVectorType(CurType, numElts, VecKind);
 }
 
+/// Handle OpenCL Access Qualifier Attribute.
+static void HandleOpenCLAccessAttr(QualType , const AttributeList ,
+   Sema ) {
+  // OpenCL v2.0 s6.6 - Access qualifier can used only for image and pipe type.
+  if (!(CurType->isImageType() || CurType->isPipeType())) {
+S.Diag(Attr.getLoc(), diag::err_opencl_invalid_access_qualifier);
+Attr.setInvalid();
+return;
+  }
+}
+
 static void processTypeAttrs(TypeProcessingState , QualType 

Re: [PATCH] D16040: [OpenCL] Refine OpenCLImageAccessAttr to OpenCLAccessAttr

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

Remove test case for access quilifier in 
test/SemaOpenCL/invalid-kernel-attrs.cl.
Due to the patch http://reviews.llvm.org/D17437.
read_only can only be used in parameters with pipe and image type.



Comment at: test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl:24
@@ -23,3 +23,3 @@
   work_group_commit_read_pipe(p, tmp);// expected-error{{invalid argument 
type to function work_group_commit_read_pipe (expecting 'reserve_id_t')}}
-  sub_group_commit_write_pipe(p, tmp);// expected-error{{nvalid pipe 
access modifier (expecting write_only)}}
 }

Anastasia wrote:
> Anastasia wrote:
> > This test doesn't seem to work correctly because it didn't detect that we 
> > were checking for the wrong error message!
> > 
> > I am thinking it might be the issue of adding "-ferror-limit 100" to the 
> > RUN line as it might have stopped to diagnose after certain number of 
> > errors given. Could you please double check this?
> I just checked it and I guess it's passing because it's doing substring 
> check, so no need to add anything to the RUN line. Your change is fine here!
I found these bug by testing with the access qualifier, and find some word 
missing and just add them in this patch.


http://reviews.llvm.org/D16040



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


r261818 - [OpenCL] Add Sema checks for types

2016-02-24 Thread Xiuli Pan via cfe-commits
Author: pxl
Date: Wed Feb 24 21:34:20 2016
New Revision: 261818

URL: http://llvm.org/viewvc/llvm-project?rev=261818=rev
Log:
[OpenCL] Add Sema checks for types

Summary:
Add Sema checks for opencl type: image, pipe
This patch is partitioned from http://reviews.llvm.org/D16047

Reviewers: Anastasia, yaxunl

Subscribers: pekka.jaaskelainen, cfe-commits

Differential Revision: http://reviews.llvm.org/D17437

Added:
cfe/trunk/test/SemaOpenCL/invalid-image.cl
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/CodeGenOpenCL/opencl_types.cl
cfe/trunk/test/SemaOpenCL/invalid-pipes-cl2.0.cl
cfe/trunk/test/SemaOpenCL/sampler_t.cl

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=261818=261817=261818=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Feb 24 21:34:20 
2016
@@ -7720,6 +7720,10 @@ def err_opencl_invalid_type_array : Erro
   "array of %0 type is invalid in OpenCL">;
 def err_opencl_ternary_with_block : Error<
   "block type cannot be used as expression in ternary expression in OpenCL">;
+def err_opencl_pointer_to_type : Error<
+  "pointer to type %0 is invalid in OpenCL">;
+def err_opencl_type_can_only_be_used_as_function_parameter : Error <
+  "type %0 can only be used as a function parameter in OpenCL">;
 
 // OpenCL v2.0 s6.13.6 -- Builtin Pipe Functions
 def err_opencl_builtin_pipe_first_arg : Error<

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=261818=261817=261818=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Feb 24 21:34:20 2016
@@ -5710,6 +5710,17 @@ Sema::ActOnVariableDeclarator(Scope *S,
   QualType R = TInfo->getType();
   DeclarationName Name = GetNameForDeclarator(D).getName();
 
+  // OpenCL v2.0 s6.9.b - Image type can only be used as a function argument.
+  // OpenCL v2.0 s6.13.16.1 - Pipe type can only be used as a function
+  // argument.
+  if (getLangOpts().OpenCL && (R->isImageType() || R->isPipeType())) {
+Diag(D.getIdentifierLoc(),
+ diag::err_opencl_type_can_only_be_used_as_function_parameter)
+<< R;
+D.setInvalidType();
+return nullptr;
+  }
+
   DeclSpec::SCS SCSpec = D.getDeclSpec().getStorageClassSpec();
   StorageClass SC = StorageClassSpecToVarDeclStorageClass(D.getDeclSpec());
 
@@ -10737,7 +10748,17 @@ ParmVarDecl *Sema::CheckParameter(DeclCo
   Diag(NameLoc, diag::err_arg_with_address_space);
   New->setInvalidDecl();
 }
-  }   
+  }
+
+  // OpenCL v2.0 s6.9b - Pointer to image/sampler cannot be used.
+  // OpenCL v2.0 s6.13.16.1 - Pointer to pipe cannot be used.
+  if (getLangOpts().OpenCL && T->isPointerType()) {
+const QualType PTy = T->getPointeeType();
+if (PTy->isImageType() || PTy->isSamplerT() || PTy->isPipeType()) {
+  Diag(NameLoc, diag::err_opencl_pointer_to_type) << PTy;
+  New->setInvalidDecl();
+}
+  }
 
   return New;
 }

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=261818=261817=261818=diff
==
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Wed Feb 24 21:34:20 2016
@@ -2176,9 +2176,12 @@ QualType Sema::BuildArrayType(QualType T
   }
 
   // OpenCL v2.0 s6.12.5 - Arrays of blocks are not supported.
+  // OpenCL v2.0 s6.16.13.1 - Arrays of pipe type are not supported.
+  // OpenCL v2.0 s6.9.b - Arrays of image/sampler type are not supported.
   if (getLangOpts().OpenCL) {
 const QualType ArrType = Context.getBaseElementType(T);
-if (ArrType->isBlockPointerType()) {
+if (ArrType->isBlockPointerType() || ArrType->isPipeType() ||
+ArrType->isSamplerT() || ArrType->isImageType()) {
   Diag(Loc, diag::err_opencl_invalid_type_array) << ArrType;
   return QualType();
 }

Modified: cfe/trunk/test/CodeGenOpenCL/opencl_types.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/opencl_types.cl?rev=261818=261817=261818=diff
==
--- cfe/trunk/test/CodeGenOpenCL/opencl_types.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/opencl_types.cl Wed Feb 24 21:34:20 2016
@@ -36,5 +36,5 @@ kernel void foo(image1d_t img) {
 // CHECK: call {{.*}}void @fnc4smp(i32
 }
 
-void __attribute__((overloadable)) bad1(image1d_t *b, image2d_t *c, image2d_t 
*d) {}
-// CHECK-LABEL: 

RE: r261719 - [OpenCL] Add Sema checks for OpenCL 2.0 block

2016-02-23 Thread xiuli pan via cfe-commits
Hi,
Does anyone knows why the svn seems to be stuck after I commit this patch.

Thanks
Xiuli


-Original Message-
From: cfe-commits [mailto:cfe-commits-boun...@lists.llvm.org] On Behalf Of 
Xiuli Pan via cfe-commits
Sent: Wednesday, February 24, 2016 12:41 PM
To: cfe-commits@lists.llvm.org
Subject: r261719 - [OpenCL] Add Sema checks for OpenCL 2.0 block

Author: pxl
Date: Tue Feb 23 22:29:36 2016
New Revision: 261719

URL: http://llvm.org/viewvc/llvm-project?rev=261719=rev
Log:
[OpenCL] Add Sema checks for OpenCL 2.0 block

Summary:
Add Sema checks for opencl 2.0 new features: Block.
This patch is partitioned from http://reviews.llvm.org/D16047

Reviewers: Anastasia

Subscribers: pekka.jaaskelainen, cfe-commits

Differential Revision: http://reviews.llvm.org/D17436

Added:
cfe/trunk/test/SemaOpenCL/invalid-block.cl
Modified:
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

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=261719=261718=261719=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Feb 23 
+++ 22:29:36 2016
@@ -7712,6 +7712,14 @@ def err_atomic_init_constant : Error<
   " in the declaration statement in the program scope">;  def 
err_opencl_implicit_vector_conversion : Error<
   "implicit conversions between vector types (%0 and %1) are not permitted">;
+def err_opencl_dereferencing : Error<
+  "dereferencing pointer of type %0 is not allowed in OpenCL">; def 
+err_opencl_block_proto_variadic : Error<
+  "invalid block prototype, variadic arguments are not allowed in 
+OpenCL">; def err_opencl_invalid_type_array : Error<
+  "array of %0 type is invalid in OpenCL">; def 
+err_opencl_ternary_with_block : Error<
+  "block type cannot be used as expression in ternary expression in 
+OpenCL">;
 
 // OpenCL v2.0 s6.13.6 -- Builtin Pipe Functions  def 
err_opencl_builtin_pipe_first_arg : Error<

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=261719=261718=261719=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Feb 23 22:29:36 2016
@@ -6708,6 +6708,19 @@ void Sema::CheckVariableDeclarationType(
 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

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=261719=261718=261719=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Feb 23 22:29:36 2016
@@ -6458,6 +6458,18 @@ OpenCLCheckVectorConditional(Sema , Ex
   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 Sema::CheckConditionalOperands(
   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()) { @

r261719 - [OpenCL] Add Sema checks for OpenCL 2.0 block

2016-02-23 Thread Xiuli Pan via cfe-commits
Author: pxl
Date: Tue Feb 23 22:29:36 2016
New Revision: 261719

URL: http://llvm.org/viewvc/llvm-project?rev=261719=rev
Log:
[OpenCL] Add Sema checks for OpenCL 2.0 block

Summary:
Add Sema checks for opencl 2.0 new features: Block.
This patch is partitioned from http://reviews.llvm.org/D16047

Reviewers: Anastasia

Subscribers: pekka.jaaskelainen, cfe-commits

Differential Revision: http://reviews.llvm.org/D17436

Added:
cfe/trunk/test/SemaOpenCL/invalid-block.cl
Modified:
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

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=261719=261718=261719=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Feb 23 22:29:36 
2016
@@ -7712,6 +7712,14 @@ def err_atomic_init_constant : Error<
   " in the declaration statement in the program scope">;
 def err_opencl_implicit_vector_conversion : Error<
   "implicit conversions between vector types (%0 and %1) are not permitted">;
+def err_opencl_dereferencing : Error<
+  "dereferencing pointer of type %0 is not allowed in OpenCL">;
+def err_opencl_block_proto_variadic : Error<
+  "invalid block prototype, variadic arguments are not allowed in OpenCL">;
+def err_opencl_invalid_type_array : Error<
+  "array of %0 type is invalid in OpenCL">;
+def err_opencl_ternary_with_block : Error<
+  "block type cannot be used as expression in ternary expression in OpenCL">;
 
 // OpenCL v2.0 s6.13.6 -- Builtin Pipe Functions
 def err_opencl_builtin_pipe_first_arg : Error<

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=261719=261718=261719=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Feb 23 22:29:36 2016
@@ -6708,6 +6708,19 @@ void Sema::CheckVariableDeclarationType(
 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

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=261719=261718=261719=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Feb 23 22:29:36 2016
@@ -6458,6 +6458,18 @@ OpenCLCheckVectorConditional(Sema , Ex
   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 Sema::CheckConditionalOperands(
   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 @@ QualType Sema::CheckAddressOfOperand(Exp
   // 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 

Re: [PATCH] D17438: [OpenCL] Add Sema checks for atomics and implicit declaration

2016-02-23 Thread Xiuli PAN via cfe-commits
pxli168 added a comment.

It now gives a warning for both C99 and OpenCL.
But for target SPIR it gives an err only because it treat unprototyped function 
as varidic function:

  /// \brief Checks whether the given calling convention supports variadic
  /// calls. Unprototyped calls also use the variadic call rules.
  inline bool sthiupportsVariadicCall(CallingConv CC) {...}

and in OpenCL s6.9.e it says

> e. Variadic macros and functions with the exception of printf and 
> enqueue_kernel are not supported.


If SPIR is followed this rule, then OpenCL should also give a err. But OpenCL 
gives only a warning.
I could not find where the following referenced

> Unprototyped calls also use the variadic call rules.


What do you think? Should we asked about if implicit declaration of function is 
allowed in OpenCL, and should we treat these function as variadic functions?


http://reviews.llvm.org/D17438



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


Re: [PATCH] D17437: [OpenCL] Add Sema checks for types

2016-02-23 Thread Xiuli PAN via cfe-commits
pxli168 updated this revision to Diff 48872.
pxli168 marked an inline comment as done.

http://reviews.llvm.org/D17437

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaType.cpp
  test/CodeGenOpenCL/opencl_types.cl
  test/SemaOpenCL/invalid-image.cl
  test/SemaOpenCL/invalid-pipes-cl2.0.cl
  test/SemaOpenCL/sampler_t.cl

Index: test/SemaOpenCL/sampler_t.cl
===
--- test/SemaOpenCL/sampler_t.cl
+++ test/SemaOpenCL/sampler_t.cl
@@ -10,4 +10,7 @@
   foo(glb_smp);
   foo(const_smp);
   foo(5); // expected-error {{sampler_t variable required - got 'int'}}
+  sampler_t sa[] = {argsmp, const_smp}; // expected-error {{array of 'sampler_t' type is invalid in OpenCL}}
 }
+
+void bad(sampler_t*); // expected-error {{pointer to type 'sampler_t' is invalid in OpenCL}}
Index: test/SemaOpenCL/invalid-pipes-cl2.0.cl
===
--- test/SemaOpenCL/invalid-pipes-cl2.0.cl
+++ test/SemaOpenCL/invalid-pipes-cl2.0.cl
@@ -6,3 +6,6 @@
 }
 void test3(int pipe p){// expected-error {{cannot combine with previous 'int' declaration specifier}}
 }
+void test4() {
+  pipe int p; // expected-error {{type 'pipe' can only be used as a function parameter}}
+}
Index: test/SemaOpenCL/invalid-image.cl
===
--- /dev/null
+++ test/SemaOpenCL/invalid-image.cl
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -verify %s
+
+void test1(image1d_t *i){} // expected-error {{pointer to type 'image1d_t' is invalid in OpenCL}}
+
+void test2(image1d_t i) {
+  image1d_t ti; // expected-error {{type 'image1d_t' can only be used as a function parameter}}
+  image1d_t ai[] = {i,i};// expected-error {{array of 'image1d_t' type is invalid in OpenCL}}
+}
Index: test/CodeGenOpenCL/opencl_types.cl
===
--- test/CodeGenOpenCL/opencl_types.cl
+++ test/CodeGenOpenCL/opencl_types.cl
@@ -36,5 +36,5 @@
 // CHECK: call {{.*}}void @fnc4smp(i32
 }
 
-void __attribute__((overloadable)) bad1(image1d_t *b, image2d_t *c, image2d_t *d) {}
-// CHECK-LABEL: @{{_Z4bad1P11ocl_image1dP11ocl_image2dS2_|"\\01\?bad1@@\$\$J0YAXPE?APAUocl_image1d@@PE?APAUocl_image2d@@1@Z"}}
+void __attribute__((overloadable)) bad1(image1d_t b, image2d_t c, image2d_t d) {}
+// CHECK-LABEL: @{{_Z4bad111ocl_image1d11ocl_image2dS0_|"\\01\?bad1@@\$\$J0YAXPAUocl_image1d@@PAUocl_image2d@@1@Z"}}
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -2176,9 +2176,12 @@
   }
 
   // OpenCL v2.0 s6.12.5 - Arrays of blocks are not supported.
+  // OpenCL v2.0 s6.16.13.1 - Arrays of pipe type are not supported.
+  // OpenCL v2.0 s6.9.b - Arrays of image/sampler type are not supported.
   if (getLangOpts().OpenCL) {
 const QualType ArrType = Context.getBaseElementType(T);
-if (ArrType->isBlockPointerType()) {
+if (ArrType->isBlockPointerType() || ArrType->isPipeType() ||
+ArrType->isSamplerT() || ArrType->isImageType()) {
   Diag(Loc, diag::err_opencl_invalid_type_array) << ArrType;
   return QualType();
 }
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -5710,6 +5710,17 @@
   QualType R = TInfo->getType();
   DeclarationName Name = GetNameForDeclarator(D).getName();
 
+  // OpenCL v2.0 s6.9.b - Image type can only be used as a function argument.
+  // OpenCL v2.0 s6.13.16.1 - Pipe type can only be used as a function
+  // argument.
+  if (getLangOpts().OpenCL && (R->isImageType() || R->isPipeType())) {
+Diag(D.getIdentifierLoc(),
+ diag::err_opencl_type_can_only_be_used_as_function_parameter)
+<< R;
+D.setInvalidType();
+return nullptr;
+  }
+
   DeclSpec::SCS SCSpec = D.getDeclSpec().getStorageClassSpec();
   StorageClass SC = StorageClassSpecToVarDeclStorageClass(D.getDeclSpec());
 
@@ -10737,7 +10748,17 @@
   Diag(NameLoc, diag::err_arg_with_address_space);
   New->setInvalidDecl();
 }
-  }   
+  }
+
+  // OpenCL v2.0 s6.9b - Pointer to image/sampler cannot be used.
+  // OpenCL v2.0 s6.13.16.1 - Pointer to pipe cannot be used.
+  if (getLangOpts().OpenCL && T->isPointerType()) {
+const QualType PTy = T->getPointeeType();
+if (PTy->isImageType() || PTy->isSamplerT() || PTy->isPipeType()) {
+  Diag(NameLoc, diag::err_opencl_pointer_to_type) << PTy;
+  New->setInvalidDecl();
+}
+  }
 
   return New;
 }
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -7703,6 +7703,10 @@
   "array of %0 type is invalid in OpenCL">;
 def err_opencl_ternary_with_block : Error<
   "block type cannot be used as 

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] D17437: [OpenCL] Add Sema checks for types

2016-02-22 Thread Xiuli PAN via cfe-commits
pxli168 updated this revision to Diff 48773.
pxli168 added a comment.

Add array check for types.


http://reviews.llvm.org/D17437

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaType.cpp
  test/CodeGenOpenCL/opencl_types.cl
  test/SemaOpenCL/invalid-image.cl
  test/SemaOpenCL/invalid-pipes-cl2.0.cl
  test/SemaOpenCL/sampler_t.cl

Index: test/SemaOpenCL/sampler_t.cl
===
--- test/SemaOpenCL/sampler_t.cl
+++ test/SemaOpenCL/sampler_t.cl
@@ -10,4 +10,7 @@
   foo(glb_smp);
   foo(const_smp);
   foo(5); // expected-error {{sampler_t variable required - got 'int'}}
+  sampler_t sa[] = {argsmp,const_smp}; // expected-error {{array of 'sampler_t' type is invalid in OpenCL}}
 }
+
+void bad(sampler_t*); // expected-error {{pointer to type 'sampler_t' is invalid in OpenCL}}
Index: test/SemaOpenCL/invalid-pipes-cl2.0.cl
===
--- test/SemaOpenCL/invalid-pipes-cl2.0.cl
+++ test/SemaOpenCL/invalid-pipes-cl2.0.cl
@@ -6,3 +6,6 @@
 }
 void test3(int pipe p){// expected-error {{cannot combine with previous 'int' declaration specifier}}
 }
+void test4() {
+  pipe int p; // expected-error {{type 'pipe' can only be used as a function parameter}}
+}
Index: test/SemaOpenCL/invalid-image.cl
===
--- /dev/null
+++ test/SemaOpenCL/invalid-image.cl
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -verify %s
+
+void test1(image1d_t *i){} // expected-error {{pointer to type 'image1d_t' is invalid in OpenCL}}
+
+void test2(image1d_t i) {
+  image1d_t ti; // expected-error {{type 'image1d_t' can only be used as a function parameter}}
+  image1d_t ai[] = {i,i};// expected-error {{array of 'image1d_t' type is invalid in OpenCL}}
+}
Index: test/CodeGenOpenCL/opencl_types.cl
===
--- test/CodeGenOpenCL/opencl_types.cl
+++ test/CodeGenOpenCL/opencl_types.cl
@@ -36,5 +36,5 @@
 // CHECK: call {{.*}}void @fnc4smp(i32
 }
 
-void __attribute__((overloadable)) bad1(image1d_t *b, image2d_t *c, image2d_t *d) {}
-// CHECK-LABEL: @{{_Z4bad1P11ocl_image1dP11ocl_image2dS2_|"\\01\?bad1@@\$\$J0YAXPE?APAUocl_image1d@@PE?APAUocl_image2d@@1@Z"}}
+void __attribute__((overloadable)) bad1(image1d_t b, image2d_t c, image2d_t d) {}
+// CHECK-LABEL: @{{_Z4bad111ocl_image1d11ocl_image2dS0_|"\\01\?bad1@@\$\$J0YAXPAUocl_image1d@@PAUocl_image2d@@1@Z"}}
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -2176,9 +2176,12 @@
   }
 
   // OpenCL v2.0 s6.12.5 - Arrays of blocks are not supported.
+  // OpenCL v2.0 s6.16.13.1 - Arrays of pipe type are not supported.
+  //  OpenCL v2.0 s6.9.b - Arrays of image/sampler type are not supported.
   if (getLangOpts().OpenCL) {
 const QualType ArrType = Context.getBaseElementType(T);
-if (ArrType->isBlockPointerType()) {
+if (ArrType->isBlockPointerType() || ArrType->isPipeType() ||
+ArrType->isSamplerT() || ArrType->isImageType()) {
   Diag(Loc, diag::err_opencl_invalid_type_array) << ArrType;
   return QualType();
 }
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -5710,6 +5710,17 @@
   QualType R = TInfo->getType();
   DeclarationName Name = GetNameForDeclarator(D).getName();
 
+  // OpenCL v2.0 s6.9.b - Image type can only be used as a function argument.
+  // OpenCL v2.0 s6.13.16.1 - Pipe type can only be used as a function
+  // argument.
+  if (getLangOpts().OpenCL && (R->isImageType() || R->isPipeType())) {
+Diag(D.getIdentifierLoc(),
+ diag::err_opencl_type_can_only_be_used_as_function_parameter)
+<< R;
+D.setInvalidType();
+return nullptr;
+  }
+
   DeclSpec::SCS SCSpec = D.getDeclSpec().getStorageClassSpec();
   StorageClass SC = StorageClassSpecToVarDeclStorageClass(D.getDeclSpec());
 
@@ -10737,7 +10748,17 @@
   Diag(NameLoc, diag::err_arg_with_address_space);
   New->setInvalidDecl();
 }
-  }   
+  }
+
+  // OpenCL v2.0 s6.9b - Pointer to image/sampler cannot be used.
+  // OpenCL v2.0 s6.13.16.1 - Pointer to pipe cannot be used.
+  if (getLangOpts().OpenCL && T->isPointerType()) {
+const QualType PTy = T->getPointeeType();
+if (PTy->isImageType() || PTy->isSamplerT() || PTy->isPipeType()) {
+  Diag(NameLoc, diag::err_opencl_pointer_to_type) << PTy;
+  New->setInvalidDecl();
+}
+  }
 
   return New;
 }
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -7703,6 +7703,10 @@
   "array of %0 type is invalid in OpenCL">;
 def err_opencl_ternary_with_block : Error<
   "block type cannot be 

Re: [PATCH] D17438: [OpenCL] Add Sema checks for atomics and implicit declaration

2016-02-22 Thread Xiuli PAN via cfe-commits
pxli168 added a comment.

It seems this patch is useless.
The spec does not tell about implicit declaration of function, but now clang 
with -triple spir will output err if there is implicit declaration of function.
I have read about spir and opencl spec but could not find anything talk about 
that.
If this is a clang bug then this patch is useless.

What do you think?



Comment at: lib/Sema/SemaDecl.cpp:3900
@@ -3899,1 +3899,3 @@
   if (!DeclaresAnything) {
+// OpenCL C doesn't support bit-field, so declaration with no declarator
+// has no use.

Anastasia wrote:
> I am still not convinced about this change? Could you give reference to spec 
> or an example? I don't understand why you are trying to change default C 
> behavior.
Just removed.


Comment at: lib/Sema/SemaDecl.cpp:7283
@@ -7276,3 +7282,3 @@
   return PtrPtrKernelParam;
-return PointeeType.getAddressSpace() == 0 ? PrivatePtrKernelParam
-  : PtrKernelParam;
+// Now generice address space is added, we need to handle like this
+unsigned addrSpace = PointeeType.getAddressSpace();

Anastasia wrote:
> Why this code?
Removed.


http://reviews.llvm.org/D17438



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


Re: [PATCH] D16928: [OpenCL] Apply missing restrictions for Blocks in OpenCL v2.0

2016-02-22 Thread Xiuli PAN via cfe-commits
pxli168 accepted this revision.
pxli168 added a comment.
This revision is now accepted and ready to land.

Then there will be no problem.
I will change my patches as well.
LGTM!
Thanks.


http://reviews.llvm.org/D16928



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


Re: [PATCH] D17437: [OpenCL] Add Sema checks for types

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


Comment at: lib/Sema/SemaDecl.cpp:5725
@@ +5724,3 @@
+  // Pipes can only be passed as arguments to a function.
+  if (getLangOpts().OpenCL && getLangOpts().OpenCLVersion >= 200 &&
+  R->isPipeType()) {

Anastasia wrote:
> Remove 'getLangOpts().OpenCLVersion >= 200'. Parser will only allow pipe for 
> CL2.0. Ideally we don't need to check getLangOpts().OpenCL either, but might 
> be good to leave it for documentation purposes.
> 
> However could we merge with the previous:
>   if (getLangOpts().OpenCL) {
>if (...) ... // image type
>if (...) ... // pipe type
>   }
Ok, it should be more clear.


Comment at: lib/Sema/SemaDecl.cpp:10768
@@ -10746,1 +10767,3 @@
 
+  // OpenCL v2.0 s6.9b2 - An image type cannot be used to declare a variable, a
+  // structure or union field, an array of images, a pointer to an image, or 
the

Anastasia wrote:
> Here you only check the pointer and not the other bits. So please modify the 
> comment according to what the code does.
> 
> Does the same restriction apply to other OpenCL types i.e. sampler, event, 
> queue, etc? 
Good suggestion. I will have a look and try to add them.


Comment at: test/CodeGenOpenCL/opencl_types.cl:39
@@ -38,3 @@
-
-void __attribute__((overloadable)) bad1(image1d_t *b, image2d_t *c, image2d_t 
*d) {}
-// CHECK-LABEL: 
@{{_Z4bad1P11ocl_image1dP11ocl_image2dS2_|"\\01\?bad1@@\$\$J0YAXPE?APAUocl_image1d@@PE?APAUocl_image2d@@1@Z"}}

Anastasia wrote:
> Could you please not remove this mangling test as it's not being tested 
> elsewhere.
> 
> You can remove * from parameters though!
OK, I will try to make this mangle right for different target.


Comment at: test/SemaOpenCL/invalid-pipes-cl2.0.cl:9
@@ -8,1 +8,3 @@
 }
+void test4() {
+  pipe int p; // expected-error {{pipe can only be used as a function 
parameter}}

yaxunl wrote:
> Do we have a test for diagnosing pipe type for OCL < 2.0 ?
We have one called test/SemaOpenCL/pipes-1.2-negative.cl


http://reviews.llvm.org/D17437



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


Re: [PATCH] D16040: [OpenCL] Refine OpenCLImageAccessAttr to OpenCLAccessAttr

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


Comment at: lib/Sema/SemaDeclAttr.cpp:5046
@@ +5045,3 @@
+  if (D->hasAttr()) {
+S.Diag(Attr.getLoc(), diag::err_opencl_multiple_access_qualifiers)
+<< D->getSourceRange();

Anastasia wrote:
> Yes, I think attribute would make more sense.
Already changed to attribute.


Comment at: lib/Sema/SemaDeclAttr.cpp:5061
@@ +5060,3 @@
+  if (S.getLangOpts().OpenCLVersion < 200 || DeclTy->isPipeType()) {
+S.Diag(Attr.getLoc(), diag::err_opencl_invalid_read_write)
+<< PDecl->getType() << DeclTy->isImageType();

Anastasia wrote:
> Yes, w/o this attribute it would assume default access qualifier i.e. 
> read_only. So I agree to point to the attribute here too.
Already done.


http://reviews.llvm.org/D16040



___
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] D16928: [OpenCL] Apply missing restrictions for Blocks in OpenCL v2.0

2016-02-21 Thread Xiuli PAN via cfe-commits
pxli168 requested changes to this revision.
pxli168 added a comment.
This revision now requires changes to proceed.

It seems this patch will check block for CL1.2 or eailer? But the spec 
reference is for OpenCL v2.0.


http://reviews.llvm.org/D16928



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


Re: [PATCH] D16928: [OpenCL] Apply missing restrictions for Blocks in OpenCL v2.0

2016-02-20 Thread Xiuli PAN via cfe-commits
pxli168 accepted this revision.
pxli168 added a comment.
This revision is now accepted and ready to land.

LGTM!
Thanks


http://reviews.llvm.org/D16928



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


Re: [PATCH] D16928: [OpenCL] Apply missing restrictions for Blocks in OpenCL v2.0

2016-02-20 Thread Xiuli PAN via cfe-commits
pxli168 added a comment.

LGTM!
Thanks.


http://reviews.llvm.org/D16928



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


[PATCH] D17438: [OpenCL] Add Sema checks for atomics and implicit declaration

2016-02-19 Thread Xiuli PAN via cfe-commits
pxli168 created this revision.
pxli168 added reviewers: pekka.jaaskelainen, Anastasia, yaxunl.
pxli168 added a subscriber: cfe-commits.

Add Sema checks for atomics and implicit declaration
This patch is partitioned from http://reviews.llvm.org/D16047

http://reviews.llvm.org/D17438

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaInit.cpp
  test/Parser/opencl-atomics-cl20.cl
  test/SemaOpenCL/invalid-decl.cl

Index: test/SemaOpenCL/invalid-decl.cl
===
--- /dev/null
+++ test/SemaOpenCL/invalid-decl.cl
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -verify -cl-std=CL2.0 %s
+int; // expected-error {{declaration does not declare anything}}
+
+void test1(){
+  myfun(); // expected-error {{implicit declaration of function 'myfun' is invalid in OpenCL}}
+}
Index: test/Parser/opencl-atomics-cl20.cl
===
--- test/Parser/opencl-atomics-cl20.cl
+++ test/Parser/opencl-atomics-cl20.cl
@@ -56,6 +56,7 @@
 #endif
 
 #ifdef CL20
+#define ATOMIC_VAR_INIT
 void foo(atomic_int * ptr) {}
 void atomic_ops_test() {
   atomic_int i;
@@ -66,4 +67,7 @@
   i += 1; // expected-error {{invalid operands to binary expression ('atomic_int' (aka '_Atomic(int)') and 'int')}}
   i = i + i; // expected-error {{invalid operands to binary expression ('atomic_int' (aka '_Atomic(int)') and 'atomic_int')}}
 }
+void atomic_init_test() {
+atomic_int guide = ATOMIC_VAR_INIT(42); // expected-error {{initialization of atomic variables is restricted to variables in global address space in opencl}}
+}
 #endif
Index: lib/Sema/SemaInit.cpp
===
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -6136,6 +6136,32 @@
   << Init->getSourceRange();
   }
 
+  // OpenCL v2.0 s6.13.11.1 - The ATOMIC_VAR_INIT macro expands to a token
+  // sequence suitable for initializing an atomic object of a type that is
+  // initialization-compatible with value. An atomic object with automatic
+  // storage duration that is not explicitly initialized using ATOMIC_VAR_INIT
+  // is initially in an indeterminate state; however, the default (zero)
+  // initialization for objects with static storage duration is guaranteed to
+  // produce a valid state.
+  // #define ATOMIC_VAR_INIT(C value)
+  // This macro can only be used to initialize atomic objects that are declared
+  // in program scope in the global address space.
+  // Examples:
+  // global atomic_int guide = ATOMIC_VAR_INIT(42);
+  if (S.getLangOpts().OpenCL && S.getLangOpts().OpenCLVersion >= 200 &&
+  Entity.getType()->isAtomicType()) {
+Qualifiers TyQualifiers = Entity.getType().getQualifiers();
+bool HasGlobalAS = TyQualifiers.hasAddressSpace() &&
+   TyQualifiers.getAddressSpace() == LangAS::opencl_global;
+if (!HasGlobalAS && Entity.getKind() == InitializedEntity::EK_Variable &&
+Args.size() > 0) {
+  Expr *Init = Args[0];
+  S.Diag(Init->getLocStart(), diag::err_opencl_atomic_init_addressspace)
+  << SourceRange(Entity.getDecl()->getLocStart(), Init->getLocEnd());
+  return ExprError();
+}
+  }
+
   // Diagnose cases where we initialize a pointer to an array temporary, and the
   // pointer obviously outlives the temporary.
   if (Args.size() == 1 && Args[0]->getType()->isArrayType() &&
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -3897,6 +3897,12 @@
   //   names into the program, or shall redeclare a name introduced by a
   //   previous declaration.
   if (!DeclaresAnything) {
+// OpenCL C doesn't support bit-field, so declaration with no declarator
+// has no use.
+if (getLangOpts().OpenCL) {
+  Diag(DS.getLocStart(), diag::err_no_declarators) << DS.getSourceRange();
+  return 0;
+}
 // In C, we allow this as a (popular) extension / bug. Don't bother
 // producing further diagnostics for redundant qualifiers after this.
 Diag(DS.getLocStart(), diag::ext_no_declarators) << DS.getSourceRange();
@@ -7274,8 +7280,13 @@
 QualType PointeeType = PT->getPointeeType();
 if (PointeeType->isPointerType())
   return PtrPtrKernelParam;
-return PointeeType.getAddressSpace() == 0 ? PrivatePtrKernelParam
-  : PtrKernelParam;
+// Now generice address space is added, we need to handle like this
+unsigned addrSpace = PointeeType.getAddressSpace();
+return (addrSpace != LangAS::opencl_global &&
+addrSpace != LangAS::opencl_constant &&
+addrSpace != LangAS::opencl_local)
+   ? PrivatePtrKernelParam
+   : PtrKernelParam;
   }
 
   // TODO: Forbid the other integer types (size_t, ptrdiff_t...) when they can
@@ -7293,6 +7304,9 @@
   if (PT->isHalfType())
 return 

Re: [PATCH] D16040: [OpenCL] Refine OpenCLImageAccessAttr to OpenCLAccessAttr

2016-02-18 Thread Xiuli PAN via cfe-commits
pxli168 updated this revision to Diff 48452.
pxli168 added a comment.

Refine the pipe parse to solve the problem the attribute for pipe will be 
handled twice within Declarator


http://reviews.llvm.org/D16040

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/CodeGen/CodeGenFunction.cpp
  lib/Parse/ParseDecl.cpp
  lib/Sema/SemaChecking.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaType.cpp
  test/Parser/opencl-image-access.cl
  test/SemaOpenCL/invalid-access-qualifier.cl
  test/SemaOpenCL/invalid-kernel-attrs.cl
  test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl

Index: test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl
===
--- test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl
+++ test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl
@@ -21,7 +21,7 @@
   // commit_read/write_pipe
   commit_read_pipe(tmp, rid);// expected-error{{first argument to commit_read_pipe must be a pipe type}}
   work_group_commit_read_pipe(p, tmp);// expected-error{{invalid argument type to function work_group_commit_read_pipe (expecting 'reserve_id_t')}}
-  sub_group_commit_write_pipe(p, tmp);// expected-error{{nvalid pipe access modifier (expecting write_only)}}
+  sub_group_commit_write_pipe(p, tmp);// expected-error{{invalid pipe access modifier (expecting write_only)}}
 }
 
 void test2(write_only pipe int p, global int* ptr){
@@ -45,7 +45,7 @@
   // commit_read/write_pipe
   commit_write_pipe(tmp, rid);// expected-error{{first argument to commit_write_pipe must be a pipe type}}
   work_group_commit_write_pipe(p, tmp);// expected-error{{invalid argument type to function work_group_commit_write_pipe (expecting 'reserve_id_t')}}
-  sub_group_commit_read_pipe(p, tmp);// expected-error{{nvalid pipe access modifier (expecting read_only)}}
+  sub_group_commit_read_pipe(p, tmp);// expected-error{{invalid pipe access modifier (expecting read_only)}}
 }
 
 void test3(){
Index: test/SemaOpenCL/invalid-kernel-attrs.cl
===
--- test/SemaOpenCL/invalid-kernel-attrs.cl
+++ test/SemaOpenCL/invalid-kernel-attrs.cl
@@ -28,8 +28,8 @@
 
 void f_kernel_image2d_t( kernel image2d_t image ) { // expected-error {{'kernel' attribute only applies to functions}}
   int __kernel x; // expected-error {{'__kernel' attribute only applies to functions}}
-  read_only int i; // expected-error {{'read_only' attribute only applies to parameters}}
-  __write_only int j; // expected-error {{'__write_only' attribute only applies to parameters}}
+  read_only image1d_t i; // expected-error {{'read_only' attribute only applies to parameters}}
+  __write_only image2d_t j; // expected-error {{'__write_only' attribute only applies to parameters}}
 }
 
 kernel __attribute__((reqd_work_group_size(1,2,0))) void kernel11(){} // expected-error {{'reqd_work_group_size' attribute must be greater than 0}}
Index: test/SemaOpenCL/invalid-access-qualifier.cl
===
--- /dev/null
+++ test/SemaOpenCL/invalid-access-qualifier.cl
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -verify %s
+// RUN: %clang_cc1 -verify -cl-std=CL2.0 -DCL20 %s
+
+void test1(read_only int i){} // expected-error{{access qualifier can only be used for pipe and image type}}
+
+void test2(read_only write_only image1d_t i){} // expected-error{{multiple access qualifiers}}
+
+void test3(read_only read_only image1d_t i){} // expected-error{{multiple access qualifiers}}
+
+#ifdef CL20
+void test4(read_write pipe int i){} // expected-error{{access qualifier read_write can not be used for 'pipe'}}
+#else
+void test4(read_write image1d_t i){} // expected-error{{access qualifier read_write can not be used for 'image1d_t' earlier than OpenCL2.0 version}}
+#endif
Index: test/Parser/opencl-image-access.cl
===
--- test/Parser/opencl-image-access.cl
+++ test/Parser/opencl-image-access.cl
@@ -1,14 +1,19 @@
-// RUN: %clang_cc1 %s -fsyntax-only
+// RUN: %clang_cc1 %s -fsyntax-only -verify
+// RUN: %clang_cc1 %s -fsyntax-only -verify -cl-std=CL2.0 -DCL20
+// expected-no-diagnostics
 
 __kernel void f__ro(__read_only image2d_t a) { }
 
 __kernel void f__wo(__write_only image2d_t a) { }
 
+#if CL20
 __kernel void f__rw(__read_write image2d_t a) { }
-
+#endif
 
 __kernel void fro(read_only image2d_t a) { }
 
 __kernel void fwo(write_only image2d_t a) { }
 
+#if CL20
 __kernel void frw(read_write image2d_t a) { }
+#endif
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -6225,6 +6225,17 @@
   CurType = S.Context.getVectorType(CurType, numElts, VecKind);
 }
 
+/// Handle OpenCL Access Qualifier Attribute
+static void HandleOpenCLAccessAttr(QualType , const AttributeList ,
+   Sema 

Re: [PATCH] D16040: [OpenCL] Refine OpenCLImageAccessAttr to OpenCLAccessAttr

2016-02-18 Thread Xiuli PAN via cfe-commits
pxli168 planned changes to this revision.
pxli168 added a comment.

It seems it is related with the pipe type. I am still working on how to fix 
this problem.


http://reviews.llvm.org/D16040



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


Re: [PATCH] D16686: [OpenCL] Generate metadata for opencl_unroll_hint attribute

2016-02-17 Thread Xiuli PAN via cfe-commits
pxli168 accepted this revision.
pxli168 added a comment.

Sorry for the late reply, I was on a break.
LGTM!


http://reviews.llvm.org/D16686



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


Re: [PATCH] D16040: [OpenCL] Refine OpenCLImageAccessAttr to OpenCLAccessAttr

2016-02-15 Thread Xiuli PAN via cfe-commits
pxli168 requested a review of this revision.
pxli168 added a comment.

Need to refine access qualifier with pipe type.



Comment at: lib/Sema/SemaDeclAttr.cpp:5052
@@ +5051,3 @@
+  if (D->hasAttr()) {
+S.Diag(D->getLocation(), diag::err_opencl_multiple_access_qualifiers)
+<< D->getSourceRange();

aaron.ballman wrote:
> This should be pointing to the attribute, not the declaration, shouldn't it?
In this case there will be two attributes, so I think it should just point to 
the declaration.


Comment at: lib/Sema/SemaDeclAttr.cpp:5804-5816
@@ -5768,9 +5803,15 @@
 
-  // Walk the declarator structure, applying decl attributes that were in a 
type
-  // position to the decl itself.  This handles cases like:
-  //   int *__attr__(x)** D;
-  // when X is a decl attribute.
-  for (unsigned i = 0, e = PD.getNumTypeObjects(); i != e; ++i)
-if (const AttributeList *Attrs = PD.getTypeObject(i).getAttrs())
-  ProcessDeclAttributeList(S, D, Attrs, /*IncludeCXX11Attributes=*/false);
+  // Skip pipe type, otherwise it will be processed twice with its element type
+  const ParmVarDecl *PDecl = llvm::dyn_cast(D);
+  if (!PDecl ||
+  !PDecl->getType().getCanonicalType().getTypePtr()->isPipeType()) {
+// Walk the declarator structure, applying decl attributes that were in a
+// type position to the decl itself.  This handles cases like:
+//   int *__attr__(x)** D;
+// when X is a decl attribute.
+for (unsigned i = 0, e = PD.getNumTypeObjects(); i != e; ++i) {
+  if (const AttributeList *Attrs = PD.getTypeObject(i).getAttrs())
+ProcessDeclAttributeList(S, D, Attrs, 
/*IncludeCXX11Attributes=*/false);
+}
+  }
 

I think this attribute one that need to be slid on the declaration. Now I just 
handle this in ProcessDeclAttributes, with

```
  const ParmVarDecl *PDecl = llvm::dyn_cast(D);
  if (!PDecl ||
  !PDecl->getType().getCanonicalType().getTypePtr()->isPipeType()) {
```
And I tried to handle it in  distributeTypeAttrsFromDeclarator but it seems 
this attribute does not go through that path and I am still working on how to 
place this check.


http://reviews.llvm.org/D16040



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


Re: [PATCH] D16040: [OpenCL] Refine OpenCLImageAccessAttr to OpenCLAccessAttr

2016-02-15 Thread Xiuli PAN via cfe-commits
pxli168 updated this revision to Diff 48046.
pxli168 marked 3 inline comments as done.
pxli168 added a comment.

Update doc for OpenCL access qualifier, still find where to handle access 
qualifier for pipe type.


http://reviews.llvm.org/D16040

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/CodeGen/CodeGenFunction.cpp
  lib/Sema/SemaChecking.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaType.cpp
  test/Parser/opencl-image-access.cl
  test/SemaOpenCL/invalid-access-qualifier.cl
  test/SemaOpenCL/invalid-kernel-attrs.cl
  test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl

Index: test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl
===
--- test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl
+++ test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl
@@ -21,7 +21,7 @@
   // commit_read/write_pipe
   commit_read_pipe(tmp, rid);// expected-error{{first argument to commit_read_pipe must be a pipe type}}
   work_group_commit_read_pipe(p, tmp);// expected-error{{invalid argument type to function work_group_commit_read_pipe (expecting 'reserve_id_t')}}
-  sub_group_commit_write_pipe(p, tmp);// expected-error{{nvalid pipe access modifier (expecting write_only)}}
+  sub_group_commit_write_pipe(p, tmp);// expected-error{{invalid pipe access modifier (expecting write_only)}}
 }
 
 void test2(write_only pipe int p, global int* ptr){
@@ -45,7 +45,7 @@
   // commit_read/write_pipe
   commit_write_pipe(tmp, rid);// expected-error{{first argument to commit_write_pipe must be a pipe type}}
   work_group_commit_write_pipe(p, tmp);// expected-error{{invalid argument type to function work_group_commit_write_pipe (expecting 'reserve_id_t')}}
-  sub_group_commit_read_pipe(p, tmp);// expected-error{{nvalid pipe access modifier (expecting read_only)}}
+  sub_group_commit_read_pipe(p, tmp);// expected-error{{invalid pipe access modifier (expecting read_only)}}
 }
 
 void test3(){
Index: test/SemaOpenCL/invalid-kernel-attrs.cl
===
--- test/SemaOpenCL/invalid-kernel-attrs.cl
+++ test/SemaOpenCL/invalid-kernel-attrs.cl
@@ -28,8 +28,8 @@
 
 void f_kernel_image2d_t( kernel image2d_t image ) { // expected-error {{'kernel' attribute only applies to functions}}
   int __kernel x; // expected-error {{'__kernel' attribute only applies to functions}}
-  read_only int i; // expected-error {{'read_only' attribute only applies to parameters}}
-  __write_only int j; // expected-error {{'__write_only' attribute only applies to parameters}}
+  read_only image1d_t i; // expected-error {{'read_only' attribute only applies to parameters}}
+  __write_only image2d_t j; // expected-error {{'__write_only' attribute only applies to parameters}}
 }
 
 kernel __attribute__((reqd_work_group_size(1,2,0))) void kernel11(){} // expected-error {{'reqd_work_group_size' attribute must be greater than 0}}
Index: test/SemaOpenCL/invalid-access-qualifier.cl
===
--- /dev/null
+++ test/SemaOpenCL/invalid-access-qualifier.cl
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -verify %s
+// RUN: %clang_cc1 -verify -cl-std=CL2.0 -DCL20 %s
+
+void test1(read_only int i){} // expected-error{{access qualifier can only be used for pipe and image type}}
+
+void test2(read_only write_only image1d_t i){} // expected-error{{multiple access qualifiers}}
+
+void test3(read_only read_only image1d_t i){} // expected-error{{multiple access qualifiers}}
+
+#ifdef CL20
+void test4(read_write pipe int i){} // expected-error{{access qualifier read_write can not be used for 'pipe'}}
+#else
+void test4(read_write image1d_t i){} // expected-error{{access qualifier read_write can not be used for 'image1d_t' earlier than OpenCL2.0 version}}
+#endif
Index: test/Parser/opencl-image-access.cl
===
--- test/Parser/opencl-image-access.cl
+++ test/Parser/opencl-image-access.cl
@@ -1,14 +1,19 @@
-// RUN: %clang_cc1 %s -fsyntax-only
+// RUN: %clang_cc1 %s -fsyntax-only -verify
+// RUN: %clang_cc1 %s -fsyntax-only -verify -cl-std=CL2.0 -DCL20
+// expected-no-diagnostics
 
 __kernel void f__ro(__read_only image2d_t a) { }
 
 __kernel void f__wo(__write_only image2d_t a) { }
 
+#if CL20
 __kernel void f__rw(__read_write image2d_t a) { }
-
+#endif
 
 __kernel void fro(read_only image2d_t a) { }
 
 __kernel void fwo(write_only image2d_t a) { }
 
+#if CL20
 __kernel void frw(read_write image2d_t a) { }
+#endif
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -6225,6 +6225,17 @@
   CurType = S.Context.getVectorType(CurType, numElts, VecKind);
 }
 
+/// Handle OpenCL Access Qualifier Attribute
+static void HandleOpenCLAccessAttr(QualType , const AttributeList ,
+   

Re: [PATCH] D16040: [OpenCL] Refine OpenCLImageAccessAttr to OpenCLAccessAttr

2016-02-10 Thread Xiuli PAN via cfe-commits
pxli168 updated this revision to Diff 47455.
pxli168 marked 5 inline comments as done.

http://reviews.llvm.org/D16040

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/CodeGen/CodeGenFunction.cpp
  lib/Sema/SemaChecking.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaType.cpp
  test/Parser/opencl-image-access.cl
  test/SemaOpenCL/invalid-access-qualifier.cl
  test/SemaOpenCL/invalid-kernel-attrs.cl

Index: test/SemaOpenCL/invalid-kernel-attrs.cl
===
--- test/SemaOpenCL/invalid-kernel-attrs.cl
+++ test/SemaOpenCL/invalid-kernel-attrs.cl
@@ -28,8 +28,8 @@
 
 void f_kernel_image2d_t( kernel image2d_t image ) { // expected-error {{'kernel' attribute only applies to functions}}
   int __kernel x; // expected-error {{'__kernel' attribute only applies to functions}}
-  read_only int i; // expected-error {{'read_only' attribute only applies to parameters}}
-  __write_only int j; // expected-error {{'__write_only' attribute only applies to parameters}}
+  read_only image1d_t i; // expected-error {{'read_only' attribute only applies to parameters}}
+  __write_only image2d_t j; // expected-error {{'__write_only' attribute only applies to parameters}}
 }
 
 kernel __attribute__((reqd_work_group_size(1,2,0))) void kernel11(){} // expected-error {{'reqd_work_group_size' attribute must be greater than 0}}
Index: test/SemaOpenCL/invalid-access-qualifier.cl
===
--- /dev/null
+++ test/SemaOpenCL/invalid-access-qualifier.cl
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -verify %s
+// RUN: %clang_cc1 -verify -cl-std=CL2.0 -DCL20 %s
+
+void test1(read_only int i){} // expected-error{{access qualifier can only be used for pipe and image type}}
+
+void test2(read_only write_only image1d_t i){} // expected-error{{multiple access qualifiers}}
+
+void test3(read_only read_only image1d_t i){} // expected-error{{multiple access qualifiers}}
+
+#ifdef CL20
+void test4(read_write pipe int i){} // expected-error{{access qualifier read_write can not be used for 'pipe'}}
+#else
+void test4(read_write image1d_t i){} // expected-error{{access qualifier read_write can not be used for 'image1d_t' earlier than OpenCL2.0 version}}
+#endif
Index: test/Parser/opencl-image-access.cl
===
--- test/Parser/opencl-image-access.cl
+++ test/Parser/opencl-image-access.cl
@@ -1,14 +1,19 @@
-// RUN: %clang_cc1 %s -fsyntax-only
+// RUN: %clang_cc1 %s -fsyntax-only -verify
+// RUN: %clang_cc1 %s -fsyntax-only -verify -cl-std=CL2.0 -DCL20 
+// expected-no-diagnostics
 
 __kernel void f__ro(__read_only image2d_t a) { }
 
 __kernel void f__wo(__write_only image2d_t a) { }
 
+#if CL20
 __kernel void f__rw(__read_write image2d_t a) { }
-
+#endif
 
 __kernel void fro(read_only image2d_t a) { }
 
 __kernel void fwo(write_only image2d_t a) { }
 
+#if CL20
 __kernel void frw(read_write image2d_t a) { }
+#endif
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -6225,6 +6225,17 @@
   CurType = S.Context.getVectorType(CurType, numElts, VecKind);
 }
 
+/// Handle OpenCL Access Qualifier Attribute
+static void HandleOpenCLAccessAttr(QualType , const AttributeList ,
+   Sema ) {
+  // OpenCL v2.0 s6.6 - Access qualifier can used only for image and pipe type
+  if (!(CurType->isImageType() || CurType->isPipeType())) {
+S.Diag(Attr.getLoc(), diag::err_opencl_invalid_access_qualifier);
+Attr.setInvalid();
+return;
+  }
+}
+
 static void processTypeAttrs(TypeProcessingState , QualType ,
  TypeAttrLocation TAL, AttributeList *attrs) {
   // Scan through and apply attributes to this type where it makes sense.  Some
@@ -6320,9 +6331,8 @@
VectorType::NeonPolyVector);
   attr.setUsedAsTypeAttr();
   break;
-case AttributeList::AT_OpenCLImageAccess:
-  // FIXME: there should be some type checking happening here, I would
-  // imagine, but the original handler's checking was entirely superfluous.
+case AttributeList::AT_OpenCLAccess:
+  HandleOpenCLAccessAttr(type, attr, state.getSema());
   attr.setUsedAsTypeAttr();
   break;
 
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -5042,6 +5042,40 @@
   return false;
 }
 
+static void handleOpenCLAccessAttr(Sema , Decl *D,
+   const AttributeList ) {
+  if (D->isInvalidDecl())
+return;
+
+  // Check if there is only one access qualifier
+  if (D->hasAttr()) {
+S.Diag(D->getLocation(), diag::err_opencl_multiple_access_qualifiers)
+<< D->getSourceRange();
+D->setInvalidDecl(true);
+return;
+  }
+
+  // OpenCL v2.0 

Re: [PATCH] D16928: [OpenCL] Apply missing restrictions for Blocks in OpenCL v2.0

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


Comment at: lib/Sema/SemaDecl.cpp:13011
@@ -12978,5 +13010,3 @@
 
-  // OpenCL 1.2 spec, s6.9 r:
-  // The event type cannot be used to declare a structure or union field.
-  if (LangOpts.OpenCL && T->isEventT()) {
-Diag(Loc, diag::err_event_t_struct_field);
+  // OpenCL v1.2 s6.9b,r & OpenCL v2.0 s6.12.5 - The following types can be 
used
+  // as structure or union field: image, sampler, event or block types.

can -> cannot
I just find I could not understand this.


Comment at: lib/Sema/SemaType.cpp:3827
@@ +3826,3 @@
+  if (LangOpts.OpenCL) {
+// OpenCL v1.2 s6.9 doesn't support variadic functions, except for
+// printf

OpenCL v1.2 s6.9 doesn't support variadic functions, except for ->OpenCL v1.2 
s6.9 - Variadic functions are not supported, 


Repository:
  rL LLVM

http://reviews.llvm.org/D16928



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


Re: [PATCH] D16876: [OpenCL] Refine pipe builtin support

2016-02-05 Thread Xiuli PAN via cfe-commits
pxli168 requested a review of this revision.
pxli168 added a reviewer: rsmith.
pxli168 added a comment.

Hi Richard/Anastasia,

I replied in the commit email, and here are some explains:

1. Without the space after comma the "//" will be aligned.
2. We want generic prototypes of the builtin functions, and we generate them in 
CodeGen. So there will be no use to perform conversion in sema for the function 
prototype.
3. We used generic prototypes and varadic function declration, the conversion 
in CodeGen use cast and won't change the original type for some arguments that 
maybe used elsewhere. (Also I do not understand very clear about how to convert 
in Sema)

Thanks
Xiuli



Comment at: lib/Sema/SemaChecking.cpp:294
@@ +293,3 @@
+ diag::err_opencl_builtin_pipe_invalid_access_modifier)
+  << "read_only" << Arg0->getSourceRange();
+  return true;

Anastasia wrote:
> Anastasia wrote:
> > Could we use getName() instead?
> > 
> > We could then also move this statement after the switch and just set an 
> > error flag here.
> Just to be clear getName() of the attr instead of passing the string (i.e. 
> "read_only").
Here we need a different access qualifier then we have. I seems to complicated 
to generated a useless attribute here just for a name. 


http://reviews.llvm.org/D16876



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


Re: [PATCH] D16686: [OpenCL] Generate metadata for opencl_unroll_hint attribute

2016-02-05 Thread Xiuli PAN via cfe-commits
pxli168 added a reviewer: rsmith.
pxli168 added a comment.

Hi richard,

What is your opinion about where to put this ParseOpenCLUnrollHintAttribute?

Thanks
Xiuli



Comment at: lib/Parse/ParseStmt.cpp:2214
@@ +2213,3 @@
+
+bool Parser::ParseOpenCLUnrollHintAttribute(ParsedAttributes ) {
+  MaybeParseGNUAttributes(Attrs);

Anastasia wrote:
> pxli168 wrote:
> > I am wondering where should this function goes in, here or ParseDecl.cpp.
> ParseGNUAttributes is in ParseDecl.cpp, but may be because it's generally 
> applicable to Decls?
> 
> I am not aware of any rule here.
Maybe we could ask richard for help?


http://reviews.llvm.org/D16686



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


Re: [PATCH] D16040: [OpenCL] Refine OpenCLImageAccessAttr to OpenCLAccessAttr

2016-02-05 Thread Xiuli PAN via cfe-commits
pxli168 updated this revision to Diff 47073.
pxli168 added a comment.

Make some optimization


http://reviews.llvm.org/D16040

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/CodeGen/CodeGenFunction.cpp
  lib/Sema/SemaChecking.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaType.cpp
  test/Parser/opencl-image-access.cl
  test/SemaOpenCL/invalid-access-qualifier.cl
  test/SemaOpenCL/invalid-kernel-attrs.cl

Index: test/SemaOpenCL/invalid-kernel-attrs.cl
===
--- test/SemaOpenCL/invalid-kernel-attrs.cl
+++ test/SemaOpenCL/invalid-kernel-attrs.cl
@@ -28,8 +28,8 @@
 
 void f_kernel_image2d_t( kernel image2d_t image ) { // expected-error {{'kernel' attribute only applies to functions}}
   int __kernel x; // expected-error {{'__kernel' attribute only applies to functions}}
-  read_only int i; // expected-error {{'read_only' attribute only applies to parameters}}
-  __write_only int j; // expected-error {{'__write_only' attribute only applies to parameters}}
+  read_only image1d_t i; // expected-error {{'read_only' attribute only applies to parameters}}
+  __write_only image2d_t j; // expected-error {{'__write_only' attribute only applies to parameters}}
 }
 
 kernel __attribute__((reqd_work_group_size(1,2,0))) void kernel11(){} // expected-error {{'reqd_work_group_size' attribute must be greater than 0}}
Index: test/SemaOpenCL/invalid-access-qualifier.cl
===
--- /dev/null
+++ test/SemaOpenCL/invalid-access-qualifier.cl
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -verify %s
+// RUN: %clang_cc1 -verify -cl-std=CL2.0 -DCL20 %s
+
+void test1(read_only int i){} // expected-error{{access qualifier can only be used for pipe and image type}}
+
+void test2(read_only write_only image1d_t i){} // expected-error{{multiple access qualifiers}}
+
+void test3(read_only read_only image1d_t i){} // expected-error{{multiple access qualifiers}}
+
+#ifdef CL20
+void test4(read_write pipe int i){} // expected-error{{access qualifier read_write can not be used for 'pipe'}}
+#else
+void test4(read_write image1d_t i){} // expected-error{{access qualifier read_write can not be used for 'image1d_t' earlier than OpenCL2.0 version}}
+#endif
Index: test/Parser/opencl-image-access.cl
===
--- test/Parser/opencl-image-access.cl
+++ test/Parser/opencl-image-access.cl
@@ -1,14 +1,18 @@
 // RUN: %clang_cc1 %s -fsyntax-only
+// RUN: %clang_cc1 %s -fsyntax-only -cl-std=CL2.0 -DCL20
 
 __kernel void f__ro(__read_only image2d_t a) { }
 
 __kernel void f__wo(__write_only image2d_t a) { }
 
+#if CL20
 __kernel void f__rw(__read_write image2d_t a) { }
-
+#endif
 
 __kernel void fro(read_only image2d_t a) { }
 
 __kernel void fwo(write_only image2d_t a) { }
 
+#if CL20
 __kernel void frw(read_write image2d_t a) { }
+#endif
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -6218,6 +6218,17 @@
   CurType = S.Context.getVectorType(CurType, numElts, VecKind);
 }
 
+/// Handle OpenCL Access Qualifier Attribute
+static void HandleOpenCLAccessAttr(QualType , const AttributeList ,
+   Sema ) {
+  // OpenCL v2.0 s6.6: Access Qualifier can used only for image and pipe type
+  if (!(CurType->isImageType() || CurType->isPipeType())) {
+S.Diag(Attr.getLoc(), diag::err_opencl_invalid_access_qualifier);
+Attr.setInvalid();
+return;
+  }
+}
+
 static void processTypeAttrs(TypeProcessingState , QualType ,
  TypeAttrLocation TAL, AttributeList *attrs) {
   // Scan through and apply attributes to this type where it makes sense.  Some
@@ -6313,9 +6324,8 @@
VectorType::NeonPolyVector);
   attr.setUsedAsTypeAttr();
   break;
-case AttributeList::AT_OpenCLImageAccess:
-  // FIXME: there should be some type checking happening here, I would
-  // imagine, but the original handler's checking was entirely superfluous.
+case AttributeList::AT_OpenCLAccess:
+  HandleOpenCLAccessAttr(type, attr, state.getSema());
   attr.setUsedAsTypeAttr();
   break;
 
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -5042,6 +5042,40 @@
   return false;
 }
 
+static void handleOpenCLAccessAttr(Sema , Decl *D,
+   const AttributeList ) {
+  if (D->isInvalidDecl())
+return;
+
+  // Check if there only one access qualifier
+  if (D->hasAttr()) {
+S.Diag(D->getLocation(), diag::err_opencl_multiple_access_qualifiers)
+<< D->getSourceRange();
+D->setInvalidDecl(true);
+return;
+  }
+
+  // OpenCL v2.0 s6.6: read_write can be used for image types to specify that an
+  // image 

Re: [PATCH] D16040: [OpenCL] Refine OpenCLImageAccessAttr to OpenCLAccessAttr

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


Comment at: lib/Sema/SemaDeclAttr.cpp:5067
@@ +5066,3 @@
+  if (DeclTy->isPipeType() ||
+  (S.getLangOpts().OpenCLVersion < 200 && DeclTy->isImageType())) {
+S.Diag(D->getLocation(), diag::err_opencl_invalid_read_write)

Anastasia wrote:
> pxli168 wrote:
> > I used arc to update the patch and it case some line error.
> > I have check about OpenCL version here and will handle the read_write with 
> > image before OpenCL 2.0. As spec mentioned that it is reversed before 
> > OpenCL 2.0. 
> Do you think we could just check:
>   if (S.getLangOpts().OpenCLVersion < 200 || DeclTy->isPipeType())
It seems can work, but maybe mislead to others.
But with the comment above it seems ok.


http://reviews.llvm.org/D16040



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


Re: [PATCH] D16047: [OpenCL] Add Sema checks for OpenCL 2.0

2016-02-05 Thread Xiuli PAN via cfe-commits
pxli168 updated this revision to Diff 47074.
pxli168 updated the summary for this revision.
pxli168 added a comment.

Rebase for partition


http://reviews.llvm.org/D16047

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaInit.cpp
  lib/Sema/SemaType.cpp
  test/CodeGenOpenCL/opencl_types.cl
  test/Parser/opencl-atomics-cl20.cl
  test/SemaOpenCL/invalid-block.cl
  test/SemaOpenCL/invalid-decl.cl
  test/SemaOpenCL/invalid-image.cl
  test/SemaOpenCL/invalid-pipes-cl2.0.cl

Index: test/SemaOpenCL/invalid-pipes-cl2.0.cl
===
--- test/SemaOpenCL/invalid-pipes-cl2.0.cl
+++ test/SemaOpenCL/invalid-pipes-cl2.0.cl
@@ -6,3 +6,6 @@
 }
 void test3(int pipe p){// expected-error {{cannot combine with previous 'int' declaration specifier}}
 }
+void test4() {
+  pipe int p; // expected-error {{pipe can only be used as a function parameter}}
+}
Index: test/SemaOpenCL/invalid-image.cl
===
--- /dev/null
+++ test/SemaOpenCL/invalid-image.cl
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -verify %s
+
+void test1(image1d_t *i){} // expected-error {{pointer to image is invalid in OpenCL}}
+
+void test2() {
+  image1d_t i; // expected-error {{image can only be used as a function parameter}}
+}
Index: test/SemaOpenCL/invalid-decl.cl
===
--- /dev/null
+++ test/SemaOpenCL/invalid-decl.cl
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -verify -cl-std=CL2.0 %s 
+int; // expected-error {{declaration does not declare anything}}
+
+void test1(){
+  myfun(); // expected-error {{implicit declaration of function 'myfun' is invalid in OpenCL}}
+}
Index: test/SemaOpenCL/invalid-block.cl
===
--- /dev/null
+++ test/SemaOpenCL/invalid-block.cl
@@ -0,0 +1,21 @@
+// 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}}
+  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 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}}
+}
+
+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}}
+}
+
Index: test/Parser/opencl-atomics-cl20.cl
===
--- test/Parser/opencl-atomics-cl20.cl
+++ test/Parser/opencl-atomics-cl20.cl
@@ -56,6 +56,7 @@
 #endif
 
 #ifdef CL20
+#define ATOMIC_VAR_INIT
 void foo(atomic_int * ptr) {}
 void atomic_ops_test() {
   atomic_int i;
@@ -66,4 +67,7 @@
   i += 1; // expected-error {{invalid operands to binary expression ('atomic_int' (aka '_Atomic(int)') and 'int')}}
   i = i + i; // expected-error {{invalid operands to binary expression ('atomic_int' (aka '_Atomic(int)') and 'atomic_int')}}
 }
+void atomic_init_test() {
+atomic_int guide = ATOMIC_VAR_INIT(42); // expected-error {{initialization of atomic variables is restricted to variables in global address space in opencl}}
+}
 #endif
Index: test/CodeGenOpenCL/opencl_types.cl
===
--- test/CodeGenOpenCL/opencl_types.cl
+++ test/CodeGenOpenCL/opencl_types.cl
@@ -35,6 +35,3 @@
   fnc4smp(glb_smp);
 // CHECK: call {{.*}}void @fnc4smp(i32
 }
-
-void __attribute__((overloadable)) bad1(image1d_t *b, image2d_t *c, image2d_t *d) {}
-// CHECK-LABEL: @{{_Z4bad1P11ocl_image1dP11ocl_image2dS2_|"\\01\?bad1@@\$\$J0YAXPE?APAUocl_image1d@@PE?APAUocl_image2d@@1@Z"}}
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -2175,6 +2175,14 @@
 Diag(Loc, diag::warn_vla_used);
   }
 
+  // OpenCL v2.0 s6.12.5 - The following Blocks features are currently not
+  // supported in OpenCL C: Arrays of Blocks.
+  if (getLangOpts().OpenCL && getLangOpts().OpenCLVersion >= 200 &&
+  Context.getBaseElementType(T)->isBlockPointerType()) {
+Diag(Loc, diag::err_opencl_invalid_block_array);
+return QualType();
+  }
+
   return T;
 }
 
Index: lib/Sema/SemaInit.cpp
===
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -6135,6 +6135,32 @@
   << Init->getSourceRange();
   }
 
+  // OpenCL v2.0 

Re: [PATCH] D16876: [OpenCL] Refine pipe builtin support

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

http://reviews.llvm.org/D16876

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaChecking.cpp
  test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl

Index: test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl
===
--- test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl
+++ test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl
@@ -5,51 +5,51 @@
   reserve_id_t rid;
 
   // read/write_pipe
-  read_pipe(tmp, p);// expected-error {{first argument to read_pipe must be a pipe type}}
-  read_pipe(p);   // expected-error {{invalid number of arguments to function: read_pipe}}
-  read_pipe(p, tmp, tmp, ptr);   // expected-error {{invalid argument type to function read_pipe (expecting 'reserve_id_t')}}
-  read_pipe(p, rid, rid, ptr);   // expected-error {{invalid argument type to function read_pipe (expecting 'unsigned int')}}
-  read_pipe(p, tmp);   // expected-error {{invalid argument type to function read_pipe (expecting 'int *')}}
+  read_pipe(tmp, p);// expected-error {{first argument to 'read_pipe' must be a pipe type}}
+  read_pipe(p);   // expected-error {{invalid number of arguments to function: 'read_pipe'}}
+  read_pipe(p, tmp, tmp, ptr);   // expected-error {{invalid argument type to function 'read_pipe' (expecting 'reserve_id_t')}}
+  read_pipe(p, rid, rid, ptr);   // expected-error {{invalid argument type to function 'read_pipe' (expecting 'unsigned int')}}
+  read_pipe(p, tmp);   // expected-error {{invalid argument type to function 'read_pipe' (expecting 'int *')}}
   write_pipe(p, ptr);// expected-error {{invalid pipe access modifier (expecting write_only)}}
   write_pipe(p, rid, tmp, ptr);// expected-error {{invalid pipe access modifier (expecting write_only)}}
 
   // reserve_read/write_pipe
-  reserve_read_pipe(p, ptr);// expected-error{{invalid argument type to function reserve_read_pipe (expecting 'unsigned int')}}
-  work_group_reserve_read_pipe(tmp, tmp);// expected-error{{first argument to work_group_reserve_read_pipe must be a pipe type}}
+  reserve_read_pipe(p, ptr);// expected-error{{invalid argument type to function 'reserve_read_pipe' (expecting 'unsigned int')}}
+  work_group_reserve_read_pipe(tmp, tmp);// expected-error{{first argument to 'work_group_reserve_read_pipe' must be a pipe type}}
   sub_group_reserve_write_pipe(p, tmp);// expected-error{{invalid pipe access modifier (expecting write_only)}}
 
   // commit_read/write_pipe
-  commit_read_pipe(tmp, rid);// expected-error{{first argument to commit_read_pipe must be a pipe type}}
-  work_group_commit_read_pipe(p, tmp);// expected-error{{invalid argument type to function work_group_commit_read_pipe (expecting 'reserve_id_t')}}
+  commit_read_pipe(tmp, rid);// expected-error{{first argument to 'commit_read_pipe' must be a pipe type}}
+  work_group_commit_read_pipe(p, tmp);// expected-error{{invalid argument type to function 'work_group_commit_read_pipe' (expecting 'reserve_id_t')}}
   sub_group_commit_write_pipe(p, tmp);// expected-error{{nvalid pipe access modifier (expecting write_only)}}
 }
 
 void test2(write_only pipe int p, global int* ptr){
   int tmp;
   reserve_id_t rid;
 
   // read/write_pipe
-  write_pipe(tmp, p);// expected-error {{first argument to write_pipe must be a pipe type}}
-  write_pipe(p);   // expected-error {{invalid number of arguments to function: write_pipe}}
-  write_pipe(p, tmp, tmp, ptr);   // expected-error {{invalid argument type to function write_pipe (expecting 'reserve_id_t')}}
-  write_pipe(p, rid, rid, ptr);   // expected-error {{invalid argument type to function write_pipe (expecting 'unsigned int')}}
-  write_pipe(p, tmp);   // expected-error {{invalid argument type to function write_pipe (expecting 'int *')}}
+  write_pipe(tmp, p);// expected-error {{first argument to 'write_pipe' must be a pipe type}}
+  write_pipe(p);   // expected-error {{invalid number of arguments to function: 'write_pipe'}}
+  write_pipe(p, tmp, tmp, ptr);   // expected-error {{invalid argument type to function 'write_pipe' (expecting 'reserve_id_t')}}
+  write_pipe(p, rid, rid, ptr);   // expected-error {{invalid argument type to function 'write_pipe' (expecting 'unsigned int')}}
+  write_pipe(p, tmp);   // expected-error {{invalid argument type to function 'write_pipe' (expecting 'int *')}}
   read_pipe(p, ptr);// expected-error {{invalid pipe access modifier (expecting read_only)}}
   read_pipe(p, rid, tmp, ptr);// expected-error {{invalid pipe access modifier (expecting read_only)}}
 
   // reserve_read/write_pipe
-  reserve_write_pipe(p, ptr);// expected-error{{invalid argument type to function reserve_write_pipe (expecting 'unsigned int')}}
-  work_group_reserve_write_pipe(tmp, tmp);// expected-error{{first argument to work_group_reserve_write_pipe must be a pipe type}}
+  reserve_write_pipe(p, ptr);// expected-error{{invalid 

Re: [PATCH] D16876: [OpenCL] Refine pipe builtin support

2016-02-04 Thread Xiuli PAN via cfe-commits
pxli168 requested a review of this revision.


Comment at: lib/Sema/SemaChecking.cpp:343
@@ -332,3 +342,3 @@
   // Two kinds of read/write pipe
   // From OpenCL C Specification 6.13.16.2 the built-in read/write
   // functions have following forms.

yaxunl wrote:
> should this follow the convention? e.g.
> OpenCL v2.0 s6.13.16.2 - 
right, this will be more clear.


http://reviews.llvm.org/D16876



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


Re: [PATCH] D16686: [OpenCL] Generate metadata for opencl_unroll_hint attribute

2016-02-04 Thread Xiuli PAN via cfe-commits
pxli168 added a comment.

Hi Pekka/Anastasia,

I find that most of the attribute parses was done in ParseDecl.cpp, should this 
also be in there?

Thanks
Xiuli



Comment at: lib/Parse/ParseStmt.cpp:2214
@@ +2213,3 @@
+
+bool Parser::ParseOpenCLUnrollHintAttribute(ParsedAttributes ) {
+  MaybeParseGNUAttributes(Attrs);

I am wondering where should this function goes in, here or ParseDecl.cpp.


Comment at: lib/Parse/ParseStmt.cpp:2220
@@ +2219,3 @@
+
+  if (Attrs.getList()->getName()->getName() != "opencl_unroll_hint")
+return true;

Using string is not very strict, can use AttributeList Kind to check that.

```
Attrs.getList()->getKind() != AttributeList::AT_OpenCLUnrollHint
```


Comment at: test/SemaOpenCL/unroll-hint.cl:1
@@ +1,2 @@
+//RUN: %clang_cc1 -O0 -fsyntax-only -verify %s
+

I think one test case here is enough, since they all hint the same code.


http://reviews.llvm.org/D16686



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


Re: [PATCH] D15914: [OpenCL] Pipe builtin functions

2016-02-04 Thread Xiuli PAN via cfe-commits
pxli168 added a comment.

Hi Anastasia/Pekka,
https://www.khronos.org/bugzilla/show_bug.cgi?id=1459
Bug report has been sent.

Thanks
Xiuli


http://reviews.llvm.org/D15914



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


[PATCH] D16876: [OpenCL] Refine pipe builtin support

2016-02-04 Thread Xiuli PAN via cfe-commits
pxli168 created this revision.
pxli168 added reviewers: Anastasia, pekka.jaaskelainen, yaxunl.
pxli168 added a subscriber: cfe-commits.

Refine the type builtin support as the request with
http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20160201/148637.html

http://reviews.llvm.org/D16876

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaChecking.cpp
  test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl

Index: test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl
===
--- test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl
+++ test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl
@@ -5,51 +5,51 @@
   reserve_id_t rid;
 
   // read/write_pipe
-  read_pipe(tmp, p);// expected-error {{first argument to read_pipe must be a pipe type}}
-  read_pipe(p);   // expected-error {{invalid number of arguments to function: read_pipe}}
-  read_pipe(p, tmp, tmp, ptr);   // expected-error {{invalid argument type to function read_pipe (expecting 'reserve_id_t')}}
-  read_pipe(p, rid, rid, ptr);   // expected-error {{invalid argument type to function read_pipe (expecting 'unsigned int')}}
-  read_pipe(p, tmp);   // expected-error {{invalid argument type to function read_pipe (expecting 'int *')}}
+  read_pipe(tmp, p);// expected-error {{first argument to 'read_pipe' must be a pipe type}}
+  read_pipe(p);   // expected-error {{invalid number of arguments to function: 'read_pipe'}}
+  read_pipe(p, tmp, tmp, ptr);   // expected-error {{invalid argument type to function 'read_pipe' (expecting 'reserve_id_t')}}
+  read_pipe(p, rid, rid, ptr);   // expected-error {{invalid argument type to function 'read_pipe' (expecting 'unsigned int')}}
+  read_pipe(p, tmp);   // expected-error {{invalid argument type to function 'read_pipe' (expecting 'int *')}}
   write_pipe(p, ptr);// expected-error {{invalid pipe access modifier (expecting write_only)}}
   write_pipe(p, rid, tmp, ptr);// expected-error {{invalid pipe access modifier (expecting write_only)}}
 
   // reserve_read/write_pipe
-  reserve_read_pipe(p, ptr);// expected-error{{invalid argument type to function reserve_read_pipe (expecting 'unsigned int')}}
-  work_group_reserve_read_pipe(tmp, tmp);// expected-error{{first argument to work_group_reserve_read_pipe must be a pipe type}}
+  reserve_read_pipe(p, ptr);// expected-error{{invalid argument type to function 'reserve_read_pipe' (expecting 'unsigned int')}}
+  work_group_reserve_read_pipe(tmp, tmp);// expected-error{{first argument to 'work_group_reserve_read_pipe' must be a pipe type}}
   sub_group_reserve_write_pipe(p, tmp);// expected-error{{invalid pipe access modifier (expecting write_only)}}
 
   // commit_read/write_pipe
-  commit_read_pipe(tmp, rid);// expected-error{{first argument to commit_read_pipe must be a pipe type}}
-  work_group_commit_read_pipe(p, tmp);// expected-error{{invalid argument type to function work_group_commit_read_pipe (expecting 'reserve_id_t')}}
+  commit_read_pipe(tmp, rid);// expected-error{{first argument to 'commit_read_pipe' must be a pipe type}}
+  work_group_commit_read_pipe(p, tmp);// expected-error{{invalid argument type to function 'work_group_commit_read_pipe' (expecting 'reserve_id_t')}}
   sub_group_commit_write_pipe(p, tmp);// expected-error{{nvalid pipe access modifier (expecting write_only)}}
 }
 
 void test2(write_only pipe int p, global int* ptr){
   int tmp;
   reserve_id_t rid;
 
   // read/write_pipe
-  write_pipe(tmp, p);// expected-error {{first argument to write_pipe must be a pipe type}}
-  write_pipe(p);   // expected-error {{invalid number of arguments to function: write_pipe}}
-  write_pipe(p, tmp, tmp, ptr);   // expected-error {{invalid argument type to function write_pipe (expecting 'reserve_id_t')}}
-  write_pipe(p, rid, rid, ptr);   // expected-error {{invalid argument type to function write_pipe (expecting 'unsigned int')}}
-  write_pipe(p, tmp);   // expected-error {{invalid argument type to function write_pipe (expecting 'int *')}}
+  write_pipe(tmp, p);// expected-error {{first argument to 'write_pipe' must be a pipe type}}
+  write_pipe(p);   // expected-error {{invalid number of arguments to function: 'write_pipe'}}
+  write_pipe(p, tmp, tmp, ptr);   // expected-error {{invalid argument type to function 'write_pipe' (expecting 'reserve_id_t')}}
+  write_pipe(p, rid, rid, ptr);   // expected-error {{invalid argument type to function 'write_pipe' (expecting 'unsigned int')}}
+  write_pipe(p, tmp);   // expected-error {{invalid argument type to function 'write_pipe' (expecting 'int *')}}
   read_pipe(p, ptr);// expected-error {{invalid pipe access modifier (expecting read_only)}}
   read_pipe(p, rid, tmp, ptr);// expected-error {{invalid pipe access modifier (expecting read_only)}}
 
   // reserve_read/write_pipe
-  reserve_write_pipe(p, ptr);// expected-error{{invalid argument type to function reserve_write_pipe (expecting 

RE: r258782 - Recommit: R258773 [OpenCL] Pipe builtin functions

2016-02-04 Thread xiuli pan via cfe-commits
The refined patch is in http://reviews.llvm.org/D16876

-Original Message-
From: cfe-commits [mailto:cfe-commits-boun...@lists.llvm.org] On Behalf Of 
xiuli pan via cfe-commits
Sent: Tuesday, February 2, 2016 10:53 AM
To: 'Richard Smith' <rich...@metafoo.co.uk>
Cc: 'cfe-commits' <cfe-commits@lists.llvm.org>
Subject: RE: r258782 - Recommit: R258773 [OpenCL] Pipe builtin functions

Thank you for you advise, I will make these fixed in some later commit.

-Original Message-
From: meta...@gmail.com [mailto:meta...@gmail.com] On Behalf Of Richard Smith
Sent: Tuesday, February 2, 2016 5:53 AM
To: Xiuli Pan <xiuli...@outlook.com>
Cc: cfe-commits <cfe-commits@lists.llvm.org>
Subject: Re: r258782 - Recommit: R258773 [OpenCL] Pipe builtin functions

On Mon, Jan 25, 2016 at 8:03 PM, Xiuli Pan via cfe-commits 
<cfe-commits@lists.llvm.org> wrote:
> Author: pxl
> Date: Mon Jan 25 22:03:48 2016
> New Revision: 258782
>
> URL: http://llvm.org/viewvc/llvm-project?rev=258782=rev
> Log:
> Recommit: R258773 [OpenCL] Pipe builtin functions Fix arc patch fuzz 
> error.
> Summary:
> Support for the pipe built-in functions for OpenCL 2.0.
> The pipe builtin functions may have infinite kinds of element types, 
> one approach would be to just generate calls that would always use generic 
> types such as void*.
> This patch is based on bader's opencl support patch on SPIR-V branch.
>
> Reviewers: Anastasia, pekka.jaaskelainen
>
> Subscribers: keryell, bader, cfe-commits
>
> Differential Revision: http://reviews.llvm.org/D15914
>
> Added:
> cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl
> cfe/trunk/test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl
> Modified:
> cfe/trunk/include/clang/Basic/Builtins.def
> cfe/trunk/include/clang/Basic/Builtins.h
> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> cfe/trunk/lib/Basic/Builtins.cpp
> cfe/trunk/lib/CodeGen/CGBuiltin.cpp
> cfe/trunk/lib/Sema/SemaChecking.cpp
>
> Modified: cfe/trunk/include/clang/Basic/Builtins.def
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Buil
> tins.def?rev=258782=258781=258782=diff
> ==
> 
> --- cfe/trunk/include/clang/Basic/Builtins.def (original)
> +++ cfe/trunk/include/clang/Basic/Builtins.def Mon Jan 25 22:03:48
> +++ 2016
> @@ -1252,6 +1252,32 @@ BUILTIN(__builtin___get_unsafe_stack_ptr
>  BUILTIN(__builtin_nontemporal_store, "v.", "t") 
> BUILTIN(__builtin_nontemporal_load, "v.", "t")
>
> +// OpenCL v2.0 s6.13.16, s9.17.3.5 - Pipe functions.
> +// We need the generic prototype, since the packet type could be anything.
> +LANGBUILTIN(read_pipe, "i.", "tn", OCLC_LANG) LANGBUILTIN(write_pipe, 
> +"i.", "tn", OCLC_LANG)
> +
> +LANGBUILTIN(reserve_read_pipe, "i.", "tn", OCLC_LANG) 
> +LANGBUILTIN(reserve_write_pipe, "i.", "tn", OCLC_LANG)
> +
> +LANGBUILTIN(commit_write_pipe, "v.", "tn", OCLC_LANG) 
> +LANGBUILTIN(commit_read_pipe, "v.", "tn", OCLC_LANG)
> +
> +LANGBUILTIN(sub_group_reserve_read_pipe, "i.", "tn", OCLC_LANG) 
> +LANGBUILTIN(sub_group_reserve_write_pipe, "i.", "tn", OCLC_LANG)
> +
> +LANGBUILTIN(sub_group_commit_read_pipe, "v.", "tn", OCLC_LANG) 
> +LANGBUILTIN(sub_group_commit_write_pipe, "v.", "tn", OCLC_LANG)
> +
> +LANGBUILTIN(work_group_reserve_read_pipe, "i.", "tn", OCLC_LANG) 
> +LANGBUILTIN(work_group_reserve_write_pipe, "i.", "tn", OCLC_LANG)
> +
> +LANGBUILTIN(work_group_commit_read_pipe, "v.", "tn", OCLC_LANG) 
> +LANGBUILTIN(work_group_commit_write_pipe, "v.", "tn", OCLC_LANG)
> +
> +LANGBUILTIN(get_pipe_num_packets, "Ui.", "tn", OCLC_LANG) 
> +LANGBUILTIN(get_pipe_max_packets, "Ui.", "tn", OCLC_LANG)
> +
>  #undef BUILTIN
>  #undef LIBBUILTIN
>  #undef LANGBUILTIN
>
> Modified: cfe/trunk/include/clang/Basic/Builtins.h
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Buil
> tins.h?rev=258782=258781=258782=diff
> ==
> 
> --- cfe/trunk/include/clang/Basic/Builtins.h (original)
> +++ cfe/trunk/include/clang/Basic/Builtins.h Mon Jan 25 22:03:48 2016
> @@ -36,6 +36,7 @@ enum LanguageID {
>CXX_LANG = 0x4,  // builtin for cplusplus only.
>OBJC_LANG = 0x8, // builtin for objective-c and objective-c++

Re: [PATCH] D16692: [OpenCL] Eliminate warning when declaring OpenCL builtin functions

2016-02-03 Thread Xiuli PAN via cfe-commits
pxli168 added a comment.

I see you have committed this patch, you can try to follow the guide here:
http://llvm.org/docs/Phabricator.html#committing-a-change
To add something in your commit and then the system will automatic close the 
diff and have link to the commmit.
This will help others to find the review process and easy to track the commit.
Or you can just use the arc tool to make the commit automatically.
Thanks
Xiuli


http://reviews.llvm.org/D16692



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


Re: [PATCH] D16686: [OpenCL] Generate metadata for opencl_unroll_hint attribute

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


Comment at: lib/CodeGen/CGLoopInfo.cpp:131
@@ +130,3 @@
+// equivalent LoopHintAttr enums.
+// See OpenCL v2.0 s6.11.5 for details.
+// 0 corresponds to opencl_unroll_hint attribute without

Can you also change this comment to the style that reference go first then 
summary.


Comment at: lib/Sema/SemaStmtAttr.cpp:224
@@ +223,3 @@
+Expr *E = A.getArgAsExpr(0);
+assert(E != nullptr && "Invalid opencl_unroll_hint argument");
+llvm::APSInt ArgVal(32);

Should this assert be here?
Can it be something else?
And you shuold just use assert(E && ).


Comment at: test/SemaOpenCL/unroll-hint.cl:1
@@ +1,2 @@
+//RUN: %clang_cc1 -O0 -cl-std=CL2.0 -fsyntax-only -verify %s
+

What will happen if using OpenCL 1.2 or 1.1 that earlier than 2.0?
You can also make a test for it, and can change this test case to 
unroll-hint-cl2.0.cl
as you can see other cl2.0 features in the folder.


http://reviews.llvm.org/D16686



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


Re: [PATCH] D16040: [OpenCL] Refine OpenCLImageAccessAttr to OpenCLAccessAttr

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


Comment at: lib/Sema/SemaDeclAttr.cpp:5067
@@ +5066,3 @@
+  if (DeclTy->isPipeType() ||
+  (S.getLangOpts().OpenCLVersion < 200 && DeclTy->isImageType())) {
+S.Diag(D->getLocation(), diag::err_opencl_invalid_read_write)

I used arc to update the patch and it case some line error.
I have check about OpenCL version here and will handle the read_write with 
image before OpenCL 2.0. As spec mentioned that it is reversed before OpenCL 
2.0. 


http://reviews.llvm.org/D16040



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


Re: [PATCH] D16040: [OpenCL] Refine OpenCLImageAccessAttr to OpenCLAccessAttr

2016-02-03 Thread Xiuli PAN via cfe-commits
pxli168 updated this revision to Diff 46865.
pxli168 added a comment.

Remove repeat test case.


http://reviews.llvm.org/D16040

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/CodeGen/CodeGenFunction.cpp
  lib/Sema/SemaChecking.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaType.cpp
  test/Parser/opencl-image-access.cl
  test/SemaOpenCL/invalid-access-qualifier.cl
  test/SemaOpenCL/invalid-kernel-attrs.cl

Index: test/SemaOpenCL/invalid-kernel-attrs.cl
===
--- test/SemaOpenCL/invalid-kernel-attrs.cl
+++ test/SemaOpenCL/invalid-kernel-attrs.cl
@@ -28,8 +28,8 @@
 
 void f_kernel_image2d_t( kernel image2d_t image ) { // expected-error {{'kernel' attribute only applies to functions}}
   int __kernel x; // expected-error {{'__kernel' attribute only applies to functions}}
-  read_only int i; // expected-error {{'read_only' attribute only applies to parameters}}
-  __write_only int j; // expected-error {{'__write_only' attribute only applies to parameters}}
+  read_only image1d_t i; // expected-error {{'read_only' attribute only applies to parameters}}
+  __write_only image2d_t j; // expected-error {{'__write_only' attribute only applies to parameters}}
 }
 
 kernel __attribute__((reqd_work_group_size(1,2,0))) void kernel11(){} // expected-error {{'reqd_work_group_size' attribute must be greater than 0}}
Index: test/SemaOpenCL/invalid-access-qualifier.cl
===
--- /dev/null
+++ test/SemaOpenCL/invalid-access-qualifier.cl
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -verify %s
+// RUN: %clang_cc1 -verify -cl-std=CL2.0 -DCL20 %s 
+
+void test1(read_only int i){} // expected-error{{access qualifier can only be used for pipe and image type}} 
+
+void test2(read_only write_only image1d_t i){} // expected-error{{multiple access qualifiers}}
+
+void test3(read_only read_only image1d_t i){} // expected-error{{multiple access qualifiers}}
+
+#ifdef CL20
+void test4(read_write pipe int i){} // expected-error{{access qualifier read_write can not be used for 'pipe'}}
+#else
+void test4(read_write image1d_t i){} // expected-error{{access qualifier read_write can not be used for 'image1d_t' earlier than OpenCL2.0 version}}
+#endif
Index: test/Parser/opencl-image-access.cl
===
--- test/Parser/opencl-image-access.cl
+++ test/Parser/opencl-image-access.cl
@@ -1,14 +1,18 @@
 // RUN: %clang_cc1 %s -fsyntax-only
+// RUN: %clang_cc1 %s -fsyntax-only -cl-std=CL2.0 -DCL20
 
 __kernel void f__ro(__read_only image2d_t a) { }
 
 __kernel void f__wo(__write_only image2d_t a) { }
 
+#if CL20
 __kernel void f__rw(__read_write image2d_t a) { }
-
+#endif
 
 __kernel void fro(read_only image2d_t a) { }
 
 __kernel void fwo(write_only image2d_t a) { }
 
+#if CL20
 __kernel void frw(read_write image2d_t a) { }
+#endif
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -6218,6 +6218,17 @@
   CurType = S.Context.getVectorType(CurType, numElts, VecKind);
 }
 
+/// Handle OpenCL Access Qualifier Attribute
+static void HandleOpenCLAccessAttr(QualType , const AttributeList ,
+   Sema ) {
+  // OpenCL v2.0 s6.6: Access Qualifier can used only for image and pipe type
+  if (!(CurType->isImageType() || CurType->isPipeType())) {
+S.Diag(Attr.getLoc(), diag::err_opencl_invalid_access_qualifier);
+Attr.setInvalid();
+return;
+  }
+}
+
 static void processTypeAttrs(TypeProcessingState , QualType ,
  TypeAttrLocation TAL, AttributeList *attrs) {
   // Scan through and apply attributes to this type where it makes sense.  Some
@@ -6313,9 +6324,8 @@
VectorType::NeonPolyVector);
   attr.setUsedAsTypeAttr();
   break;
-case AttributeList::AT_OpenCLImageAccess:
-  // FIXME: there should be some type checking happening here, I would
-  // imagine, but the original handler's checking was entirely superfluous.
+case AttributeList::AT_OpenCLAccess:
+  HandleOpenCLAccessAttr(type, attr, state.getSema());
   attr.setUsedAsTypeAttr();
   break;
 
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -5042,6 +5042,41 @@
   return false;
 }
 
+static void handleOpenCLAccessAttr(Sema , Decl *D,
+   const AttributeList ) {
+  if (D->isInvalidDecl())
+return;
+
+  // Check if there only one access qualifier
+  if (D->hasAttr()) {
+S.Diag(D->getLocation(), diag::err_opencl_multiple_access_qualifiers)
+<< D->getSourceRange();
+D->setInvalidDecl(true);
+return;
+  }
+
+  // OpenCL v2.0 s6.6: read_write can be used for image types to specify that an
+  // image 

Re: [PATCH] D16686: [OpenCL] Generate metadata for opencl_unroll_hint attribute

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


Comment at: lib/Sema/SemaStmtAttr.cpp:208
@@ +207,3 @@
+SourceRange Range) {
+  assert(A.getKind() == AttributeList::AT_OpenCLUnrollHint);
+

This is also not necessary because this function can be called only if it is an 
OpenCLUnrollHint


Comment at: lib/Sema/SemaStmtAttr.cpp:210
@@ +209,3 @@
+
+  // opencl_unroll_hint can have 0 arguments (compiler determines unrolling
+  // factor) or 1 argument (the unroll factor provided by the user).

You may put the reference at the begin and make a summary after that, I don't 
think see ... for details is need.
Just like what other OpenCL references. 


Comment at: lib/Sema/SemaStmtAttr.cpp:217
@@ +216,3 @@
+  if (NumArgs > 1) {
+S.Diag(A.getLoc(), diag::err_attribute_too_many_arguments) << 1;
+return 0;

> def err_attribute_too_many_arguments : Error<"%0 attribute takes no more than 
> %1 argument%s1">;

you should give this two arguments, one is name and another is the number you 
expected.





Comment at: lib/Sema/SemaStmtAttr.cpp:218
@@ +217,3 @@
+S.Diag(A.getLoc(), diag::err_attribute_too_many_arguments) << 1;
+return 0;
+  }

please use nullptr
should not use 0 in C++11.


Comment at: lib/Sema/SemaStmtAttr.cpp:225
@@ +224,3 @@
+Expr *E = A.getArgAsExpr(0);
+assert(E != nullptr && "Invalid opencl_unroll_hint argument");
+llvm::APSInt ArgVal(32);

Is this necessary as you have checked there is only one arg in this attr? 


Comment at: lib/Sema/SemaStmtAttr.cpp:230
@@ +229,3 @@
+  S.Diag(A.getLoc(), diag::err_attribute_argument_type)
+  << A.getName()->getName() << AANT_ArgumentIntegerConstant
+  << E->getSourceRange();

Why there is two getName?


Comment at: test/SemaOpenCL/unroll-hint.cl:17
@@ +16,3 @@
+kernel void E() {
+  __attribute__((opencl_unroll_hint(2,4))) // expected-error {{1 attribute 
takes no more than 1 argument}}
+  for(int i=0; i<100; i++);

I think

> expected-error {{**1 attribute **takes no more than 1 argument}}

should be opencl_unroll_hint


http://reviews.llvm.org/D16686



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


Re: [PATCH] D16686: [OpenCL] Generate metadata for opencl_unroll_hint attribute

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


Comment at: lib/Sema/SemaStmtAttr.cpp:216
@@ +215,3 @@
+S.Diag(A.getLoc(), diag::err_attribute_too_many_arguments)
+<< "opencl_unroll_hint" << 1;
+return nullptr;

I think you should not use hard code here, just use A.getName(). And diag will 
find a good way to output is.


Comment at: lib/Sema/SemaStmtAttr.cpp:230
@@ +229,3 @@
+  << A.getName()->getName() << AANT_ArgumentIntegerConstant
+  << E->getSourceRange();
+  return 0;

I think diag did not need StringRef, A.getName() is enough. It is Diag's job to 
find the best output form.


http://reviews.llvm.org/D16686



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


Re: [PATCH] D16692: [OpenCL] Eliminate warning when declaring OpenCL builtin functions

2016-02-01 Thread Xiuli PAN via cfe-commits
pxli168 accepted this revision.
pxli168 added a comment.

Thanks, LGTM!


http://reviews.llvm.org/D16692



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


RE: r258782 - Recommit: R258773 [OpenCL] Pipe builtin functions

2016-02-01 Thread xiuli pan via cfe-commits
Thank you for you advise, I will make these fixed in some later commit.

-Original Message-
From: meta...@gmail.com [mailto:meta...@gmail.com] On Behalf Of Richard Smith
Sent: Tuesday, February 2, 2016 5:53 AM
To: Xiuli Pan <xiuli...@outlook.com>
Cc: cfe-commits <cfe-commits@lists.llvm.org>
Subject: Re: r258782 - Recommit: R258773 [OpenCL] Pipe builtin functions

On Mon, Jan 25, 2016 at 8:03 PM, Xiuli Pan via cfe-commits 
<cfe-commits@lists.llvm.org> wrote:
> Author: pxl
> Date: Mon Jan 25 22:03:48 2016
> New Revision: 258782
>
> URL: http://llvm.org/viewvc/llvm-project?rev=258782=rev
> Log:
> Recommit: R258773 [OpenCL] Pipe builtin functions Fix arc patch fuzz 
> error.
> Summary:
> Support for the pipe built-in functions for OpenCL 2.0.
> The pipe builtin functions may have infinite kinds of element types, 
> one approach would be to just generate calls that would always use generic 
> types such as void*.
> This patch is based on bader's opencl support patch on SPIR-V branch.
>
> Reviewers: Anastasia, pekka.jaaskelainen
>
> Subscribers: keryell, bader, cfe-commits
>
> Differential Revision: http://reviews.llvm.org/D15914
>
> Added:
> cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl
> cfe/trunk/test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl
> Modified:
> cfe/trunk/include/clang/Basic/Builtins.def
> cfe/trunk/include/clang/Basic/Builtins.h
> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> cfe/trunk/lib/Basic/Builtins.cpp
> cfe/trunk/lib/CodeGen/CGBuiltin.cpp
> cfe/trunk/lib/Sema/SemaChecking.cpp
>
> Modified: cfe/trunk/include/clang/Basic/Builtins.def
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Buil
> tins.def?rev=258782=258781=258782=diff
> ==
> 
> --- cfe/trunk/include/clang/Basic/Builtins.def (original)
> +++ cfe/trunk/include/clang/Basic/Builtins.def Mon Jan 25 22:03:48 
> +++ 2016
> @@ -1252,6 +1252,32 @@ BUILTIN(__builtin___get_unsafe_stack_ptr
>  BUILTIN(__builtin_nontemporal_store, "v.", "t")  
> BUILTIN(__builtin_nontemporal_load, "v.", "t")
>
> +// OpenCL v2.0 s6.13.16, s9.17.3.5 - Pipe functions.
> +// We need the generic prototype, since the packet type could be anything.
> +LANGBUILTIN(read_pipe, "i.", "tn", OCLC_LANG) LANGBUILTIN(write_pipe, 
> +"i.", "tn", OCLC_LANG)
> +
> +LANGBUILTIN(reserve_read_pipe, "i.", "tn", OCLC_LANG) 
> +LANGBUILTIN(reserve_write_pipe, "i.", "tn", OCLC_LANG)
> +
> +LANGBUILTIN(commit_write_pipe, "v.", "tn", OCLC_LANG) 
> +LANGBUILTIN(commit_read_pipe, "v.", "tn", OCLC_LANG)
> +
> +LANGBUILTIN(sub_group_reserve_read_pipe, "i.", "tn", OCLC_LANG) 
> +LANGBUILTIN(sub_group_reserve_write_pipe, "i.", "tn", OCLC_LANG)
> +
> +LANGBUILTIN(sub_group_commit_read_pipe, "v.", "tn", OCLC_LANG) 
> +LANGBUILTIN(sub_group_commit_write_pipe, "v.", "tn", OCLC_LANG)
> +
> +LANGBUILTIN(work_group_reserve_read_pipe, "i.", "tn", OCLC_LANG) 
> +LANGBUILTIN(work_group_reserve_write_pipe, "i.", "tn", OCLC_LANG)
> +
> +LANGBUILTIN(work_group_commit_read_pipe, "v.", "tn", OCLC_LANG) 
> +LANGBUILTIN(work_group_commit_write_pipe, "v.", "tn", OCLC_LANG)
> +
> +LANGBUILTIN(get_pipe_num_packets, "Ui.", "tn", OCLC_LANG) 
> +LANGBUILTIN(get_pipe_max_packets, "Ui.", "tn", OCLC_LANG)
> +
>  #undef BUILTIN
>  #undef LIBBUILTIN
>  #undef LANGBUILTIN
>
> Modified: cfe/trunk/include/clang/Basic/Builtins.h
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Buil
> tins.h?rev=258782=258781=258782=diff
> ==
> 
> --- cfe/trunk/include/clang/Basic/Builtins.h (original)
> +++ cfe/trunk/include/clang/Basic/Builtins.h Mon Jan 25 22:03:48 2016
> @@ -36,6 +36,7 @@ enum LanguageID {
>CXX_LANG = 0x4,  // builtin for cplusplus only.
>OBJC_LANG = 0x8, // builtin for objective-c and objective-c++
>MS_LANG = 0x10,  // builtin requires MS mode.
> +  OCLC_LANG = 0x20,// builtin for OpenCL C only.

Missing space after comma.

>ALL_LANGUAGES = C_LANG | CXX_LANG | OBJC_LANG, // builtin for all 
> languages.
>ALL_GNU_LANGUAGES = ALL_LANGUAGES | GNU_LANG,  // builtin requires GNU 
> mode.
>ALL_MS_LANGUAGES = ALL_LANGUAGES | MS_LANG // builtin requires MS mode.
>
> Modified: cfe/trunk/include/clang/Ba

Re: [PATCH] D16686: [OpenCL] Generate metadata for opencl_unroll_hint attribute

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


Comment at: test/SemaOpenCL/unroll-hint.cl:22
@@ +21,2 @@
+}
+#endif

It seems the negative integer invalid test  is missing?
I think it was in your last diff.


http://reviews.llvm.org/D16686



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


Re: [PATCH] D16539: [FIX] 26194 - LLVM crash in CXXNameMangler::mangleType

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


Comment at: test/CodeGenOpenCL/generic_mangling.cl:1
@@ +1,2 @@
+// RUN: %clang_cc1 -ffake-address-space-map -emit-llvm -ffp-contract=off -x cl 
-cl-std=CL2.0 -o - %s | FileCheck %s
+

Is this enough for the new added MicrosoftMangle?


Comment at: tools/driver/driver.cpp:367
@@ -367,1 +366,3 @@
+int Result = ExecuteCC1Tool(argv, argv[1] + 4);
+return Result; // Useful for debugging to set breakpoint here
   }

I think this dubug use shuold not be in the patch.


http://reviews.llvm.org/D16539



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


  1   2   >