Skip to content

Commit 62f841d

Browse files
[SYCL] Add diagnostics for long double in device code (#1512)
It was decided to issue an error whenever 'long double' is used in device code. Regardless, of whether the underlying representation is 64-bit or 80-bit. Signed-off-by: Chris Perkins <[email protected]>
1 parent e88a611 commit 62f841d

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,10 @@ static void checkSYCLVarType(Sema &S, QualType Ty, SourceRange Loc,
244244
while (Ty->isAnyPointerType() || Ty->isArrayType())
245245
Ty = QualType{Ty->getPointeeOrArrayElementType(), 0};
246246

247-
// __int128, __int128_t, __uint128_t, __float128
247+
// __int128, __int128_t, __uint128_t, long double, __float128
248248
if (Ty->isSpecificBuiltinType(BuiltinType::Int128) ||
249249
Ty->isSpecificBuiltinType(BuiltinType::UInt128) ||
250+
Ty->isSpecificBuiltinType(BuiltinType::LongDouble) ||
250251
(Ty->isSpecificBuiltinType(BuiltinType::Float128) &&
251252
!S.Context.getTargetInfo().hasFloat128Type()))
252253
emitDeferredDiagnosticAndNote(S, Loc, diag::err_type_unsupported, UsedAtLoc)

clang/test/SemaSYCL/sycl-restrict.cpp

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ using myFuncDef = int(int, int);
112112

113113
// defines (early and late)
114114
#define floatDef __float128
115+
#define longdoubleDef long double
115116
#define int128Def __int128
116117
#define int128tDef __int128_t
117118
#define intDef int
@@ -120,6 +121,7 @@ using myFuncDef = int(int, int);
120121
typedef __uint128_t megeType;
121122
typedef __float128 trickyFloatType;
122123
typedef __int128 tricky128Type;
124+
typedef long double trickyLDType;
123125

124126
//templated return type
125127
template <typename T>
@@ -137,6 +139,10 @@ using floatalias_t = __float128;
137139
template <typename...>
138140
using int128alias_t = __int128;
139141

142+
//alias template
143+
template <typename...>
144+
using ldalias_t = long double;
145+
140146
//false positive. early incorrectly catches
141147
template <typename t>
142148
void foo(){};
@@ -152,6 +158,8 @@ struct frankenStruct {
152158
__float128 scaryQuad;
153159
// expected-error@+1 {{'__int128' is not supported on this target}}
154160
__int128 frightenInt;
161+
// expected-error@+1 {{'long double' is not supported on this target}}
162+
long double terrorLD;
155163
};
156164

157165
//struct
@@ -160,6 +168,8 @@ struct trickyStruct {
160168
trickyFloatType trickySructQuad;
161169
// expected-error@+1 {{'__int128' is not supported on this target}}
162170
tricky128Type trickyStructInt;
171+
// expected-error@+1 {{'long double' is not supported on this target}}
172+
trickyLDType trickyStructLD;
163173
};
164174

165175
// function return type and argument both unsupported
@@ -229,6 +239,32 @@ void usage(myFuncDef functionPtr) {
229239
foo<__float128>();
230240
safealias_t<__float128> notAFloat = 3;
231241

242+
// ======= long double Not Allowed in Kernel ==========
243+
// expected-error@+1 {{'long double' is not supported on this target}}
244+
long double malLD = 50;
245+
// expected-error@+1 {{'long double' is not supported on this target}}
246+
trickyLDType malLDTrick = 51;
247+
// expected-error@+1 {{'long double' is not supported on this target}}
248+
longdoubleDef malLDDef = 52;
249+
// expected-error@+1 {{'long double' is not supported on this target}}
250+
auto whatLD = malLD;
251+
// expected-error@+1 {{'long double' is not supported on this target}}
252+
auto malAutoLD = bar<long double>();
253+
// expected-error@+1 {{'long double' is not supported on this target}}
254+
auto malAutoLD2 = bar<trickyLDType>();
255+
// expected-error@+1 {{'long double' is not supported on this target}}
256+
decltype(malLD) malDeclLD = 53;
257+
// expected-error@+1 {{'long double' is not supported on this target}}
258+
auto malLDTemplateVar = solutionToEverything<long double>;
259+
// expected-error@+1 {{'long double' is not supported on this target}}
260+
auto malTrifectaLD = solutionToEverything<trickyLDType>;
261+
// expected-error@+1 {{'long double' is not supported on this target}}
262+
ldalias_t<void> aliasedLongDouble = 54;
263+
// ---- false positive tests
264+
std::size_t someLDSz = sizeof(long double);
265+
foo<long double>();
266+
safealias_t<long double> notALD = 55;
267+
232268
// ======= Zero Length Arrays Not Allowed in Kernel ==========
233269
// expected-error@+1 {{zero-length arrays are not permitted in C++}}
234270
int MalArray[0];
@@ -282,8 +318,8 @@ void usage(myFuncDef functionPtr) {
282318
auto malTrifectaInt128T = solutionToEverything<megeType>;
283319

284320
// ======= Struct Members Checked =======
285-
frankenStruct strikesFear; // expected-note 3{{used here}}
286-
trickyStruct incitesPanic; // expected-note 2{{used here}}
321+
frankenStruct strikesFear; // expected-note 4{{used here}}
322+
trickyStruct incitesPanic; // expected-note 3{{used here}}
287323

288324
// ======= Function Prototype Checked =======
289325
// expected-error@+1 2{{'__int128' is not supported on this target}}

0 commit comments

Comments
 (0)