Home | History | Annotate | Download | only in SemaOpenCL
      1 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -Wno-unused-value -triple spir-unknown-unknown
      2 
      3 #pragma OPENCL EXTENSION cl_khr_fp16 : disable
      4 constant float f = 1.0h; // expected-error{{half precision constant requires cl_khr_fp16}}
      5 
      6 half half_disabled(half *p, // expected-error{{declaring function return value of type 'half' is not allowed}}
      7                    half h)  // expected-error{{declaring function parameter of type 'half' is not allowed}}
      8 {
      9   half a[2]; // expected-error{{declaring variable of type 'half [2]' is not allowed}}
     10   half b;    // expected-error{{declaring variable of type 'half' is not allowed}}
     11   *p; // expected-error{{loading directly from pointer to type 'half' is not allowed}}
     12   p[1]; // expected-error{{loading directly from pointer to type 'half' is not allowed}}
     13 
     14   float c = 1.0f;
     15   b = (half) c;  // expected-error{{casting to type 'half' is not allowed}}
     16   c = (float) 1.0h;  // expected-error{{half precision constant requires cl_khr_fp16}}
     17   b = 1.0h; // expected-error{{half precision constant requires cl_khr_fp16}}
     18 
     19   half *allowed = &p[1];
     20   half *allowed2 = &*p;
     21   half *allowed3 = p + 1;
     22 
     23   return h;
     24 }
     25 
     26 // Exactly the same as above but with the cl_khr_fp16 extension enabled.
     27 #pragma OPENCL EXTENSION cl_khr_fp16 : enable
     28 constant half a = 1.0h;
     29 half half_enabled(half *p, half h)
     30 {
     31   half a[2];
     32   half b;
     33   *p;
     34   p[1];
     35 
     36   float c = 1.0f;
     37   b = (half) c;
     38   c = (float) 1.0h;
     39   b = 1.0h;
     40 
     41   half *allowed = &p[1];
     42   half *allowed2 = &*p;
     43   half *allowed3 = p + 1;
     44 
     45   return h;
     46 }
     47