Skip to content

[SYCL] Fix address space assertion with templates #2798

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clang/include/clang/AST/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,8 @@ class Qualifiers {
| (((uint32_t) space) << AddressSpaceShift);
}
void removeAddressSpace() { setAddressSpace(LangAS::Default); }
void addAddressSpace(LangAS space) {
assert(space != LangAS::Default);
void addAddressSpace(LangAS space, bool AllowDefaultAddrSpace = false) {
assert(space != LangAS::Default || AllowDefaultAddrSpace);
setAddressSpace(space);
}

Expand Down
3 changes: 2 additions & 1 deletion clang/lib/Sema/SemaInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4897,7 +4897,8 @@ static void TryReferenceInitializationCore(Sema &S,
// Add addr space conversion if required.
if (T1Quals.getAddressSpace() != T2Quals.getAddressSpace()) {
auto T4Quals = cv1T4.getQualifiers();
T4Quals.addAddressSpace(T1Quals.getAddressSpace());
T4Quals.addAddressSpace(T1Quals.getAddressSpace(),
S.getLangOpts().SYCLIsDevice);
QualType cv1T4WithAS = S.Context.getQualifiedType(T2, T4Quals);
Sequence.AddQualificationConversionStep(cv1T4WithAS, ValueKind);
cv1T4 = cv1T4WithAS;
Expand Down
52 changes: 52 additions & 0 deletions clang/test/SemaSYCL/sycl-templ-addr-space.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// RUN: %clang_cc1 -fsycl -fsycl-is-device -triple spir64 -verify %s

// Test that the compiler no longer asserts while processing this test case.

template <int N>
struct integral_constant {
static constexpr int val = N;
};
template <typename T>
T &&convert(int);
template <typename T>
auto declval(convert<T>(0));
template <typename Op1, typename Op2>
class sub_group {
template <typename T, decltype(declval<T>)>
// expected-note@+1 {{possible target for call}}
static integral_constant<true> binary_op();
// expected-error@+1 {{reference to overloaded function could not be resolved; did you mean to call it?}}
decltype(binary_op<Op1, Op2>) i;
};
// expected-note-re@+2 {{in instantiation {{.*}} requested here}}
template <typename n>
struct group : sub_group<n, int> {
};
template <typename T>
struct wrapper {
typedef T val;
};
class element_type {
};
struct Container {
using __element_type = __attribute__((opencl_global)) element_type;
};
template <bool, class Base, class> using BaseImpl = Base;
// expected-note-re@+1 2{{candidate constructor {{.*}} not viable: {{.*}}}}
template <int> class id_type {
template <class...> struct Base;
// expected-note-re@+1 {{in instantiation {{.*}} requested here}}
template <class Der> struct Base<Der> : BaseImpl<Der::val, Base<>, Der> {};
// expected-note-re@+1 {{in instantiation {{.*}} requested here}}
template <typename T> using Base2 = wrapper<typename Base<group<T>>::val>;
// expected-note-re@+3 {{in instantiation {{.*}} requested here}}
// expected-note-re@+2 {{in instantiation {{.*}} required here}}
// expected-note-re@+1 {{candidate template ignored: {{.*}}}}
template <typename T, typename = Base2<T>> id_type(T &);
};
id_type<1> get() {
Container::__element_type *ElemPtr;
// expected-error@+2 {{no viable conversion from returned value of type 'Container::__element_type' (aka '__global element_type') to function return type 'id_type<1>'}}
// expected-note-re@+1 {{while substituting {{.*}}}}
return ElemPtr[0];
}