|
| 1 | +// RUN: %clang_cc1 -fsycl-is-device -fsyntax-only -ast-dump -verify -pedantic %s | FileCheck %s |
| 2 | + |
| 3 | +// Test that checks template parameter support for 'sycl_esimd_vectorize' attribute on sycl device. |
| 4 | + |
| 5 | +// Test wrong function template instantiation and ensure that the type |
| 6 | +// is checked properly when instantiating from the template definition. |
| 7 | +template <typename Ty> |
| 8 | +// expected-error@+3{{integral constant expression must have integral or unscoped enumeration type, not 'S'}} |
| 9 | +// expected-error@+2{{integral constant expression must have integral or unscoped enumeration type, not 'float'}} |
| 10 | +// expected-error@+1{{'sycl_esimd_vectorize' attribute argument must be 8, 16, or 32}} |
| 11 | +[[intel::sycl_esimd_vectorize(Ty{})]] void func() {} |
| 12 | + |
| 13 | +struct S {}; |
| 14 | +void test() { |
| 15 | + //expected-note@+1{{in instantiation of function template specialization 'func<S>' requested here}} |
| 16 | + func<S>(); |
| 17 | + //expected-note@+1{{in instantiation of function template specialization 'func<float>' requested here}} |
| 18 | + func<float>(); |
| 19 | + //expected-note@+1{{in instantiation of function template specialization 'func<int>' requested here}} |
| 20 | + func<int>(); |
| 21 | +} |
| 22 | + |
| 23 | +// Test a non-constant expression. |
| 24 | +// expected-note@+1{{declared here}} |
| 25 | +int foo(); |
| 26 | +// expected-error@+2{{expression is not an integral constant expression}} |
| 27 | +// expected-note@+1{{non-constexpr function 'foo' cannot be used in a constant expression}} |
| 28 | +[[intel::sycl_esimd_vectorize(foo() + 12)]] void func1(); |
| 29 | + |
| 30 | +// Test a constant expression. |
| 31 | +constexpr int bar() { return 0; } |
| 32 | +[[intel::sycl_esimd_vectorize(bar() + 16)]] void func2(); // OK |
| 33 | + |
| 34 | +// Test template parameter support on member function of class template. |
| 35 | +template <int SIZE> |
| 36 | +class KernelFunctor { |
| 37 | +public: |
| 38 | + // expected-error@+1{{'sycl_esimd_vectorize' attribute argument must be 8, 16, or 32}} |
| 39 | + [[intel::sycl_esimd_vectorize(SIZE)]] void operator()() {} |
| 40 | +}; |
| 41 | + |
| 42 | +int main() { |
| 43 | + //expected-note@+1{{in instantiation of template class 'KernelFunctor<-1>' requested here}} |
| 44 | + KernelFunctor<-1>(); |
| 45 | + // no error expected |
| 46 | + KernelFunctor<8>(); |
| 47 | + return 0; |
| 48 | +} |
| 49 | + |
| 50 | +// CHECK: ClassTemplateDecl {{.*}} {{.*}} KernelFunctor |
| 51 | +// CHECK: ClassTemplateSpecializationDecl {{.*}} {{.*}} class KernelFunctor definition |
| 52 | +// CHECK: CXXRecordDecl {{.*}} {{.*}} implicit class KernelFunctor |
| 53 | +// CHECK: SYCLIntelESimdVectorizeAttr {{.*}} |
| 54 | +// CHECK: SubstNonTypeTemplateParmExpr {{.*}} |
| 55 | +// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} |
| 56 | +// CHECK-NEXT: IntegerLiteral{{.*}}8{{$}} |
| 57 | + |
| 58 | +// Test template parameter support on function. |
| 59 | +template <int N> |
| 60 | +// expected-error@+1{{'sycl_esimd_vectorize' attribute argument must be 8, 16, or 32}} |
| 61 | +[[intel::sycl_esimd_vectorize(N)]] void func3() {} |
| 62 | + |
| 63 | +template <int N> |
| 64 | +[[intel::sycl_esimd_vectorize(32)]] void func4(); // expected-note {{previous attribute is here}} |
| 65 | + |
| 66 | +template <int N> |
| 67 | +[[intel::sycl_esimd_vectorize(N)]] void func4() {} // expected-warning {{attribute 'sycl_esimd_vectorize' is already applied with different arguments}} |
| 68 | + |
| 69 | +int check() { |
| 70 | + // no error expected. |
| 71 | + func3<8>(); |
| 72 | + //expected-note@+1{{in instantiation of function template specialization 'func3<-1>' requested here}} |
| 73 | + func3<-1>(); |
| 74 | + //expected-note@+1 {{in instantiation of function template specialization 'func4<16>' requested here}} |
| 75 | + func4<16>(); |
| 76 | + return 0; |
| 77 | +} |
| 78 | + |
| 79 | +// No diagnostic is emitted because the arguments match. Duplicate attribute is silently ignored. |
| 80 | +[[intel::sycl_esimd_vectorize(8)]] |
| 81 | +[[intel::sycl_esimd_vectorize(8)]] void func5() {} |
| 82 | + |
| 83 | +// CHECK: FunctionTemplateDecl {{.*}} {{.*}} func3 |
| 84 | +// CHECK: NonTypeTemplateParmDecl {{.*}} {{.*}} referenced 'int' depth 0 index 0 N |
| 85 | +// CHECK: FunctionDecl {{.*}} {{.*}} func3 'void ()' |
| 86 | +// CHECK: SYCLIntelESimdVectorizeAttr {{.*}} |
| 87 | +// CHECK: SubstNonTypeTemplateParmExpr {{.*}} |
| 88 | +// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} |
| 89 | +// CHECK-NEXT: IntegerLiteral{{.*}}8{{$}} |
| 90 | + |
| 91 | +// CHECK: FunctionDecl {{.*}} {{.*}} func5 'void ()' |
| 92 | +// CHECK: SYCLIntelESimdVectorizeAttr {{.*}} |
| 93 | +// CHECK-NEXT: ConstantExpr {{.*}} 'int' |
| 94 | +// CHECK-NEXT: value: Int 8 |
| 95 | +// CHECK-NEXT: IntegerLiteral{{.*}}8{{$}} |
0 commit comments