Skip to content

Commit 92fa91b

Browse files
author
Anastasia Stulova
committed
[OpenCL] Fixed missing address space for templated copy constructor.
Added missing address space for the parameter of copy ctor created for templated constructor with an R-value reference. Patch by Ole Strohm (olestrohm)! Tags: #clang Differential Revision: https://reviews.llvm.org/D83665
1 parent 1b4d249 commit 92fa91b

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

clang/lib/Sema/SemaTemplateDeduction.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3815,8 +3815,11 @@ static bool AdjustFunctionParmAndArgTypesForDeduction(
38153815
// If P is a forwarding reference and the argument is an lvalue, the type
38163816
// "lvalue reference to A" is used in place of A for type deduction.
38173817
if (isForwardingReference(QualType(ParamRefType, 0), FirstInnerIndex) &&
3818-
Arg->isLValue())
3818+
Arg->isLValue()) {
3819+
if (S.getLangOpts().OpenCL)
3820+
ArgType = S.Context.getAddrSpaceQualType(ArgType, LangAS::opencl_generic);
38193821
ArgType = S.Context.getLValueReferenceType(ArgType);
3822+
}
38203823
} else {
38213824
// C++ [temp.deduct.call]p2:
38223825
// If P is not a reference type:

clang/test/SemaOpenCLCXX/address-space-templates.cl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,28 @@ void foo3() {
2222
__private T ii; // expected-error{{conflicting address space qualifiers are provided between types '__private T' and '__global int'}}
2323
}
2424

25+
template <class _Tp> struct remove_reference { typedef _Tp type; };
26+
template <class _Tp> struct remove_reference<_Tp &> { typedef _Tp type; };
27+
template <class _Tp> struct as_pointer {
28+
typedef typename remove_reference<_Tp>::type* type;
29+
};
30+
31+
struct rep {
32+
// CHECK |-CXXConstructorDecl {{.*}} rep 'void (const __generic rep &__private) __generic'
33+
template<class U, class = typename as_pointer<U>::type>
34+
rep(U&& v) {}
35+
};
36+
37+
struct rep_outer : private rep {
38+
rep_outer()
39+
: rep(0) {}
40+
};
41+
2542
void bar() {
2643
S<const __global int> sintgl; // expected-note{{in instantiation of template class 'S<const __global int>' requested here}}
2744

2845
foo1<__local int>(1); // expected-error{{no matching function for call to 'foo1'}}
2946
foo2<__global int>(0);
3047
foo3<__global int>(); // expected-note{{in instantiation of function template specialization 'foo3<__global int>' requested here}}
48+
rep_outer r;
3149
}

0 commit comments

Comments
 (0)