brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.5 KiB · 526e865 Raw
122 lines · plain
1//RUN: %clang_cc1 %s -pedantic -ast-dump -verify | FileCheck %s2 3//expected-no-diagnostics4 5//CHECK: |-VarDecl {{.*}} foo 'const __global int'6constexpr int foo = 0;7 8//CHECK: |-VarDecl {{.*}} foo1 'T' cinit9//CHECK: `-VarTemplateSpecializationDecl {{.*}} used foo1 '__global long' implicit_instantiation cinit10template <typename T>11T foo1 = 0;12 13class c {14public:15  //CHECK: `-VarDecl {{.*}} foo2 'const __global int'16  static constexpr int foo2 = 0;17};18 19struct c1 {};20 21// We only deduce addr space in type alias in pointer types.22//CHECK: TypeAliasDecl {{.*}} alias_c1 'c1'23using alias_c1 = c1;24//CHECK: TypeAliasDecl {{.*}} alias_c1_ptr '__generic c1 *'25using alias_c1_ptr = c1 *;26 27struct c2 {28  alias_c1 y;29  alias_c1_ptr ptr = &y;30};31 32 33// Addr spaces for pointee of dependent types are not deduced34// during parsing but during template instantiation instead.35 36template <class T>37struct x1 {38//CHECK: -CXXMethodDecl {{.*}} operator= 'x1<T> &(const x1<T> &){{( __attribute__.*)?}} __generic'39//CHECK: -CXXMethodDecl {{.*}} operator= '__generic x1<int> &(const __generic x1<int> &__private){{( __attribute__.*)?}} __generic'40  x1<T>& operator=(const x1<T>& xx) {41    y = xx.y;42    return *this;43  }44  int y;45};46 47template <class T>48struct x2 {49//CHECK: -CXXMethodDecl {{.*}} foo 'void (x1<T> *){{( __attribute__.*)?}} __generic'50//CHECK: -CXXMethodDecl {{.*}} foo 'void (__generic x1<int> *__private){{( __attribute__.*)?}} __generic'51  void foo(x1<T>* xx) {52    m[0] = *xx;53  }54//CHECK: -FieldDecl {{.*}}  m 'x1<int>[2]'55  x1<T> m[2];56};57 58void bar(__global x1<int> *xx, __global x2<int> *bar) {59  bar->foo(xx);60}61 62template <typename T>63class x3 : public T {64public:65  //CHECK: -CXXConstructorDecl {{.*}} x3<T> 'void (const x3<T> &){{( __attribute__.*)?}} __generic'66  x3(const x3 &t);67};68//CHECK: -CXXConstructorDecl {{.*}} x3<T> 'void (const x3<T> &){{( __attribute__.*)?}} __generic'69template <typename T>70x3<T>::x3(const x3<T> &t) {}71 72template <class T>73T xxx(T *in1, T in2) {74  // This pointer can't be deduced to generic because addr space75  // will be taken from the template argument.76  //CHECK: `-VarDecl {{.*}} 'T *' cinit77  //CHECK: `-VarDecl {{.*}} i '__private int *__private' cinit78  T *i = in1;79  T ii;80  __private T *ptr = &ii;81  ptr = &in2;82  return *i;83}84 85__kernel void test() {86  int foo[10];87  xxx<__private int>(&foo[0], foo[0]);88  // FIXME: Template param deduction fails here because89  // temporaries are not in the __private address space.90  // It is probably reasonable to put them in __private91  // considering that stack and function params are92  // implicitly in __private.93  // However, if temporaries are left in default addr94  // space we should at least pretty print the __private95  // addr space. Otherwise diagnostic apprears to be96  // confusing.97  //xxx(&foo[0], foo[0]);98}99 100// Addr space for pointer/reference to an array101//CHECK: FunctionDecl {{.*}} t1 'void (const float (__generic &__private)[2])'102void t1(const float (&fYZ)[2]);103//CHECK: FunctionDecl {{.*}} t2 'void (const float (__generic *__private)[2])'104void t2(const float (*fYZ)[2]);105//CHECK: FunctionDecl {{.*}} t3 'void (float (((__generic *__private)))[2])'106void t3(float(((*fYZ)))[2]);107//CHECK: FunctionDecl {{.*}} t4 'void (float (((__generic *__generic *__private)))[2])'108void t4(float(((**fYZ)))[2]);109//CHECK: FunctionDecl {{.*}} t5 'void (float (__generic *(__generic *__private))[2])'110void t5(float (*(*fYZ))[2]);111 112__kernel void k() {113  __local float x[2];114  float(*p)[2];115  t1(x);116  t2(&x);117  t3(&x);118  t4(&p);119  t5(&p);120  long f1 = foo1<long>;121}122