[PATCH] D64400: [OpenCL][PR42390] Deduce addr space for templ specialization

Phabricator via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 15 06:03:32 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL366063: [OpenCL] Deduce addr space for pointee of dependent types in instantiation. (authored by stulova, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D64400?vs=209205&id=209831#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64400/new/

https://reviews.llvm.org/D64400

Files:
  cfe/trunk/lib/Sema/TreeTransform.h
  cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl


Index: cfe/trunk/lib/Sema/TreeTransform.h
===================================================================
--- cfe/trunk/lib/Sema/TreeTransform.h
+++ cfe/trunk/lib/Sema/TreeTransform.h
@@ -4536,6 +4536,14 @@
   return Result;
 }
 
+/// Helper to deduce addr space of a pointee type in OpenCL mode.
+/// If the type is updated it will be overwritten in PointeeType param.
+static void deduceOpenCLPointeeAddrSpace(Sema &SemaRef, QualType &PointeeType) {
+  if (PointeeType.getAddressSpace() == LangAS::Default)
+    PointeeType = SemaRef.Context.getAddrSpaceQualType(PointeeType,
+                                                       LangAS::opencl_generic);
+}
+
 template<typename Derived>
 QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
                                                       PointerTypeLoc TL) {
@@ -4544,6 +4552,9 @@
   if (PointeeType.isNull())
     return QualType();
 
+  if (SemaRef.getLangOpts().OpenCL)
+    deduceOpenCLPointeeAddrSpace(SemaRef, PointeeType);
+
   QualType Result = TL.getType();
   if (PointeeType->getAs<ObjCObjectType>()) {
     // A dependent pointer type 'T *' has is being transformed such
@@ -4582,6 +4593,9 @@
   if (PointeeType.isNull())
     return QualType();
 
+  if (SemaRef.getLangOpts().OpenCL)
+    deduceOpenCLPointeeAddrSpace(SemaRef, PointeeType);
+
   QualType Result = TL.getType();
   if (getDerived().AlwaysRebuild() ||
       PointeeType != TL.getPointeeLoc().getType()) {
@@ -4611,6 +4625,9 @@
   if (PointeeType.isNull())
     return QualType();
 
+  if (SemaRef.getLangOpts().OpenCL)
+    deduceOpenCLPointeeAddrSpace(SemaRef, PointeeType);
+
   QualType Result = TL.getType();
   if (getDerived().AlwaysRebuild() ||
       PointeeType != T->getPointeeTypeAsWritten()) {
Index: cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl
===================================================================
--- cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl
+++ cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl
@@ -24,3 +24,42 @@
   alias_c1_ptr ptr = &y;
 };
 
+
+// Addr spaces for pointee of dependent types are not deduced
+// during parsing but during template instantiation instead.
+
+template <class T>
+struct x1 {
+//CHECK: -CXXMethodDecl {{.*}} operator= 'x1<T> &(const x1<T> &) __generic'
+//CHECK: -CXXMethodDecl {{.*}} operator= '__generic x1<int> &(const __generic x1<int> &) __generic'
+  x1<T>& operator=(const x1<T>& xx) {
+    y = xx.y;
+    return *this;
+  }
+  int y;
+};
+
+template <class T>
+struct x2 {
+//CHECK: -CXXMethodDecl {{.*}} foo 'void (x1<T> *) __generic'
+//CHECK: -CXXMethodDecl {{.*}} foo 'void (__generic x1<int> *) __generic'
+  void foo(x1<T>* xx) {
+    m[0] = *xx;
+  }
+//CHECK: -FieldDecl {{.*}}  m 'x1<int> [2]'
+  x1<T> m[2];
+};
+
+void bar(__global x1<int> *xx, __global x2<int> *bar) {
+  bar->foo(xx);
+}
+
+template <typename T>
+class x3 : public T {
+public:
+  //CHECK: -CXXConstructorDecl {{.*}} x3<T> 'void (const x3<T> &) __generic'
+  x3(const x3 &t);
+};
+//CHECK: -CXXConstructorDecl {{.*}} x3<T> 'void (const x3<T> &) __generic'
+template <typename T>
+x3<T>::x3(const x3<T> &t) {}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64400.209831.patch
Type: text/x-patch
Size: 3159 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190715/6cbee063/attachment.bin>


More information about the cfe-commits mailing list