[PATCH] D62584: [OpenCL][PR42033] Deducing addr space with template parameter types
Anastasia Stulova via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 2 07:47:09 PDT 2019
Anastasia updated this revision to Diff 207562.
Anastasia added a comment.
- Removed diagnostic for address space in return type in tree transforms
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D62584/new/
https://reviews.llvm.org/D62584
Files:
lib/Sema/SemaDecl.cpp
lib/Sema/SemaType.cpp
lib/Sema/TreeTransform.h
test/SemaOpenCLCXX/address-space-deduction.cl
test/SemaOpenCLCXX/address-space-templates.cl
Index: test/SemaOpenCLCXX/address-space-templates.cl
===================================================================
--- test/SemaOpenCLCXX/address-space-templates.cl
+++ test/SemaOpenCLCXX/address-space-templates.cl
@@ -3,7 +3,7 @@
template <typename T>
struct S {
T a; // expected-error{{field may not be qualified with an address space}}
- T f1(); // expected-error{{function type may not be qualified with an address space}}
+ T f1(); // we ignore address space on a return types.
void f2(T); // expected-error{{parameter may not be qualified with an address space}}
};
Index: test/SemaOpenCLCXX/address-space-deduction.cl
===================================================================
--- test/SemaOpenCLCXX/address-space-deduction.cl
+++ test/SemaOpenCLCXX/address-space-deduction.cl
@@ -24,3 +24,17 @@
alias_c1_ptr ptr = &y;
};
+template <class T>
+T xxx(T *in) {
+ // This pointer can't be deduced to generic because addr space
+ // will be taken from the template argument.
+ //CHECK: `-VarDecl {{.*}} i 'T *' cinit
+ T *i = in;
+ T ii;
+ return *i;
+}
+
+__kernel void test() {
+ int foo[10];
+ xxx(&foo[0]);
+}
Index: lib/Sema/TreeTransform.h
===================================================================
--- lib/Sema/TreeTransform.h
+++ lib/Sema/TreeTransform.h
@@ -5365,13 +5365,6 @@
if (ResultType.isNull())
return QualType();
- // Return type can not be qualified with an address space.
- if (ResultType.getAddressSpace() != LangAS::Default) {
- SemaRef.Diag(TL.getReturnLoc().getBeginLoc(),
- diag::err_attribute_address_function_type);
- return QualType();
- }
-
if (getDerived().TransformFunctionTypeParams(
TL.getBeginLoc(), TL.getParams(),
TL.getTypePtr()->param_type_begin(),
Index: lib/Sema/SemaType.cpp
===================================================================
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -7414,7 +7414,9 @@
(T->isVoidType() && !IsPointee) ||
// Do not deduce addr spaces for dependent types because they might end
// up instantiating to a type with an explicit address space qualifier.
- T->isDependentType() ||
+ // Expect for pointer or reference types because the addr space in
+ // template argument can only belong to a pointee.
+ (T->isDependentType() && !T->isPointerType() && !T->isReferenceType()) ||
// Do not deduce addr space of decltype because it will be taken from
// its argument.
T->isDecltypeType() ||
Index: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -7484,7 +7484,10 @@
return;
}
}
- } else if (T.getAddressSpace() != LangAS::opencl_private) {
+ } else if (T.getAddressSpace() != LangAS::opencl_private &&
+ // If we are parsing a template we didn't deduce an addr
+ // space yet.
+ T.getAddressSpace() != LangAS::Default) {
// Do not allow other address spaces on automatic variable.
Diag(NewVD->getLocation(), diag::err_as_qualified_auto_decl) << 1;
NewVD->setInvalidDecl();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62584.207562.patch
Type: text/x-patch
Size: 3279 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190702/3dcb2023/attachment-0001.bin>
More information about the cfe-commits
mailing list