Re: [PATCH] D20602: Add .rgba syntax extension to ext_vector_type types

2016-07-22 Thread Pirama Arumuga Nainar via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL276455: Add .rgba syntax extension to ext_vector_type types 
(authored by pirama).

Changed prior to commit:
  https://reviews.llvm.org/D20602?vs=62305=65119#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D20602

Files:
  cfe/trunk/include/clang/AST/Type.h
  cfe/trunk/include/clang/Basic/DiagnosticGroups.td
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/lib/AST/Expr.cpp
  cfe/trunk/lib/Sema/SemaExprMember.cpp
  cfe/trunk/test/CodeGen/ext-vector.c
  cfe/trunk/test/Sema/ext_vector_components.c
  cfe/trunk/test/SemaOpenCL/ext_vectors.cl

Index: cfe/trunk/include/clang/AST/Type.h
===
--- cfe/trunk/include/clang/AST/Type.h
+++ cfe/trunk/include/clang/AST/Type.h
@@ -2812,19 +2812,20 @@
 /// __attribute__((ext_vector_type(n)), where "n" is the number of elements.
 /// Unlike vector_size, ext_vector_type is only allowed on typedef's. This
 /// class enables syntactic extensions, like Vector Components for accessing
-/// points, colors, and textures (modeled after OpenGL Shading Language).
+/// points (as .xyzw), colors (as .rgba), and textures (modeled after OpenGL
+/// Shading Language).
 class ExtVectorType : public VectorType {
   ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) :
 VectorType(ExtVector, vecType, nElements, canonType, GenericVector) {}
   friend class ASTContext;  // ASTContext creates these.
 public:
   static int getPointAccessorIdx(char c) {
 switch (c) {
 default: return -1;
-case 'x': return 0;
-case 'y': return 1;
-case 'z': return 2;
-case 'w': return 3;
+case 'x': case 'r': return 0;
+case 'y': case 'g': return 1;
+case 'z': case 'b': return 2;
+case 'w': case 'a': return 3;
 }
   }
   static int getNumericAccessorIdx(char c) {
@@ -2855,13 +2856,15 @@
 }
   }
 
-  static int getAccessorIdx(char c) {
-if (int idx = getPointAccessorIdx(c)+1) return idx-1;
-return getNumericAccessorIdx(c);
+  static int getAccessorIdx(char c, bool isNumericAccessor) {
+if (isNumericAccessor)
+  return getNumericAccessorIdx(c);
+else
+  return getPointAccessorIdx(c);
   }
 
-  bool isAccessorWithinNumElements(char c) const {
-if (int idx = getAccessorIdx(c)+1)
+  bool isAccessorWithinNumElements(char c, bool isNumericAccessor) const {
+if (int idx = getAccessorIdx(c, isNumericAccessor)+1)
   return unsigned(idx-1) < getNumElements();
 return false;
   }
Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7980,6 +7980,11 @@
   "blocks used in device side enqueue are expected to have parameters of type 'local void*'">;
 def err_opencl_enqueue_kernel_blocks_no_args : Error<
   "blocks in this form of device side enqueue call are expected to have have no parameters">;
+
+// OpenCL v2.2 s2.1.2.3 - Vector Component Access
+def ext_opencl_ext_vector_type_rgba_selector: ExtWarn<
+  "vector component name '%0' is an OpenCL version 2.2 feature">,
+  InGroup;
 } // end of sema category
 
 let CategoryName = "OpenMP Issue" in {
Index: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td
@@ -316,6 +316,7 @@
 def ObjCPointerIntrospectPerformSelector : DiagGroup<"deprecated-objc-pointer-introspection-performSelector">;
 def ObjCPointerIntrospect : DiagGroup<"deprecated-objc-pointer-introspection", [ObjCPointerIntrospectPerformSelector]>;
 def ObjCMultipleMethodNames : DiagGroup<"objc-multiple-method-names">;
+def OpenCLUnsupportedRGBA: DiagGroup<"opencl-unsupported-rgba">;
 def DeprecatedObjCIsaUsage : DiagGroup<"deprecated-objc-isa-usage">;
 def ExplicitInitializeCall : DiagGroup<"explicit-initialize-call">;
 def Packed : DiagGroup<"packed">;
Index: cfe/trunk/test/CodeGen/ext-vector.c
===
--- cfe/trunk/test/CodeGen/ext-vector.c
+++ cfe/trunk/test/CodeGen/ext-vector.c
@@ -301,3 +301,40 @@
   char valC;
   char16 destVal = valC ? valA : valB;
 }
+
+typedef __attribute__(( ext_vector_type(16) )) float float16;
+
+float16 vec16, vec16_2;
+
+// CHECK: @test_rgba
+void test_rgba() {
+  // CHECK: fadd <4 x float>
+  vec4_2 = vec4.abgr + vec4;
+
+  // CHECK: shufflevector {{.*}} 
+  vec2 = vec4.rg;
+  // CHECK: shufflevector {{.*}} 
+  vec2_2 = vec4.ba;
+  // CHECK: extractelement {{.*}} 2
+  f = vec4.b;
+  // CHECK: shufflevector {{.*}} 
+  vec4_2 = vec4_2.;
+
+  // CHECK: insertelement {{.*}} 0
+  vec2.r = f;
+  // CHECK: shufflevector {{.*}} 
+  vec2.gr = vec2;
+
+  // CHECK: extractelement {{.*}} 0
+  f = 

Re: [PATCH] D20602: Add .rgba syntax extension to ext_vector_type types

2016-07-11 Thread Pirama Arumuga Nainar via cfe-commits
pirama added a comment.

Ping...


http://reviews.llvm.org/D20602



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


Re: [PATCH] D20602: Add .rgba syntax extension to ext_vector_type types

2016-06-29 Thread Pirama Arumuga Nainar via cfe-commits
pirama updated this revision to Diff 62305.
pirama added a comment.

Added GroupInfo to warning.


http://reviews.llvm.org/D20602

Files:
  include/clang/AST/Type.h
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/AST/Expr.cpp
  lib/Sema/SemaExprMember.cpp
  test/CodeGen/ext-vector.c
  test/Sema/ext_vector_components.c
  test/SemaOpenCL/ext_vectors.cl

Index: test/SemaOpenCL/ext_vectors.cl
===
--- /dev/null
+++ test/SemaOpenCL/ext_vectors.cl
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.1
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0
+
+typedef float float4 __attribute__((ext_vector_type(4)));
+
+void test_ext_vector_accessors(float4 V) {
+  V = V.wzyx;
+  V = V.abgr; // expected-warning {{vector component name 'a' is an OpenCL version 2.2 feature}}
+  V = V.xyzr; // expected-warning {{vector component name 'r' is an OpenCL version 2.2 feature}} \
+  // expected-error {{illegal vector component name 'r'}}
+}
Index: test/Sema/ext_vector_components.c
===
--- test/Sema/ext_vector_components.c
+++ test/Sema/ext_vector_components.c
@@ -39,6 +39,33 @@
 vec4.x = vec16.sF;
   
 vec4p->yz = vec4p->xy;
+
+vec2.a; // expected-error {{vector component access exceeds type 'float2'}}
+vec2.rgba; // expected-error {{vector component access exceeds type 'float2'}}
+vec4.rgba; // expected-warning {{expression result unused}}
+vec4.rgbz; // expected-error {{illegal vector component name 'z'}}
+vec4.rgbc; // expected-error {{illegal vector component name 'c'}}
+vec4.xyzr; // expected-error {{illegal vector component name 'r'}}
+vec4.s01b; // expected-error {{vector component access exceeds type 'float4'}}
+
+vec3 = vec4.rgb; // legal, shorten
+f = vec2.r; // legal, shorten
+f = vec4.rg.r; // legal, shorten
+vec4_2.rgba = vec4.xyzw; // legal, no intermingling
+
+vec4_2.rgbr = vec4.rgba; // expected-error {{vector is not assignable (contains duplicate components)}}
+vec4_2.rgbb = vec4.rgba; // expected-error {{vector is not assignable (contains duplicate components)}}
+vec4_2.rgga = vec4.rgba; // expected-error {{vector is not assignable (contains duplicate components)}}
+vec2.x = f;
+vec2.rr = vec2_2.rg; // expected-error {{vector is not assignable (contains duplicate components)}}
+vec2.gr = vec2_2.rg;
+vec2.gr.g = vec2_2.r;
+vec4 = (float4){ 1,2,3,4 };
+vec4.rg.b; // expected-error {{vector component access exceeds type 'float2'}}
+vec4.r = vec16.sf;
+vec4.g = vec16.sF;
+
+vec4p->gb = vec4p->rg;
 }
 
 float2 lo(float3 x) { return x.lo; }
Index: test/CodeGen/ext-vector.c
===
--- test/CodeGen/ext-vector.c
+++ test/CodeGen/ext-vector.c
@@ -301,3 +301,40 @@
   char valC;
   char16 destVal = valC ? valA : valB;
 }
+
+typedef __attribute__(( ext_vector_type(16) )) float float16;
+
+float16 vec16, vec16_2;
+
+// CHECK: @test_rgba
+void test_rgba() {
+  // CHECK: fadd <4 x float>
+  vec4_2 = vec4.abgr + vec4;
+
+  // CHECK: shufflevector {{.*}} 
+  vec2 = vec4.rg;
+  // CHECK: shufflevector {{.*}} 
+  vec2_2 = vec4.ba;
+  // CHECK: extractelement {{.*}} 2
+  f = vec4.b;
+  // CHECK: shufflevector {{.*}} 
+  vec4_2 = vec4_2.;
+
+  // CHECK: insertelement {{.*}} 0
+  vec2.r = f;
+  // CHECK: shufflevector {{.*}} 
+  vec2.gr = vec2;
+
+  // CHECK: extractelement {{.*}} 0
+  f = vec4_2.rg.r;
+  // CHECK: shufflevector {{.*}} 
+  // CHECK: shufflevector {{.*}} 
+  // CHECK: shufflevector {{.*}} 
+  vec4.rgb = vec4.bgr;
+
+  // CHECK: extractelement {{.*}} 11
+  // CHECK: insertelement {{.*}} 2
+  vec4.b = vec16.sb;
+  // CHECK: shufflevector {{.*}} 
+  vec4_2 = vec16.sabcd;
+}
Index: lib/Sema/SemaExprMember.cpp
===
--- lib/Sema/SemaExprMember.cpp
+++ lib/Sema/SemaExprMember.cpp
@@ -268,6 +268,20 @@
   llvm_unreachable("unexpected instance member access kind");
 }
 
+/// Determine whether input char is from rgba component set.
+static bool
+IsRGBA(char c) {
+  switch (c) {
+  case 'r':
+  case 'g':
+  case 'b':
+  case 'a':
+return true;
+  default:
+return false;
+  }
+}
+
 /// Check an ext-vector component access expression.
 ///
 /// VK should be set in advance to the value kind of the base
@@ -307,11 +321,25 @@
 HalvingSwizzle = true;
   } else if (!HexSwizzle &&
  (Idx = vecType->getPointAccessorIdx(*compStr)) != -1) {
+bool HasRGBA = IsRGBA(*compStr);
 do {
+  // Ensure that xyzw and rgba components don't intermingle.
+  if (HasRGBA != IsRGBA(*compStr))
+break;
   if (HasIndex[Idx]) HasRepeated = true;
   HasIndex[Idx] = true;
   compStr++;
 } while (*compStr && (Idx = 

Re: [PATCH] D20602: Add .rgba syntax extension to ext_vector_type types

2016-06-29 Thread Richard Smith via cfe-commits
rsmith added inline comments.


Comment at: include/clang/Basic/DiagnosticSemaKinds.td:7907
@@ -7904,1 +7906,3 @@
+def ext_opencl_ext_vector_type_rgba_selector: ExtWarn<
+  "vector component name '%0' is an OpenCL version 2.2 feature">;
 } // end of sema category

As mentioned, normal Clang policy is to issue an `ExtWarn` in such cases unless 
there is some actual problem with accepting the feature as an extension. This 
*does* cause us to produce a diagnostic, which, as you say, is important.

The C and C++ standards are both clear that producing a diagnostic is a 
sufficient response to code that is ill-formed, and that we are still allowed 
to accept the program after producing the diagnostic; if the OpenCL 
specification says something else, it is simply broken and we should get it 
fixed.


Comment at: test/Misc/warning-flags.c:15-19
@@ -14,7 +14,7 @@
 
 If you add a new warning without a flag, this test will fail.  To fix
 this test, simply add a warning group to that warning.
 
 
 The list of warnings below should NEVER grow.  It should gradually shrink to 0.
 

Please follow these instructions.


http://reviews.llvm.org/D20602



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


Re: [PATCH] D20602: Add .rgba syntax extension to ext_vector_type types

2016-06-14 Thread Pirama Arumuga Nainar via cfe-commits
pirama updated this revision to Diff 60723.
pirama added a comment.

- Undo bad merge from different patch


http://reviews.llvm.org/D20602

Files:
  include/clang/AST/Type.h
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/AST/Expr.cpp
  lib/Sema/SemaExprMember.cpp
  test/CodeGen/ext-vector.c
  test/Misc/warning-flags.c
  test/Sema/ext_vector_components.c
  test/SemaOpenCL/ext_vectors.cl

Index: test/SemaOpenCL/ext_vectors.cl
===
--- /dev/null
+++ test/SemaOpenCL/ext_vectors.cl
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.1
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0
+
+typedef float float4 __attribute__((ext_vector_type(4)));
+
+void test_ext_vector_accessors(float4 V) {
+  V = V.wzyx;
+  V = V.abgr; // expected-warning {{vector component name 'a' is an OpenCL version 2.2 feature}}
+  V = V.xyzr; // expected-warning {{vector component name 'r' is an OpenCL version 2.2 feature}} \
+  // expected-error {{illegal vector component name 'r'}}
+}
Index: test/Sema/ext_vector_components.c
===
--- test/Sema/ext_vector_components.c
+++ test/Sema/ext_vector_components.c
@@ -39,6 +39,33 @@
 vec4.x = vec16.sF;
   
 vec4p->yz = vec4p->xy;
+
+vec2.a; // expected-error {{vector component access exceeds type 'float2'}}
+vec2.rgba; // expected-error {{vector component access exceeds type 'float2'}}
+vec4.rgba; // expected-warning {{expression result unused}}
+vec4.rgbz; // expected-error {{illegal vector component name 'z'}}
+vec4.rgbc; // expected-error {{illegal vector component name 'c'}}
+vec4.xyzr; // expected-error {{illegal vector component name 'r'}}
+vec4.s01b; // expected-error {{vector component access exceeds type 'float4'}}
+
+vec3 = vec4.rgb; // legal, shorten
+f = vec2.r; // legal, shorten
+f = vec4.rg.r; // legal, shorten
+vec4_2.rgba = vec4.xyzw; // legal, no intermingling
+
+vec4_2.rgbr = vec4.rgba; // expected-error {{vector is not assignable (contains duplicate components)}}
+vec4_2.rgbb = vec4.rgba; // expected-error {{vector is not assignable (contains duplicate components)}}
+vec4_2.rgga = vec4.rgba; // expected-error {{vector is not assignable (contains duplicate components)}}
+vec2.x = f;
+vec2.rr = vec2_2.rg; // expected-error {{vector is not assignable (contains duplicate components)}}
+vec2.gr = vec2_2.rg;
+vec2.gr.g = vec2_2.r;
+vec4 = (float4){ 1,2,3,4 };
+vec4.rg.b; // expected-error {{vector component access exceeds type 'float2'}}
+vec4.r = vec16.sf;
+vec4.g = vec16.sF;
+
+vec4p->gb = vec4p->rg;
 }
 
 float2 lo(float3 x) { return x.lo; }
Index: test/Misc/warning-flags.c
===
--- test/Misc/warning-flags.c
+++ test/Misc/warning-flags.c
@@ -18,15 +18,16 @@
 
 The list of warnings below should NEVER grow.  It should gradually shrink to 0.
 
-CHECK: Warnings without flags (84):
+CHECK: Warnings without flags (85):
 CHECK-NEXT:   ext_excess_initializers
 CHECK-NEXT:   ext_excess_initializers_in_char_array_initializer
 CHECK-NEXT:   ext_expected_semi_decl_list
 CHECK-NEXT:   ext_explicit_specialization_storage_class
 CHECK-NEXT:   ext_initializer_string_for_char_array_too_long
 CHECK-NEXT:   ext_missing_declspec
 CHECK-NEXT:   ext_missing_whitespace_after_macro_name
 CHECK-NEXT:   ext_new_paren_array_nonconst
+CHECK-NEXT:   ext_opencl_ext_vector_type_rgba_selector
 CHECK-NEXT:   ext_plain_complex
 CHECK-NEXT:   ext_template_arg_extra_parens
 CHECK-NEXT:   ext_typecheck_comparison_of_pointer_integer
Index: test/CodeGen/ext-vector.c
===
--- test/CodeGen/ext-vector.c
+++ test/CodeGen/ext-vector.c
@@ -301,3 +301,40 @@
   char valC;
   char16 destVal = valC ? valA : valB;
 }
+
+typedef __attribute__(( ext_vector_type(16) )) float float16;
+
+float16 vec16, vec16_2;
+
+// CHECK: @test_rgba
+void test_rgba() {
+  // CHECK: fadd <4 x float>
+  vec4_2 = vec4.abgr + vec4;
+
+  // CHECK: shufflevector {{.*}} 
+  vec2 = vec4.rg;
+  // CHECK: shufflevector {{.*}} 
+  vec2_2 = vec4.ba;
+  // CHECK: extractelement {{.*}} 2
+  f = vec4.b;
+  // CHECK: shufflevector {{.*}} 
+  vec4_2 = vec4_2.;
+
+  // CHECK: insertelement {{.*}} 0
+  vec2.r = f;
+  // CHECK: shufflevector {{.*}} 
+  vec2.gr = vec2;
+
+  // CHECK: extractelement {{.*}} 0
+  f = vec4_2.rg.r;
+  // CHECK: shufflevector {{.*}} 
+  // CHECK: shufflevector {{.*}} 
+  // CHECK: shufflevector {{.*}} 
+  vec4.rgb = vec4.bgr;
+
+  // CHECK: extractelement {{.*}} 11
+  // CHECK: insertelement {{.*}} 2
+  vec4.b = vec16.sb;
+  // CHECK: shufflevector {{.*}} 
+  vec4_2 = vec16.sabcd;
+}
Index: lib/Sema/SemaExprMember.cpp
===
--- lib/Sema/SemaExprMember.cpp
+++ 

Re: [PATCH] D20602: Add .rgba syntax extension to ext_vector_type types

2016-06-14 Thread Pirama Arumuga Nainar via cfe-commits
pirama updated this revision to Diff 60718.
pirama added a comment.
Herald added subscribers: danalbert, tberghammer.

- Add TargetInfo for 32-bit and 64-bit RenderScript


http://reviews.llvm.org/D20602

Files:
  include/clang/AST/Type.h
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/AST/Expr.cpp
  lib/Basic/Targets.cpp
  lib/Sema/SemaExprMember.cpp
  test/CodeGen/ext-vector.c
  test/CodeGen/renderscript.c
  test/Misc/warning-flags.c
  test/Sema/ext_vector_components.c
  test/SemaOpenCL/ext_vectors.cl

Index: test/SemaOpenCL/ext_vectors.cl
===
--- /dev/null
+++ test/SemaOpenCL/ext_vectors.cl
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.1
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0
+
+typedef float float4 __attribute__((ext_vector_type(4)));
+
+void test_ext_vector_accessors(float4 V) {
+  V = V.wzyx;
+  V = V.abgr; // expected-warning {{vector component name 'a' is an OpenCL version 2.2 feature}}
+  V = V.xyzr; // expected-warning {{vector component name 'r' is an OpenCL version 2.2 feature}} \
+  // expected-error {{illegal vector component name 'r'}}
+}
Index: test/Sema/ext_vector_components.c
===
--- test/Sema/ext_vector_components.c
+++ test/Sema/ext_vector_components.c
@@ -39,6 +39,33 @@
 vec4.x = vec16.sF;
   
 vec4p->yz = vec4p->xy;
+
+vec2.a; // expected-error {{vector component access exceeds type 'float2'}}
+vec2.rgba; // expected-error {{vector component access exceeds type 'float2'}}
+vec4.rgba; // expected-warning {{expression result unused}}
+vec4.rgbz; // expected-error {{illegal vector component name 'z'}}
+vec4.rgbc; // expected-error {{illegal vector component name 'c'}}
+vec4.xyzr; // expected-error {{illegal vector component name 'r'}}
+vec4.s01b; // expected-error {{vector component access exceeds type 'float4'}}
+
+vec3 = vec4.rgb; // legal, shorten
+f = vec2.r; // legal, shorten
+f = vec4.rg.r; // legal, shorten
+vec4_2.rgba = vec4.xyzw; // legal, no intermingling
+
+vec4_2.rgbr = vec4.rgba; // expected-error {{vector is not assignable (contains duplicate components)}}
+vec4_2.rgbb = vec4.rgba; // expected-error {{vector is not assignable (contains duplicate components)}}
+vec4_2.rgga = vec4.rgba; // expected-error {{vector is not assignable (contains duplicate components)}}
+vec2.x = f;
+vec2.rr = vec2_2.rg; // expected-error {{vector is not assignable (contains duplicate components)}}
+vec2.gr = vec2_2.rg;
+vec2.gr.g = vec2_2.r;
+vec4 = (float4){ 1,2,3,4 };
+vec4.rg.b; // expected-error {{vector component access exceeds type 'float2'}}
+vec4.r = vec16.sf;
+vec4.g = vec16.sF;
+
+vec4p->gb = vec4p->rg;
 }
 
 float2 lo(float3 x) { return x.lo; }
Index: test/Misc/warning-flags.c
===
--- test/Misc/warning-flags.c
+++ test/Misc/warning-flags.c
@@ -18,15 +18,16 @@
 
 The list of warnings below should NEVER grow.  It should gradually shrink to 0.
 
-CHECK: Warnings without flags (84):
+CHECK: Warnings without flags (85):
 CHECK-NEXT:   ext_excess_initializers
 CHECK-NEXT:   ext_excess_initializers_in_char_array_initializer
 CHECK-NEXT:   ext_expected_semi_decl_list
 CHECK-NEXT:   ext_explicit_specialization_storage_class
 CHECK-NEXT:   ext_initializer_string_for_char_array_too_long
 CHECK-NEXT:   ext_missing_declspec
 CHECK-NEXT:   ext_missing_whitespace_after_macro_name
 CHECK-NEXT:   ext_new_paren_array_nonconst
+CHECK-NEXT:   ext_opencl_ext_vector_type_rgba_selector
 CHECK-NEXT:   ext_plain_complex
 CHECK-NEXT:   ext_template_arg_extra_parens
 CHECK-NEXT:   ext_typecheck_comparison_of_pointer_integer
Index: test/CodeGen/renderscript.c
===
--- /dev/null
+++ test/CodeGen/renderscript.c
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 %s -triple=renderscript32 -emit-llvm -o - -Werror | FileCheck %s -check-prefix=CHECK-RS32
+// RUN: %clang_cc1 %s -triple=renderscript64 -emit-llvm -o - -Werror | FileCheck %s -check-prefix=CHECK-RS64
+// RUN: %clang_cc1 %s -triple=armv7-none-linux-gnueabi -emit-llvm -o - -Werror | FileCheck %s -check-prefix=CHECK-ARM
+
+// Ensure that the bitcode has the correct triple
+// CHECK-RS32: target triple = "armv7-none-linux-gnueabi"
+// CHECK-RS64: target triple = "aarch64-linux-android"
+// CHECK-ARM: target triple = "armv7-none-linux-gnueabi"
+
+// Ensure that long data type has 8-byte size and alignment in RenderScript
+#ifdef __RENDERSCRIPT__
+#define LONG_WIDTH_AND_ALIGN 8
+#else
+#define LONG_WIDTH_AND_ALIGN 4
+#endif
+
+_Static_assert(sizeof(long) == LONG_WIDTH_AND_ALIGN, "sizeof long is wrong");
+_Static_assert(_Alignof(long) == LONG_WIDTH_AND_ALIGN, "sizeof long is wrong");
+
+// CHECK-RS32: i64 @test_long(i64 %v)
+// CHECK-RS64: i64 

Re: [PATCH] D20602: Add .rgba syntax extension to ext_vector_type types

2016-06-13 Thread Anastasia Stulova via cfe-commits
Anastasia added inline comments.


Comment at: include/clang/Basic/DiagnosticSemaKinds.td:7907
@@ -7904,1 +7906,3 @@
+def ext_opencl_ext_vector_type_rgba_selector: ExtWarn<
+  "vector component name '%0' is an OpenCL version 2.2 feature">;
 } // end of sema category

I am not too bothered with this specific case and I agree compiler 
implementation can deviate from the spec in certain beneficial cases (though I 
hope not too many of them).

Just for the record: we have diagnosed with an errors all other similar 
situations. Also my understanding is that compilation should largely work 
compliant to the passed language version. This is something we have been doing 
for OpenCL mainly - making sure to accept or reject code according to the 
language version requirement. This way if the code is compiled with features 
that aren't supported by either hardware or a driver user will be given 
diagnostics about it and spec compliance acts as a contract guarantee between 
compiler and other components involved.


http://reviews.llvm.org/D20602



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


Re: [PATCH] D20602: Add .rgba syntax extension to ext_vector_type types

2016-06-10 Thread Pirama Arumuga Nainar via cfe-commits
pirama updated this revision to Diff 60425.
pirama added a comment.

Convert error to warning, update tests, and rename variable name.


http://reviews.llvm.org/D20602

Files:
  include/clang/AST/Type.h
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/AST/Expr.cpp
  lib/Sema/SemaExprMember.cpp
  test/CodeGen/ext-vector.c
  test/Misc/warning-flags.c
  test/Sema/ext_vector_components.c
  test/SemaOpenCL/ext_vectors.cl

Index: test/SemaOpenCL/ext_vectors.cl
===
--- /dev/null
+++ test/SemaOpenCL/ext_vectors.cl
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.1
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0
+
+typedef float float4 __attribute__((ext_vector_type(4)));
+
+void test_ext_vector_accessors(float4 V) {
+  V = V.wzyx;
+  V = V.abgr; // expected-warning {{vector component name 'a' is an OpenCL version 2.2 feature}}
+  V = V.xyzr; // expected-warning {{vector component name 'r' is an OpenCL version 2.2 feature}} \
+  // expected-error {{illegal vector component name 'r'}}
+}
Index: test/Sema/ext_vector_components.c
===
--- test/Sema/ext_vector_components.c
+++ test/Sema/ext_vector_components.c
@@ -39,6 +39,33 @@
 vec4.x = vec16.sF;
   
 vec4p->yz = vec4p->xy;
+
+vec2.a; // expected-error {{vector component access exceeds type 'float2'}}
+vec2.rgba; // expected-error {{vector component access exceeds type 'float2'}}
+vec4.rgba; // expected-warning {{expression result unused}}
+vec4.rgbz; // expected-error {{illegal vector component name 'z'}}
+vec4.rgbc; // expected-error {{illegal vector component name 'c'}}
+vec4.xyzr; // expected-error {{illegal vector component name 'r'}}
+vec4.s01b; // expected-error {{vector component access exceeds type 'float4'}}
+
+vec3 = vec4.rgb; // legal, shorten
+f = vec2.r; // legal, shorten
+f = vec4.rg.r; // legal, shorten
+vec4_2.rgba = vec4.xyzw; // legal, no intermingling
+
+vec4_2.rgbr = vec4.rgba; // expected-error {{vector is not assignable (contains duplicate components)}}
+vec4_2.rgbb = vec4.rgba; // expected-error {{vector is not assignable (contains duplicate components)}}
+vec4_2.rgga = vec4.rgba; // expected-error {{vector is not assignable (contains duplicate components)}}
+vec2.x = f;
+vec2.rr = vec2_2.rg; // expected-error {{vector is not assignable (contains duplicate components)}}
+vec2.gr = vec2_2.rg;
+vec2.gr.g = vec2_2.r;
+vec4 = (float4){ 1,2,3,4 };
+vec4.rg.b; // expected-error {{vector component access exceeds type 'float2'}}
+vec4.r = vec16.sf;
+vec4.g = vec16.sF;
+
+vec4p->gb = vec4p->rg;
 }
 
 float2 lo(float3 x) { return x.lo; }
Index: test/Misc/warning-flags.c
===
--- test/Misc/warning-flags.c
+++ test/Misc/warning-flags.c
@@ -18,15 +18,16 @@
 
 The list of warnings below should NEVER grow.  It should gradually shrink to 0.
 
-CHECK: Warnings without flags (84):
+CHECK: Warnings without flags (85):
 CHECK-NEXT:   ext_excess_initializers
 CHECK-NEXT:   ext_excess_initializers_in_char_array_initializer
 CHECK-NEXT:   ext_expected_semi_decl_list
 CHECK-NEXT:   ext_explicit_specialization_storage_class
 CHECK-NEXT:   ext_initializer_string_for_char_array_too_long
 CHECK-NEXT:   ext_missing_declspec
 CHECK-NEXT:   ext_missing_whitespace_after_macro_name
 CHECK-NEXT:   ext_new_paren_array_nonconst
+CHECK-NEXT:   ext_opencl_ext_vector_type_rgba_selector
 CHECK-NEXT:   ext_plain_complex
 CHECK-NEXT:   ext_template_arg_extra_parens
 CHECK-NEXT:   ext_typecheck_comparison_of_pointer_integer
Index: test/CodeGen/ext-vector.c
===
--- test/CodeGen/ext-vector.c
+++ test/CodeGen/ext-vector.c
@@ -301,3 +301,40 @@
   char valC;
   char16 destVal = valC ? valA : valB;
 }
+
+typedef __attribute__(( ext_vector_type(16) )) float float16;
+
+float16 vec16, vec16_2;
+
+// CHECK: @test_rgba
+void test_rgba() {
+  // CHECK: fadd <4 x float>
+  vec4_2 = vec4.abgr + vec4;
+
+  // CHECK: shufflevector {{.*}} 
+  vec2 = vec4.rg;
+  // CHECK: shufflevector {{.*}} 
+  vec2_2 = vec4.ba;
+  // CHECK: extractelement {{.*}} 2
+  f = vec4.b;
+  // CHECK: shufflevector {{.*}} 
+  vec4_2 = vec4_2.;
+
+  // CHECK: insertelement {{.*}} 0
+  vec2.r = f;
+  // CHECK: shufflevector {{.*}} 
+  vec2.gr = vec2;
+
+  // CHECK: extractelement {{.*}} 0
+  f = vec4_2.rg.r;
+  // CHECK: shufflevector {{.*}} 
+  // CHECK: shufflevector {{.*}} 
+  // CHECK: shufflevector {{.*}} 
+  vec4.rgb = vec4.bgr;
+
+  // CHECK: extractelement {{.*}} 11
+  // CHECK: insertelement {{.*}} 2
+  vec4.b = vec16.sb;
+  // CHECK: shufflevector {{.*}} 
+  vec4_2 = vec16.sabcd;
+}
Index: lib/Sema/SemaExprMember.cpp
===
--- 

Re: [PATCH] D20602: Add .rgba syntax extension to ext_vector_type types

2016-06-10 Thread Richard Smith via cfe-commits
rsmith added inline comments.


Comment at: include/clang/Basic/DiagnosticSemaKinds.td:7900
@@ -7897,1 +7899,3 @@
+def err_opencl_ext_vector_type_rgba_selector: Error<
+  "vector component name '%0' cannot be used earlier than OpenCL version 2.2">;
 } // end of sema category

I don't see any good reason to reject this in earlier versions of OpenCL. Clang 
has its own extensions and is not beholden to the OpenCL spec's notion of 
extensions in this regard. Generally, wherever reasonable, we support features 
from later versions of a language as extensions in earlier versions.

However, since "extension" means something in the OpenCL specification, we 
could say "OpenCL 2.2 feature" rather than "OpenCL 2.2 extension" in the 
ExtWarn message.


Comment at: lib/Sema/SemaExprMember.cpp:337-339
@@ +336,5 @@
+  if (S.getLangOpts().OpenCL && S.getLangOpts().OpenCLVersion < 220) {
+const char *diagBegin = HasRGBA ? CompName->getNameStart() : compStr;
+S.Diag(OpLoc, diag::err_opencl_ext_vector_type_rgba_selector)
+  << StringRef(diagBegin, 1)
+  << S.getLangOpts().OpenCLVersion << SourceRange(CompLoc);

diagBegin -> DiagBegin


http://reviews.llvm.org/D20602



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


Re: [PATCH] D20602: Add .rgba syntax extension to ext_vector_type types

2016-06-03 Thread Pirama Arumuga Nainar via cfe-commits
pirama added a comment.

Friendly ping...


http://reviews.llvm.org/D20602



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


Re: [PATCH] D20602: Add .rgba syntax extension to ext_vector_type types

2016-05-27 Thread Pirama Arumuga Nainar via cfe-commits
pirama updated this revision to Diff 58813.
pirama added a comment.

Switched to emitting errors when rgba is used in OpenCL < 2.2.  Also, fixed the
diagnostic's name mismatch at its point of issue.


http://reviews.llvm.org/D20602

Files:
  include/clang/AST/Type.h
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/AST/Expr.cpp
  lib/Sema/SemaExprMember.cpp
  test/CodeGen/ext-vector.c
  test/Sema/ext_vector_components.c
  test/SemaOpenCL/ext_vectors.cl

Index: test/SemaOpenCL/ext_vectors.cl
===
--- /dev/null
+++ test/SemaOpenCL/ext_vectors.cl
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.1
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0
+
+typedef float float4 __attribute__((ext_vector_type(4)));
+
+void test_ext_vector_accessors(float4 V) {
+  V = V.wzyx;
+  V = V.abgr; // expected-error {{vector component name 'a' cannot be used earlier than OpenCL version 2.2}}
+  V = V.xyzr; // expected-error {{vector component name 'r' cannot be used earlier than OpenCL version 2.2}} \
+  // expected-error {{illegal vector component name 'r'}}
+}
Index: test/Sema/ext_vector_components.c
===
--- test/Sema/ext_vector_components.c
+++ test/Sema/ext_vector_components.c
@@ -39,6 +39,33 @@
 vec4.x = vec16.sF;
   
 vec4p->yz = vec4p->xy;
+
+vec2.a; // expected-error {{vector component access exceeds type 'float2'}}
+vec2.rgba; // expected-error {{vector component access exceeds type 'float2'}}
+vec4.rgba; // expected-warning {{expression result unused}}
+vec4.rgbz; // expected-error {{illegal vector component name 'z'}}
+vec4.rgbc; // expected-error {{illegal vector component name 'c'}}
+vec4.xyzr; // expected-error {{illegal vector component name 'r'}}
+vec4.s01b; // expected-error {{vector component access exceeds type 'float4'}}
+
+vec3 = vec4.rgb; // legal, shorten
+f = vec2.r; // legal, shorten
+f = vec4.rg.r; // legal, shorten
+vec4_2.rgba = vec4.xyzw; // legal, no intermingling
+
+vec4_2.rgbr = vec4.rgba; // expected-error {{vector is not assignable (contains duplicate components)}}
+vec4_2.rgbb = vec4.rgba; // expected-error {{vector is not assignable (contains duplicate components)}}
+vec4_2.rgga = vec4.rgba; // expected-error {{vector is not assignable (contains duplicate components)}}
+vec2.x = f;
+vec2.rr = vec2_2.rg; // expected-error {{vector is not assignable (contains duplicate components)}}
+vec2.gr = vec2_2.rg;
+vec2.gr.g = vec2_2.r;
+vec4 = (float4){ 1,2,3,4 };
+vec4.rg.b; // expected-error {{vector component access exceeds type 'float2'}}
+vec4.r = vec16.sf;
+vec4.g = vec16.sF;
+
+vec4p->gb = vec4p->rg;
 }
 
 float2 lo(float3 x) { return x.lo; }
Index: test/CodeGen/ext-vector.c
===
--- test/CodeGen/ext-vector.c
+++ test/CodeGen/ext-vector.c
@@ -301,3 +301,40 @@
   char valC;
   char16 destVal = valC ? valA : valB;
 }
+
+typedef __attribute__(( ext_vector_type(16) )) float float16;
+
+float16 vec16, vec16_2;
+
+// CHECK: @test_rgba
+void test_rgba() {
+  // CHECK: fadd <4 x float>
+  vec4_2 = vec4.abgr + vec4;
+
+  // CHECK: shufflevector {{.*}} 
+  vec2 = vec4.rg;
+  // CHECK: shufflevector {{.*}} 
+  vec2_2 = vec4.ba;
+  // CHECK: extractelement {{.*}} 2
+  f = vec4.b;
+  // CHECK: shufflevector {{.*}} 
+  vec4_2 = vec4_2.;
+
+  // CHECK: insertelement {{.*}} 0
+  vec2.r = f;
+  // CHECK: shufflevector {{.*}} 
+  vec2.gr = vec2;
+
+  // CHECK: extractelement {{.*}} 0
+  f = vec4_2.rg.r;
+  // CHECK: shufflevector {{.*}} 
+  // CHECK: shufflevector {{.*}} 
+  // CHECK: shufflevector {{.*}} 
+  vec4.rgb = vec4.bgr;
+
+  // CHECK: extractelement {{.*}} 11
+  // CHECK: insertelement {{.*}} 2
+  vec4.b = vec16.sb;
+  // CHECK: shufflevector {{.*}} 
+  vec4_2 = vec16.sabcd;
+}
Index: lib/Sema/SemaExprMember.cpp
===
--- lib/Sema/SemaExprMember.cpp
+++ lib/Sema/SemaExprMember.cpp
@@ -268,6 +268,20 @@
   llvm_unreachable("unexpected instance member access kind");
 }
 
+/// Determine whether input char is from rgba component set.
+static bool
+IsRGBA(char c) {
+  switch (c) {
+  case 'r':
+  case 'g':
+  case 'b':
+  case 'a':
+return true;
+  default:
+return false;
+  }
+}
+
 /// Check an ext-vector component access expression.
 ///
 /// VK should be set in advance to the value kind of the base
@@ -307,11 +321,25 @@
 HalvingSwizzle = true;
   } else if (!HexSwizzle &&
  (Idx = vecType->getPointAccessorIdx(*compStr)) != -1) {
+bool HasRGBA = IsRGBA(*compStr);
 do {
+  // Ensure that xyzw and rgba components don't intermingle.
+  if (HasRGBA != IsRGBA(*compStr))
+break;
   if (HasIndex[Idx]) HasRepeated = true;
   HasIndex[Idx] = 

Re: [PATCH] D20602: Add .rgba syntax extension to ext_vector_type types

2016-05-26 Thread Pirama Arumuga Nainar via cfe-commits
pirama added inline comments.


Comment at: include/clang/Basic/DiagnosticSemaKinds.td:7900
@@ -7897,1 +7899,3 @@
+def ext_opencl_ext_vector_type_rgba_selector: ExtWarn<
+  "vector component name '%0' is an OpenCL 2.2 extension">;
 } // end of sema category

Anastasia wrote:
> Could it be an error instead for CL <2.2? It isn't a valid feature and we 
> have already rejected similar cases with an error. 
> 
> How about changing to something like:
>   "vector component name '%0' is not supported in earlier than OpenCL version 
> 2.2"
> 
> See similar diagnostics above - err_opencl_invalid_read_write, 
> err_opencl_unknown_type_specifier.
> 
> Using extension might be confusing because we have core spec and extension 
> spec in OpenCL.
Since .rgba is just a syntactic feature in the frontend that requires no 
support from the runtime, should this be an error?  Making this an ExtWarn, 
like Richard suggested, will reject these under -pedantic-errors.  But I'll let 
you make this call.

I'll update the diagnostic message to the following, if that's ok:

> "vector component name '%0' cannot be used earlier than OpenCL version 2.2.




http://reviews.llvm.org/D20602



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


Re: [PATCH] D20602: Add .rgba syntax extension to ext_vector_type types

2016-05-26 Thread Anastasia Stulova via cfe-commits
Anastasia added a subscriber: Anastasia.


Comment at: include/clang/Basic/DiagnosticSemaKinds.td:7900
@@ -7897,1 +7899,3 @@
+def ext_opencl_ext_vector_type_rgba_selector: ExtWarn<
+  "vector component name '%0' is an OpenCL 2.2 extension">;
 } // end of sema category

Could it be an error instead for CL <2.2? It isn't a valid feature and we have 
already rejected similar cases with an error. 

How about changing to something like:
  "vector component name '%0' is not supported in earlier than OpenCL version 
2.2"

See similar diagnostics above - err_opencl_invalid_read_write, 
err_opencl_unknown_type_specifier.

Using extension might be confusing because we have core spec and extension spec 
in OpenCL.


http://reviews.llvm.org/D20602



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


Re: [PATCH] D20602: Add .rgba syntax extension to ext_vector_type types

2016-05-25 Thread Pirama Arumuga Nainar via cfe-commits
pirama updated this revision to Diff 58537.
pirama added a comment.

Renamed diagnostic to use ext_ prefix.


http://reviews.llvm.org/D20602

Files:
  include/clang/AST/Type.h
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/AST/Expr.cpp
  lib/Sema/SemaExprMember.cpp
  test/CodeGen/ext-vector.c
  test/Misc/warning-flags.c
  test/Sema/ext_vector_components.c
  test/SemaOpenCL/ext_vectors.cl

Index: test/SemaOpenCL/ext_vectors.cl
===
--- /dev/null
+++ test/SemaOpenCL/ext_vectors.cl
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.1
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0
+
+typedef float float4 __attribute__((ext_vector_type(4)));
+
+void test_ext_vector_accessors(float4 V) {
+  V = V.wzyx;
+  V = V.abgr; // expected-warning {{vector component name 'a' is an OpenCL 2.2 extension}}
+  V = V.xyzr; // expected-warning {{vector component name 'r' is an OpenCL 2.2 extension}} \
+  // expected-error {{illegal vector component name 'r'}}
+}
Index: test/Sema/ext_vector_components.c
===
--- test/Sema/ext_vector_components.c
+++ test/Sema/ext_vector_components.c
@@ -39,6 +39,33 @@
 vec4.x = vec16.sF;
   
 vec4p->yz = vec4p->xy;
+
+vec2.a; // expected-error {{vector component access exceeds type 'float2'}}
+vec2.rgba; // expected-error {{vector component access exceeds type 'float2'}}
+vec4.rgba; // expected-warning {{expression result unused}}
+vec4.rgbz; // expected-error {{illegal vector component name 'z'}}
+vec4.rgbc; // expected-error {{illegal vector component name 'c'}}
+vec4.xyzr; // expected-error {{illegal vector component name 'r'}}
+vec4.s01b; // expected-error {{vector component access exceeds type 'float4'}}
+
+vec3 = vec4.rgb; // legal, shorten
+f = vec2.r; // legal, shorten
+f = vec4.rg.r; // legal, shorten
+vec4_2.rgba = vec4.xyzw; // legal, no intermingling
+
+vec4_2.rgbr = vec4.rgba; // expected-error {{vector is not assignable (contains duplicate components)}}
+vec4_2.rgbb = vec4.rgba; // expected-error {{vector is not assignable (contains duplicate components)}}
+vec4_2.rgga = vec4.rgba; // expected-error {{vector is not assignable (contains duplicate components)}}
+vec2.x = f;
+vec2.rr = vec2_2.rg; // expected-error {{vector is not assignable (contains duplicate components)}}
+vec2.gr = vec2_2.rg;
+vec2.gr.g = vec2_2.r;
+vec4 = (float4){ 1,2,3,4 };
+vec4.rg.b; // expected-error {{vector component access exceeds type 'float2'}}
+vec4.r = vec16.sf;
+vec4.g = vec16.sF;
+
+vec4p->gb = vec4p->rg;
 }
 
 float2 lo(float3 x) { return x.lo; }
Index: test/Misc/warning-flags.c
===
--- test/Misc/warning-flags.c
+++ test/Misc/warning-flags.c
@@ -18,7 +18,7 @@
 
 The list of warnings below should NEVER grow.  It should gradually shrink to 0.
 
-CHECK: Warnings without flags (84):
+CHECK: Warnings without flags (85):
 CHECK-NEXT:   ext_excess_initializers
 CHECK-NEXT:   ext_excess_initializers_in_char_array_initializer
 CHECK-NEXT:   ext_expected_semi_decl_list
@@ -83,6 +83,7 @@
 CHECK-NEXT:   warn_objc_property_copy_missing_on_block
 CHECK-NEXT:   warn_objc_protocol_qualifier_missing_id
 CHECK-NEXT:   warn_on_superclass_use
+CHECK-NEXT:   warn_opencl_ext_vector_type_rgba_selector
 CHECK-NEXT:   warn_partial_specs_not_deducible
 CHECK-NEXT:   warn_pp_convert_to_positive
 CHECK-NEXT:   warn_pp_expr_overflow
Index: test/CodeGen/ext-vector.c
===
--- test/CodeGen/ext-vector.c
+++ test/CodeGen/ext-vector.c
@@ -301,3 +301,40 @@
   char valC;
   char16 destVal = valC ? valA : valB;
 }
+
+typedef __attribute__(( ext_vector_type(16) )) float float16;
+
+float16 vec16, vec16_2;
+
+// CHECK: @test_rgba
+void test_rgba() {
+  // CHECK: fadd <4 x float>
+  vec4_2 = vec4.abgr + vec4;
+
+  // CHECK: shufflevector {{.*}} 
+  vec2 = vec4.rg;
+  // CHECK: shufflevector {{.*}} 
+  vec2_2 = vec4.ba;
+  // CHECK: extractelement {{.*}} 2
+  f = vec4.b;
+  // CHECK: shufflevector {{.*}} 
+  vec4_2 = vec4_2.;
+
+  // CHECK: insertelement {{.*}} 0
+  vec2.r = f;
+  // CHECK: shufflevector {{.*}} 
+  vec2.gr = vec2;
+
+  // CHECK: extractelement {{.*}} 0
+  f = vec4_2.rg.r;
+  // CHECK: shufflevector {{.*}} 
+  // CHECK: shufflevector {{.*}} 
+  // CHECK: shufflevector {{.*}} 
+  vec4.rgb = vec4.bgr;
+
+  // CHECK: extractelement {{.*}} 11
+  // CHECK: insertelement {{.*}} 2
+  vec4.b = vec16.sb;
+  // CHECK: shufflevector {{.*}} 
+  vec4_2 = vec16.sabcd;
+}
Index: lib/Sema/SemaExprMember.cpp
===
--- lib/Sema/SemaExprMember.cpp
+++ lib/Sema/SemaExprMember.cpp
@@ -268,6 +268,20 @@
   llvm_unreachable("unexpected instance member access kind");
 

Re: [PATCH] D20602: Add .rgba syntax extension to ext_vector_type types

2016-05-25 Thread Pirama Arumuga Nainar via cfe-commits
pirama updated this revision to Diff 58535.
pirama added a comment.

Switched to ExtWarn, updated warning's message and made the version check 
strict w.r.t. 2.2.


http://reviews.llvm.org/D20602

Files:
  include/clang/AST/Type.h
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/AST/Expr.cpp
  lib/Sema/SemaExprMember.cpp
  test/CodeGen/ext-vector.c
  test/Misc/warning-flags.c
  test/Sema/ext_vector_components.c
  test/SemaOpenCL/ext_vectors.cl

Index: test/SemaOpenCL/ext_vectors.cl
===
--- /dev/null
+++ test/SemaOpenCL/ext_vectors.cl
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.1
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0
+
+typedef float float4 __attribute__((ext_vector_type(4)));
+
+void test_ext_vector_accessors(float4 V) {
+  V = V.wzyx;
+  V = V.abgr; // expected-warning {{vector component name 'a' is an OpenCL 2.2 extension}}
+  V = V.xyzr; // expected-warning {{vector component name 'r' is an OpenCL 2.2 extension}} \
+  // expected-error {{illegal vector component name 'r'}}
+}
Index: test/Sema/ext_vector_components.c
===
--- test/Sema/ext_vector_components.c
+++ test/Sema/ext_vector_components.c
@@ -39,6 +39,33 @@
 vec4.x = vec16.sF;
   
 vec4p->yz = vec4p->xy;
+
+vec2.a; // expected-error {{vector component access exceeds type 'float2'}}
+vec2.rgba; // expected-error {{vector component access exceeds type 'float2'}}
+vec4.rgba; // expected-warning {{expression result unused}}
+vec4.rgbz; // expected-error {{illegal vector component name 'z'}}
+vec4.rgbc; // expected-error {{illegal vector component name 'c'}}
+vec4.xyzr; // expected-error {{illegal vector component name 'r'}}
+vec4.s01b; // expected-error {{vector component access exceeds type 'float4'}}
+
+vec3 = vec4.rgb; // legal, shorten
+f = vec2.r; // legal, shorten
+f = vec4.rg.r; // legal, shorten
+vec4_2.rgba = vec4.xyzw; // legal, no intermingling
+
+vec4_2.rgbr = vec4.rgba; // expected-error {{vector is not assignable (contains duplicate components)}}
+vec4_2.rgbb = vec4.rgba; // expected-error {{vector is not assignable (contains duplicate components)}}
+vec4_2.rgga = vec4.rgba; // expected-error {{vector is not assignable (contains duplicate components)}}
+vec2.x = f;
+vec2.rr = vec2_2.rg; // expected-error {{vector is not assignable (contains duplicate components)}}
+vec2.gr = vec2_2.rg;
+vec2.gr.g = vec2_2.r;
+vec4 = (float4){ 1,2,3,4 };
+vec4.rg.b; // expected-error {{vector component access exceeds type 'float2'}}
+vec4.r = vec16.sf;
+vec4.g = vec16.sF;
+
+vec4p->gb = vec4p->rg;
 }
 
 float2 lo(float3 x) { return x.lo; }
Index: test/Misc/warning-flags.c
===
--- test/Misc/warning-flags.c
+++ test/Misc/warning-flags.c
@@ -18,7 +18,7 @@
 
 The list of warnings below should NEVER grow.  It should gradually shrink to 0.
 
-CHECK: Warnings without flags (84):
+CHECK: Warnings without flags (85):
 CHECK-NEXT:   ext_excess_initializers
 CHECK-NEXT:   ext_excess_initializers_in_char_array_initializer
 CHECK-NEXT:   ext_expected_semi_decl_list
@@ -83,6 +83,7 @@
 CHECK-NEXT:   warn_objc_property_copy_missing_on_block
 CHECK-NEXT:   warn_objc_protocol_qualifier_missing_id
 CHECK-NEXT:   warn_on_superclass_use
+CHECK-NEXT:   warn_opencl_ext_vector_type_rgba_selector
 CHECK-NEXT:   warn_partial_specs_not_deducible
 CHECK-NEXT:   warn_pp_convert_to_positive
 CHECK-NEXT:   warn_pp_expr_overflow
Index: test/CodeGen/ext-vector.c
===
--- test/CodeGen/ext-vector.c
+++ test/CodeGen/ext-vector.c
@@ -301,3 +301,40 @@
   char valC;
   char16 destVal = valC ? valA : valB;
 }
+
+typedef __attribute__(( ext_vector_type(16) )) float float16;
+
+float16 vec16, vec16_2;
+
+// CHECK: @test_rgba
+void test_rgba() {
+  // CHECK: fadd <4 x float>
+  vec4_2 = vec4.abgr + vec4;
+
+  // CHECK: shufflevector {{.*}} 
+  vec2 = vec4.rg;
+  // CHECK: shufflevector {{.*}} 
+  vec2_2 = vec4.ba;
+  // CHECK: extractelement {{.*}} 2
+  f = vec4.b;
+  // CHECK: shufflevector {{.*}} 
+  vec4_2 = vec4_2.;
+
+  // CHECK: insertelement {{.*}} 0
+  vec2.r = f;
+  // CHECK: shufflevector {{.*}} 
+  vec2.gr = vec2;
+
+  // CHECK: extractelement {{.*}} 0
+  f = vec4_2.rg.r;
+  // CHECK: shufflevector {{.*}} 
+  // CHECK: shufflevector {{.*}} 
+  // CHECK: shufflevector {{.*}} 
+  vec4.rgb = vec4.bgr;
+
+  // CHECK: extractelement {{.*}} 11
+  // CHECK: insertelement {{.*}} 2
+  vec4.b = vec16.sb;
+  // CHECK: shufflevector {{.*}} 
+  vec4_2 = vec16.sabcd;
+}
Index: lib/Sema/SemaExprMember.cpp
===
--- lib/Sema/SemaExprMember.cpp
+++ lib/Sema/SemaExprMember.cpp
@@ -268,6 +268,20 @@
   

Re: [PATCH] D20602: Add .rgba syntax extension to ext_vector_type types

2016-05-25 Thread Richard Smith via cfe-commits
rsmith added a comment.

Looks good other than the recent information about the version of OpenCL that 
actually specifies this.



Comment at: include/clang/Basic/DiagnosticSemaKinds.td:7899
@@ +7898,3 @@
+// OpenCL v2.2 s2.1.2.3 - Vector Component Access
+def warn_opencl_ext_vector_type_rgba_selector: Warning <
+  "vector component name '%0' is not part of OpenCL 2.0 and earlier">;

This should be an `ExtWarn`, not a `Warning`, and should be named `ext_...`. 
That way we'll reject it under `-cl-std=CL2.0 -pedantic-errors`.


Comment at: include/clang/Basic/DiagnosticSemaKinds.td:7900
@@ -7897,1 +7899,3 @@
+def warn_opencl_ext_vector_type_rgba_selector: Warning <
+  "vector component name '%0' is not part of OpenCL 2.0 and earlier">;
 } // end of sema category

I think the result of the discussion was that this is added in OpenCL 2.2. The 
way we phrase this in other diagnostics is:

  "vector component name '%0' is an OpenCL 2.2 extension"


Comment at: lib/Sema/SemaExprMember.cpp:334-336
@@ +333,5 @@
+
+// Emit a warning if an rgba selector is used in OpenCL 2.0 and below.
+if (HasRGBA || (*compStr && IsRGBA(*compStr))) {
+  if (S.getLangOpts().OpenCL && S.getLangOpts().OpenCLVersion <= 200) {
+const char *diagBegin = HasRGBA ? CompName->getNameStart() : compStr;

This should presumably be `OpenCLVersion < 220`.


http://reviews.llvm.org/D20602



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


Re: [PATCH] D20602: Add .rgba syntax extension to ext_vector_type types

2016-05-25 Thread Pirama Arumuga Nainar via cfe-commits
pirama added a comment.

> > > I'm not suggesting it be treated as invalid. This extension is part of at 
> > > least OpenCL 2.1, but it's not part of OpenCL 1.0. `ext_vector_type` is 
> > > Clang's implementation of the OpenCL vector type. Therefore if the user 
> > > asks us to support OpenCL 1.0, we should give them a warning if they use 
> > > this syntax.

> 

> > 

> 

> 

> 

> 

> - use of ext_vector_type in OpenCL 1.0 and earlier.


Looks like OpenCL 1.0 also has vector data types (Section 6.1.2 
https://www.khronos.org/registry/cl/specs/opencl-1.0.pdf).  So, I don't think 
it is necessary to emit warnings for ext_vector_types at all.


http://reviews.llvm.org/D20602



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


Re: [PATCH] D20602: Add .rgba syntax extension to ext_vector_type types

2016-05-25 Thread Pirama Arumuga Nainar via cfe-commits
pirama updated this revision to Diff 58525.
pirama added a comment.

Added warnings when rgba is used with OpenCL


http://reviews.llvm.org/D20602

Files:
  include/clang/AST/Type.h
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/AST/Expr.cpp
  lib/Sema/SemaExprMember.cpp
  test/CodeGen/ext-vector.c
  test/Misc/warning-flags.c
  test/Sema/ext_vector_components.c
  test/SemaOpenCL/ext_vectors.cl

Index: test/SemaOpenCL/ext_vectors.cl
===
--- /dev/null
+++ test/SemaOpenCL/ext_vectors.cl
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.1
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0
+
+typedef float float4 __attribute__((ext_vector_type(4)));
+
+void test_ext_vector_accessors(float4 V) {
+  V = V.wzyx;
+  V = V.abgr; // expected-warning {{vector component name 'a' is not part of OpenCL 2.0 and earlier}}
+  V = V.xyzr; // expected-warning {{vector component name 'r' is not part of OpenCL 2.0 and earlier}} \
+  // expected-error {{illegal vector component name 'r'}}
+}
Index: test/Sema/ext_vector_components.c
===
--- test/Sema/ext_vector_components.c
+++ test/Sema/ext_vector_components.c
@@ -39,6 +39,33 @@
 vec4.x = vec16.sF;
   
 vec4p->yz = vec4p->xy;
+
+vec2.a; // expected-error {{vector component access exceeds type 'float2'}}
+vec2.rgba; // expected-error {{vector component access exceeds type 'float2'}}
+vec4.rgba; // expected-warning {{expression result unused}}
+vec4.rgbz; // expected-error {{illegal vector component name 'z'}}
+vec4.rgbc; // expected-error {{illegal vector component name 'c'}}
+vec4.xyzr; // expected-error {{illegal vector component name 'r'}}
+vec4.s01b; // expected-error {{vector component access exceeds type 'float4'}}
+
+vec3 = vec4.rgb; // legal, shorten
+f = vec2.r; // legal, shorten
+f = vec4.rg.r; // legal, shorten
+vec4_2.rgba = vec4.xyzw; // legal, no intermingling
+
+vec4_2.rgbr = vec4.rgba; // expected-error {{vector is not assignable (contains duplicate components)}}
+vec4_2.rgbb = vec4.rgba; // expected-error {{vector is not assignable (contains duplicate components)}}
+vec4_2.rgga = vec4.rgba; // expected-error {{vector is not assignable (contains duplicate components)}}
+vec2.x = f;
+vec2.rr = vec2_2.rg; // expected-error {{vector is not assignable (contains duplicate components)}}
+vec2.gr = vec2_2.rg;
+vec2.gr.g = vec2_2.r;
+vec4 = (float4){ 1,2,3,4 };
+vec4.rg.b; // expected-error {{vector component access exceeds type 'float2'}}
+vec4.r = vec16.sf;
+vec4.g = vec16.sF;
+
+vec4p->gb = vec4p->rg;
 }
 
 float2 lo(float3 x) { return x.lo; }
Index: test/Misc/warning-flags.c
===
--- test/Misc/warning-flags.c
+++ test/Misc/warning-flags.c
@@ -18,7 +18,7 @@
 
 The list of warnings below should NEVER grow.  It should gradually shrink to 0.
 
-CHECK: Warnings without flags (84):
+CHECK: Warnings without flags (85):
 CHECK-NEXT:   ext_excess_initializers
 CHECK-NEXT:   ext_excess_initializers_in_char_array_initializer
 CHECK-NEXT:   ext_expected_semi_decl_list
@@ -83,6 +83,7 @@
 CHECK-NEXT:   warn_objc_property_copy_missing_on_block
 CHECK-NEXT:   warn_objc_protocol_qualifier_missing_id
 CHECK-NEXT:   warn_on_superclass_use
+CHECK-NEXT:   warn_opencl_ext_vector_type_rgba_selector
 CHECK-NEXT:   warn_partial_specs_not_deducible
 CHECK-NEXT:   warn_pp_convert_to_positive
 CHECK-NEXT:   warn_pp_expr_overflow
Index: test/CodeGen/ext-vector.c
===
--- test/CodeGen/ext-vector.c
+++ test/CodeGen/ext-vector.c
@@ -301,3 +301,40 @@
   char valC;
   char16 destVal = valC ? valA : valB;
 }
+
+typedef __attribute__(( ext_vector_type(16) )) float float16;
+
+float16 vec16, vec16_2;
+
+// CHECK: @test_rgba
+void test_rgba() {
+  // CHECK: fadd <4 x float>
+  vec4_2 = vec4.abgr + vec4;
+
+  // CHECK: shufflevector {{.*}} 
+  vec2 = vec4.rg;
+  // CHECK: shufflevector {{.*}} 
+  vec2_2 = vec4.ba;
+  // CHECK: extractelement {{.*}} 2
+  f = vec4.b;
+  // CHECK: shufflevector {{.*}} 
+  vec4_2 = vec4_2.;
+
+  // CHECK: insertelement {{.*}} 0
+  vec2.r = f;
+  // CHECK: shufflevector {{.*}} 
+  vec2.gr = vec2;
+
+  // CHECK: extractelement {{.*}} 0
+  f = vec4_2.rg.r;
+  // CHECK: shufflevector {{.*}} 
+  // CHECK: shufflevector {{.*}} 
+  // CHECK: shufflevector {{.*}} 
+  vec4.rgb = vec4.bgr;
+
+  // CHECK: extractelement {{.*}} 11
+  // CHECK: insertelement {{.*}} 2
+  vec4.b = vec16.sb;
+  // CHECK: shufflevector {{.*}} 
+  vec4_2 = vec16.sabcd;
+}
Index: lib/Sema/SemaExprMember.cpp
===
--- lib/Sema/SemaExprMember.cpp
+++ lib/Sema/SemaExprMember.cpp
@@ -268,6 +268,20 @@
   llvm_unreachable("unexpected 

Re: [PATCH] D20602: Add .rgba syntax extension to ext_vector_type types

2016-05-25 Thread Richard Smith via cfe-commits
On Wed, May 25, 2016 at 2:20 PM, Aleksey Bader 
wrote:

> On Wed, May 25, 2016 at 11:53 PM, Richard Smith 
> wrote:
>
>> On Wed, May 25, 2016 at 2:20 AM, Alexey Bader via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> bader added a subscriber: bader.
>>> bader added a comment.
>>>
>>> In http://reviews.llvm.org/D20602#438667, @rsmith wrote:
>>>
>>> > I'm not suggesting it be treated as invalid. This extension is part of
>>> at least OpenCL 2.1, but it's not part of OpenCL 1.0. `ext_vector_type` is
>>> Clang's implementation of the OpenCL vector type. Therefore if the user
>>> asks us to support OpenCL 1.0, we should give them a warning if they use
>>> this syntax.
>>> >
>>> > If we're not building an OpenCL source file, then yes, this is our
>>> extension and it makes sense for it to be available unconditionally
>>> (without a warning).
>>>
>>>
>>> To avoid confusion, I'd like to note that rgba selector was first
>>> introduced in OpenCL C++ kernel language, which is currently in provisional
>>> state and will be part of OpenCL version 2.2.
>>> https://www.khronos.org/registry/cl/specs/opencl-2.2-cplusplus.pdf
>>> (page 18).
>>>
>>
>> https://www.khronos.org/registry/cl/specs/opencl-2.1-openclc++.pdf page
>> 12-13 document it. Is that not OpenCL version 2.1?
>>
>>
>
> Not quite. OpenCL C++ kernel language was planned to be ratified with
> OpenCL 2.1 standard, but it did happen.
> It's still listed as provisional although OpenCL 2.1 specification was
> released last year. https://www.khronos.org/opencl/
> Ratified OpenCL 2.1 standard requires to support only OpenCL C 2.0 and
> SPIR-V 1.0 kernel languages.
> There is no much sense to support provisional specification that will
> never be ratified.
>

Thanks for the explanation.

It seems to me that the right way to handle this is the same way we'd
handle any feature that's part of an upcoming language standard:
 - add a flag to enable the OpenCL 2.2 language mode
 - if an OpenCL compilation uses this extension and doesn't specify that
version or newer, produce an `ExtWarn`

BTW, Khronos provided open source implementation of OpenCL C++ compiler and
> since OpenCL C++ is a new kernel language and specification (
> https://www.khronos.org/registry/cl/specs/opencl-2.2-cplusplus.pdf) is
> version 1.0, the numbering of standard versions is different from OpenCL C.
> Current std version is 'c++'.
> Here is usage example:
> https://github.com/KhronosGroup/SPIR/blob/spirv-1.1/test/OpenCL/OpenCL22/opencl_cplusplus.cl
>

That's a really weird way to specify a version number.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20602: Add .rgba syntax extension to ext_vector_type types

2016-05-25 Thread Aleksey Bader via cfe-commits
On Wed, May 25, 2016 at 11:53 PM, Richard Smith 
wrote:

> On Wed, May 25, 2016 at 2:20 AM, Alexey Bader via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> bader added a subscriber: bader.
>> bader added a comment.
>>
>> In http://reviews.llvm.org/D20602#438667, @rsmith wrote:
>>
>> > I'm not suggesting it be treated as invalid. This extension is part of
>> at least OpenCL 2.1, but it's not part of OpenCL 1.0. `ext_vector_type` is
>> Clang's implementation of the OpenCL vector type. Therefore if the user
>> asks us to support OpenCL 1.0, we should give them a warning if they use
>> this syntax.
>> >
>> > If we're not building an OpenCL source file, then yes, this is our
>> extension and it makes sense for it to be available unconditionally
>> (without a warning).
>>
>>
>> To avoid confusion, I'd like to note that rgba selector was first
>> introduced in OpenCL C++ kernel language, which is currently in provisional
>> state and will be part of OpenCL version 2.2.
>> https://www.khronos.org/registry/cl/specs/opencl-2.2-cplusplus.pdf (page
>> 18).
>>
>
> https://www.khronos.org/registry/cl/specs/opencl-2.1-openclc++.pdf page
> 12-13 document it. Is that not OpenCL version 2.1?
>
>

Not quite. OpenCL C++ kernel language was planned to be ratified with
OpenCL 2.1 standard, but it did happen.
It's still listed as provisional although OpenCL 2.1 specification was
released last year. https://www.khronos.org/opencl/
Ratified OpenCL 2.1 standard requires to support only OpenCL C 2.0 and
SPIR-V 1.0 kernel languages.
There is no much sense to support provisional specification that will never
be ratified.

BTW, Khronos provided open source implementation of OpenCL C++ compiler and
since OpenCL C++ is a new kernel language and specification (
https://www.khronos.org/registry/cl/specs/opencl-2.2-cplusplus.pdf) is
version 1.0, the numbering of standard versions is different from OpenCL C.
Current std version is 'c++'.
Here is usage example:
https://github.com/KhronosGroup/SPIR/blob/spirv-1.1/test/OpenCL/OpenCL22/opencl_cplusplus.cl


> OpenCL version 2.1 uses OpenCL C 2.0 kernel language, which doesn't
>> support rgba selector.
>>
>> https://www.khronos.org/registry/cl/ - latest versions of OpenCL specs.
>>
>>
>> http://reviews.llvm.org/D20602
>>
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20602: Add .rgba syntax extension to ext_vector_type types

2016-05-25 Thread Richard Smith via cfe-commits
On Wed, May 25, 2016 at 2:20 AM, Alexey Bader via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> bader added a subscriber: bader.
> bader added a comment.
>
> In http://reviews.llvm.org/D20602#438667, @rsmith wrote:
>
> > I'm not suggesting it be treated as invalid. This extension is part of
> at least OpenCL 2.1, but it's not part of OpenCL 1.0. `ext_vector_type` is
> Clang's implementation of the OpenCL vector type. Therefore if the user
> asks us to support OpenCL 1.0, we should give them a warning if they use
> this syntax.
> >
> > If we're not building an OpenCL source file, then yes, this is our
> extension and it makes sense for it to be available unconditionally
> (without a warning).
>
>
> To avoid confusion, I'd like to note that rgba selector was first
> introduced in OpenCL C++ kernel language, which is currently in provisional
> state and will be part of OpenCL version 2.2.
> https://www.khronos.org/registry/cl/specs/opencl-2.2-cplusplus.pdf (page
> 18).
>

https://www.khronos.org/registry/cl/specs/opencl-2.1-openclc++.pdf page
12-13 document it. Is that not OpenCL version 2.1?


> OpenCL version 2.1 uses OpenCL C 2.0 kernel language, which doesn't
> support rgba selector.
>
> https://www.khronos.org/registry/cl/ - latest versions of OpenCL specs.
>
>
> http://reviews.llvm.org/D20602
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20602: Add .rgba syntax extension to ext_vector_type types

2016-05-25 Thread Pirama Arumuga Nainar via cfe-commits
pirama added a comment.

To summarize, there are two scenarios where a warning is warranted when the 
source language is OpenCL:

> > I'm not suggesting it be treated as invalid. This extension is part of at 
> > least OpenCL 2.1, but it's not part of OpenCL 1.0. `ext_vector_type` is 
> > Clang's implementation of the OpenCL vector type. Therefore if the user 
> > asks us to support OpenCL 1.0, we should give them a warning if they use 
> > this syntax.

> 




- use of ext_vector_type in OpenCL 1.0 and earlier.

> To avoid confusion, I'd like to note that rgba selector was first introduced 
> in OpenCL C++ kernel language, which is currently in provisional state and 
> will be part of OpenCL version 2.2.




- use of rgba selector in OpenCL 2.1 and earlier.

I'll look at how to add the first warning.  I'll most probably upload a 
separate CL for this.

I can easily add the second warning in this CL - to emit one on *any* OpenCL 
source.  Alexey: can you take care of revising this warning when OpenCL2.2 is 
added as a langugage standard?


http://reviews.llvm.org/D20602



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


Re: [PATCH] D20602: Add .rgba syntax extension to ext_vector_type types

2016-05-25 Thread Alexey Bader via cfe-commits
bader added a subscriber: bader.
bader added a comment.

In http://reviews.llvm.org/D20602#438667, @rsmith wrote:

> I'm not suggesting it be treated as invalid. This extension is part of at 
> least OpenCL 2.1, but it's not part of OpenCL 1.0. `ext_vector_type` is 
> Clang's implementation of the OpenCL vector type. Therefore if the user asks 
> us to support OpenCL 1.0, we should give them a warning if they use this 
> syntax.
>
> If we're not building an OpenCL source file, then yes, this is our extension 
> and it makes sense for it to be available unconditionally (without a warning).


To avoid confusion, I'd like to note that rgba selector was first introduced in 
OpenCL C++ kernel language, which is currently in provisional state and will be 
part of OpenCL version 2.2. 
https://www.khronos.org/registry/cl/specs/opencl-2.2-cplusplus.pdf (page 18).

OpenCL version 2.1 uses OpenCL C 2.0 kernel language, which doesn't support 
rgba selector.

https://www.khronos.org/registry/cl/ - latest versions of OpenCL specs.


http://reviews.llvm.org/D20602



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


Re: [PATCH] D20602: Add .rgba syntax extension to ext_vector_type types

2016-05-24 Thread Richard Smith via cfe-commits
rsmith added a comment.

In http://reviews.llvm.org/D20602#438643, @srhines wrote:

> In http://reviews.llvm.org/D20602#438528, @rsmith wrote:
>
> > Looks like this extension was added at some point between 1.1 and 2.1. It 
> > would make sense to produce an `ExtWarn` for it if the OpenCL standard 
> > version is less than the one that introduced it (whenever that was) -- that 
> > would match what we do for extensions in other languages.
>
>
> This isn't just for OpenCL (actually we don't care about it in the context of 
> OpenCL at all). We really are adding this as more of an extension for C99, 
> where Android has used this in the past. In the case of OpenCL, I also don't 
> know that it should be recognized as invalid, because it can be lowered to an 
> appropriate construct on any implementation (since they all have to support 
> regular 4-vectors).


I'm not suggesting it be treated as invalid. This extension is part of at least 
OpenCL 2.1, but it's not part of OpenCL 1.0. `ext_vector_type` is Clang's 
implementation of the OpenCL vector type. Therefore if the user asks us to 
support OpenCL 1.0, we should give them a warning if they use this syntax.

If we're not building an OpenCL source file, then yes, this is our extension 
and it makes sense for it to be available unconditionally (without a warning).


http://reviews.llvm.org/D20602



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


Re: [PATCH] D20602: Add .rgba syntax extension to ext_vector_type types

2016-05-24 Thread Stephen Hines via cfe-commits
srhines added a comment.

In http://reviews.llvm.org/D20602#438528, @rsmith wrote:

> Looks like this extension was added at some point between 1.1 and 2.1. It 
> would make sense to produce an `ExtWarn` for it if the OpenCL standard 
> version is less than the one that introduced it (whenever that was) -- that 
> would match what we do for extensions in other languages.


This isn't just for OpenCL (actually we don't care about it in the context of 
OpenCL at all). We really are adding this as more of an extension for C99, 
where Android has used this in the past. In the case of OpenCL, I also don't 
know that it should be recognized as invalid, because it can be lowered to an 
appropriate construct on any implementation (since they all have to support 
regular 4-vectors).


http://reviews.llvm.org/D20602



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


Re: [PATCH] D20602: Add .rgba syntax extension to ext_vector_type types

2016-05-24 Thread Richard Smith via cfe-commits
rsmith added a comment.

Looks like this extension was added at some point between 1.1 and 2.1. It would 
make sense to produce an `ExtWarn` for it if the OpenCL standard version is 
less than the one that introduced it (whenever that was) -- that would match 
what we do for extensions in other languages.


http://reviews.llvm.org/D20602



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


[PATCH] D20602: Add .rgba syntax extension to ext_vector_type types

2016-05-24 Thread Pirama Arumuga Nainar via cfe-commits
pirama created this revision.
pirama added subscribers: cfe-commits, srhines.

This patch enables .rgba accessors to ext_vector_type types and adds
tests for syntax validation and code generation.

'a' and 'b' can appear either in the point access mode or the numeric
access mode (for indices 10 and 11).  To disambiguate between the two
usages, the accessor type is explicitly passed to relevant methods.

http://reviews.llvm.org/D20602

Files:
  include/clang/AST/Type.h
  lib/AST/Expr.cpp
  lib/Sema/SemaExprMember.cpp
  test/CodeGen/ext-vector.c
  test/Sema/ext_vector_components.c

Index: test/Sema/ext_vector_components.c
===
--- test/Sema/ext_vector_components.c
+++ test/Sema/ext_vector_components.c
@@ -39,6 +39,33 @@
 vec4.x = vec16.sF;
   
 vec4p->yz = vec4p->xy;
+
+vec2.a; // expected-error {{vector component access exceeds type 'float2'}}
+vec2.rgba; // expected-error {{vector component access exceeds type 'float2'}}
+vec4.rgba; // expected-warning {{expression result unused}}
+vec4.rgbz; // expected-error {{illegal vector component name 'z'}}
+vec4.rgbc; // expected-error {{illegal vector component name 'c'}}
+vec4.xyzr; // expected-error {{illegal vector component name 'r'}}
+vec4.s01b; // expected-error {{vector component access exceeds type 'float4'}}
+
+vec3 = vec4.rgb; // legal, shorten
+f = vec2.r; // legal, shorten
+f = vec4.rg.r; // legal, shorten
+vec4_2.rgba = vec4.xyzw; // legal, no intermingling
+
+vec4_2.rgbr = vec4.rgba; // expected-error {{vector is not assignable (contains duplicate components)}}
+vec4_2.rgbb = vec4.rgba; // expected-error {{vector is not assignable (contains duplicate components)}}
+vec4_2.rgga = vec4.rgba; // expected-error {{vector is not assignable (contains duplicate components)}}
+vec2.x = f;
+vec2.rr = vec2_2.rg; // expected-error {{vector is not assignable (contains duplicate components)}}
+vec2.gr = vec2_2.rg;
+vec2.gr.g = vec2_2.r;
+vec4 = (float4){ 1,2,3,4 };
+vec4.rg.b; // expected-error {{vector component access exceeds type 'float2'}}
+vec4.r = vec16.sf;
+vec4.g = vec16.sF;
+
+vec4p->gb = vec4p->rg;
 }
 
 float2 lo(float3 x) { return x.lo; }
Index: test/CodeGen/ext-vector.c
===
--- test/CodeGen/ext-vector.c
+++ test/CodeGen/ext-vector.c
@@ -301,3 +301,40 @@
   char valC;
   char16 destVal = valC ? valA : valB;
 }
+
+typedef __attribute__(( ext_vector_type(16) )) float float16;
+
+float16 vec16, vec16_2;
+
+// CHECK: @test_rgba
+void test_rgba() {
+  // CHECK: fadd <4 x float>
+  vec4_2 = vec4.abgr + vec4;
+
+  // CHECK: shufflevector {{.*}} 
+  vec2 = vec4.rg;
+  // CHECK: shufflevector {{.*}} 
+  vec2_2 = vec4.ba;
+  // CHECK: extractelement {{.*}} 2
+  f = vec4.b;
+  // CHECK: shufflevector {{.*}} 
+  vec4_2 = vec4_2.;
+
+  // CHECK: insertelement {{.*}} 0
+  vec2.r = f;
+  // CHECK: shufflevector {{.*}} 
+  vec2.gr = vec2;
+
+  // CHECK: extractelement {{.*}} 0
+  f = vec4_2.rg.r;
+  // CHECK: shufflevector {{.*}} 
+  // CHECK: shufflevector {{.*}} 
+  // CHECK: shufflevector {{.*}} 
+  vec4.rgb = vec4.bgr;
+
+  // CHECK: extractelement {{.*}} 11
+  // CHECK: insertelement {{.*}} 2
+  vec4.b = vec16.sb;
+  // CHECK: shufflevector {{.*}} 
+  vec4_2 = vec16.sabcd;
+}
Index: lib/Sema/SemaExprMember.cpp
===
--- lib/Sema/SemaExprMember.cpp
+++ lib/Sema/SemaExprMember.cpp
@@ -268,6 +268,20 @@
   llvm_unreachable("unexpected instance member access kind");
 }
 
+/// Determine whether input char is from rgba component set.
+static bool
+IsRGBA(char c) {
+  switch (c) {
+  case 'r':
+  case 'g':
+  case 'b':
+  case 'a':
+return true;
+  default:
+return false;
+  }
+}
+
 /// Check an ext-vector component access expression.
 ///
 /// VK should be set in advance to the value kind of the base
@@ -307,7 +321,11 @@
 HalvingSwizzle = true;
   } else if (!HexSwizzle &&
  (Idx = vecType->getPointAccessorIdx(*compStr)) != -1) {
+bool HasRGBA = IsRGBA(*compStr);
 do {
+  // Ensure that xyzw and rgba components don't intermingle.
+  if (HasRGBA != IsRGBA(*compStr))
+break;
   if (HasIndex[Idx]) HasRepeated = true;
   HasIndex[Idx] = true;
   compStr++;
@@ -338,7 +356,7 @@
   compStr++;
 
 while (*compStr) {
-  if (!vecType->isAccessorWithinNumElements(*compStr++)) {
+  if (!vecType->isAccessorWithinNumElements(*compStr++, HexSwizzle)) {
 S.Diag(OpLoc, diag::err_ext_vector_component_exceeds_length)
   << baseType << SourceRange(CompLoc);
 return QualType();
Index: lib/AST/Expr.cpp
===
--- lib/AST/Expr.cpp
+++ lib/AST/Expr.cpp
@@ -3383,8 +3383,11 @@
 void ExtVectorElementExpr::getEncodedElementAccess(
 SmallVectorImpl