Skip to content

Commit 710fe46

Browse files
authored
[SYCL] Account for target when checking types (#17036)
The patch makes querries to the TargetInfo to determine if builtin types are supported on the device side.
1 parent 474235e commit 710fe46

File tree

4 files changed

+32
-12
lines changed

4 files changed

+32
-12
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,11 @@ static void checkSYCLType(SemaSYCL &S, QualType Ty, SourceRange Loc,
430430
// inform the user of both, e.g. struct member usage vs declaration.
431431

432432
bool Emitting = false;
433+
ASTContext &Context = S.getASTContext();
433434

434435
//--- check types ---
436+
if (Ty->isDependentType())
437+
return;
435438

436439
// zero length arrays
437440
if (isZeroSizedArray(S, Ty)) {
@@ -450,13 +453,15 @@ static void checkSYCLType(SemaSYCL &S, QualType Ty, SourceRange Loc,
450453
while (Ty->isAnyPointerType() || Ty->isArrayType())
451454
Ty = QualType{Ty->getPointeeOrArrayElementType(), 0};
452455

453-
// __int128, __int128_t, __uint128_t, long double, __float128
454-
if (Ty->isSpecificBuiltinType(BuiltinType::Int128) ||
455-
Ty->isSpecificBuiltinType(BuiltinType::UInt128) ||
456-
Ty->isSpecificBuiltinType(BuiltinType::LongDouble) ||
457-
Ty->isSpecificBuiltinType(BuiltinType::BFloat16) ||
458-
(Ty->isSpecificBuiltinType(BuiltinType::Float128) &&
459-
!S.getASTContext().getTargetInfo().hasFloat128Type())) {
456+
if (((Ty->isFloat128Type() ||
457+
(Ty->isRealFloatingType() && Context.getTypeSize(Ty) == 128)) &&
458+
!Context.getTargetInfo().hasFloat128Type()) ||
459+
(Ty->isIntegerType() && Context.getTypeSize(Ty) == 128 &&
460+
!Context.getTargetInfo().hasInt128Type()) ||
461+
(Ty->isBFloat16Type() && !Context.getTargetInfo().hasBFloat16Type()) ||
462+
// FIXME: this should have a TI check, but support isn't properly reported
463+
// ...
464+
(Ty->isSpecificBuiltinType(BuiltinType::LongDouble))) {
460465
S.DiagIfDeviceCode(Loc.getBegin(), diag::err_type_unsupported)
461466
<< Ty.getUnqualifiedType().getCanonicalType();
462467
Emitting = true;

clang/test/SemaSYCL/accessor-type-diagnostics.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
// RUN: %clang_cc1 -triple spir64 -fsycl-is-device -verify \
1+
// RUN: %clang_cc1 -triple spir64 -fsycl-is-device -verify -verify=expected,all \
22
// RUN: -aux-triple x86_64-unknown-linux-gnu -fsyntax-only %s
3-
// RUN: %clang_cc1 -triple spir64 -fsycl-is-device -verify \
3+
// RUN: %clang_cc1 -triple spir64 -fsycl-is-device -verify=expected,all \
4+
// RUN: -aux-triple x86_64-pc-windows-msvc -fsyntax-only %s
5+
// RUN: %clang_cc1 -triple nvptx64 -fsycl-is-device -verify=all \
6+
// RUN: -aux-triple x86_64-unknown-linux-gnu -fsyntax-only %s
7+
// RUN: %clang_cc1 -triple nvptx64 -fsycl-is-device -verify=all \
48
// RUN: -aux-triple x86_64-pc-windows-msvc -fsyntax-only %s
59
//
610
// Ensure SYCL type restrictions are applied to accessors as well.
@@ -45,19 +49,19 @@ int main() {
4549
ok_acc.use();
4650

4751
// -- accessors using prohibited types
48-
// expected-error@+1 {{'__float128' is not supported on this target}}
52+
// all-error@+1 {{'__float128' is not supported on this target}}
4953
f128_acc.use();
5054
// expected-error@+1 {{'__int128' is not supported on this target}}
5155
i128_acc.use();
52-
// expected-error@+1 {{'long double' is not supported on this target}}
56+
// all-error@+1 {{'long double' is not supported on this target}}
5357
ld_acc.use();
5458

5559
// -- pointers, aliases, auto, typedef, decltype of prohibited type
5660
// expected-error@+1 {{'__int128' is not supported on this target}}
5761
i128Ptr_acc.use();
5862
// expected-error@+1 {{'unsigned __int128' is not supported on this target}}
5963
aliased_acc.use();
60-
// expected-error@+1 {{'__float128' is not supported on this target}}
64+
// all-error@+1 {{'__float128' is not supported on this target}}
6165
typedef_acc.use();
6266
// expected-error@+1 {{'__int128' is not supported on this target}}
6367
declty_acc.use();

clang/test/SemaSYCL/deferred-diagnostics-emit.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ class type_info;
1616
typedef __typeof__(sizeof(int)) size_t;
1717
} // namespace std
1818

19+
template<typename T>
20+
void Dep() {
21+
enum Mode { N, E, O, EO };
22+
Mode m = N;
23+
}
24+
1925
//variadic functions from SYCL kernels emit a deferred diagnostic
2026
void variadic(int, ...) {}
2127

clang/test/SemaSYCL/int128.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
// RUN: %clang_cc1 -triple spir64 -aux-triple x86_64-unknown-linux-gnu \
22
// RUN: -fsycl-is-device -internal-isystem %S/Inputs -sycl-std=2020 -verify -fsyntax-only %s
3+
// RUN: %clang_cc1 -triple nvptx64 -aux-triple x86_64-unknown-linux-gnu \
4+
// RUN: -fsycl-is-device -internal-isystem %S/Inputs -sycl-std=2020 -verify=supported -fsyntax-only %s
35

46
#include "sycl.hpp"
57

68
sycl::queue deviceQueue;
79

810
typedef __uint128_t BIGTY;
911

12+
// if type is supported, no diagnostics should be raised
13+
// supported-no-diagnostics
14+
1015
template <class T>
1116
class Z {
1217
public:

0 commit comments

Comments
 (0)