Skip to content

Commit bfa18e0

Browse files
committed
Implement more diagnostic cases
1 parent bc84382 commit bfa18e0

File tree

4 files changed

+41
-19
lines changed

4 files changed

+41
-19
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ void Sema::checkSYCLDeviceFunction(SourceLocation Loc, FunctionDecl *Callee) {
4646
assert(Callee && "Callee may not be null.");
4747
FunctionDecl *Caller = dyn_cast<FunctionDecl>(getCurLexicalContext());
4848

49+
// Errors in unevaluated context don't need to be generated,
50+
// so we can safely skip them.
51+
if (isUnevaluatedContext())
52+
return;
53+
4954
// If the caller is known-emitted, mark the callee as known-emitted.
5055
// Otherwise, mark the call in our call graph so we can traverse it later.
5156
if (Caller && isKnownEmitted(*this, Caller))

clang/lib/Sema/SemaTemplateDeduction.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4712,6 +4712,9 @@ Sema::DeduceAutoType(TypeLoc Type, Expr *&Init, QualType &Result,
47124712
}
47134713
}
47144714

4715+
if (!Context.getTargetInfo().hasFloat128Type() &&
4716+
(Result->isFloat128Type()) && getLangOpts().SYCLIsDevice)
4717+
SYCLDiagIfDeviceCode(Loc, diag::err_type_unsupported) << "__float128";
47154718
return DAR_Succeeded;
47164719
}
47174720

clang/lib/Sema/SemaType.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,12 +1516,8 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) {
15161516
break;
15171517
case DeclSpec::TST_float128:
15181518
if (!S.Context.getTargetInfo().hasFloat128Type() &&
1519-
S.getLangOpts().SYCLIsDevice)
1520-
S.SYCLDiagIfDeviceCode(DS.getTypeSpecTypeLoc(),
1521-
diag::err_type_unsupported)
1522-
<< "__float128";
1523-
else if (!S.Context.getTargetInfo().hasFloat128Type() &&
1524-
!(S.getLangOpts().OpenMP && S.getLangOpts().OpenMPIsDevice))
1519+
!(S.getLangOpts().OpenMP && S.getLangOpts().OpenMPIsDevice) &&
1520+
!S.getLangOpts().SYCLIsDevice)
15251521
S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_unsupported)
15261522
<< "__float128";
15271523
Result = Context.Float128Ty;
@@ -3095,7 +3091,6 @@ static QualType GetDeclSpecTypeForDeclarator(TypeProcessingState &state,
30953091
if (DeducedType *Deduced = T->getContainedDeducedType()) {
30963092
AutoType *Auto = dyn_cast<AutoType>(Deduced);
30973093
int Error = -1;
3098-
30993094
// Is this a 'auto' or 'decltype(auto)' type (as opposed to __auto_type or
31003095
// class template argument deduction)?
31013096
bool IsCXXAutoType =
@@ -5441,6 +5436,11 @@ TypeSourceInfo *Sema::GetTypeForDeclarator(Declarator &D, Scope *S) {
54415436

54425437
TypeSourceInfo *ReturnTypeInfo = nullptr;
54435438
QualType T = GetDeclSpecTypeForDeclarator(state, ReturnTypeInfo);
5439+
if (!Context.getTargetInfo().hasFloat128Type() && (T->isFloat128Type()) &&
5440+
getLangOpts().SYCLIsDevice &&
5441+
D.getContext() != DeclaratorContext::TemplateArgContext)
5442+
SYCLDiagIfDeviceCode(D.getIdentifierLoc(), diag::err_type_unsupported)
5443+
<< "__float128";
54445444
if (D.isPrototypeContext() && getLangOpts().ObjCAutoRefCount)
54455445
inferARCWriteback(state, T);
54465446

@@ -5551,6 +5551,11 @@ TypeSourceInfo *Sema::GetTypeForDeclaratorCast(Declarator &D, QualType FromTy) {
55515551

55525552
TypeSourceInfo *ReturnTypeInfo = nullptr;
55535553
QualType declSpecTy = GetDeclSpecTypeForDeclarator(state, ReturnTypeInfo);
5554+
if (!Context.getTargetInfo().hasFloat128Type() &&
5555+
(declSpecTy->isFloat128Type()) && getLangOpts().SYCLIsDevice &&
5556+
D.getContext() != DeclaratorContext::TemplateParamContext)
5557+
SYCLDiagIfDeviceCode(D.getIdentifierLoc(), diag::err_type_unsupported)
5558+
<< "__float128";
55545559

55555560
if (getLangOpts().ObjC) {
55565561
Qualifiers::ObjCLifetime ownership = Context.getInnerObjCOwnership(FromTy);

clang/test/SemaSYCL/sycl-restrict.cpp

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,44 +30,53 @@ template<typename t> void foo2(){};
3030
// getCurLexicalContext() returns translation unit decl and we can diagnose only
3131
// inside function decls
3232
__float128 foo(__float128 P) {
33-
// expected-error@+1 {{__float128 is not supported on this target}}
34-
Z<__float128> A;
33+
34+
// TODO should this be diagnosed?
3535
bar(P);
36-
bar(A);
3736
// expected-error@+1 {{__float128 is not supported on this target}}
3837
__float128 B;
3938
bar(B);
40-
// expected-error@+1 {{__float128 is not supported on this target}}
41-
bar((__float128)0);
4239

43-
// TODO
44-
// NOT ANALYZED PROBLEM
40+
// expected-error@+1 2{{__float128 is not supported on this target}}
41+
auto D = bar((__float128)0);
4542
// expected-error@+1 {{__float128 is not supported on this target}}
43+
auto C = D;
44+
45+
// expected-error@+1 2{{__float128 is not supported on this target}}
46+
decltype(bar((__float128)0)) E = bar((__float128)0);
47+
4648
foo2<__float128>();
49+
Z<__float128> A;
4750
return P;
4851
}
4952

5053
void usage() {
5154
// expected-error@+1 {{__float128 is not supported on this target}}
5255
__float128 A;
53-
// expected-note@+1{{called by 'usage'}}
56+
// expected-note@+2{{called by 'usage'}}
57+
// expected-error@+1 {{__float128 is not supported on this target}}
5458
auto B = foo(A);
5559
int E = sizeof(__float128);
5660

57-
// NOT ANALYZED PROBLEM
61+
// expected-error@+1 {{__float128 is not supported on this target}}
5862
decltype(A) C;
63+
// expected-error@+1 {{__float128 is not supported on this target}}
5964
decltype(foo1()) D;
6065
}
6166

6267
template <typename Name, typename Func>
6368
__attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) {
64-
// expected-note@+1 2{{called by 'kernel_single_task}}
69+
// expected-note@+1 3{{called by 'kernel_single_task}}
6570
kernelFunc();
6671
}
6772

6873
int main() {
69-
// expected-note@+1 2{{called by 'operator()'}}
70-
kernel_single_task<class fake_kernel>([]() { usage(); });
74+
__float128 B = 1;
75+
// expected-note@+2 2{{called by 'operator()'}}
76+
kernel_single_task<class fake_kernel>([=]() {
77+
usage();
78+
// expected-error@+1 {{__float128 is not supported on this target}}
79+
auto C = B; });
7180
return 0;
7281
}
7382

0 commit comments

Comments
 (0)