8
8
// This implements Semantic Analysis for SYCL constructs.
9
9
// ===----------------------------------------------------------------------===//
10
10
11
+ #include " clang/Sema/SemaSYCL.h"
11
12
#include " clang/AST/Mangle.h"
12
13
#include " clang/Sema/Sema.h"
13
14
#include " clang/Sema/SemaDiagnostic.h"
@@ -18,28 +19,30 @@ using namespace clang;
18
19
// SYCL device specific diagnostics implementation
19
20
// -----------------------------------------------------------------------------
20
21
21
- Sema::SemaDiagnosticBuilder Sema::SYCLDiagIfDeviceCode (SourceLocation Loc,
22
+ SemaSYCL::SemaSYCL (Sema &S) : SemaBase(S) {}
23
+
24
+ Sema::SemaDiagnosticBuilder SemaSYCL::DiagIfDeviceCode (SourceLocation Loc,
22
25
unsigned DiagID) {
23
26
assert (getLangOpts ().SYCLIsDevice &&
24
27
" Should only be called during SYCL compilation" );
25
- FunctionDecl *FD = dyn_cast<FunctionDecl>(getCurLexicalContext ());
28
+ FunctionDecl *FD = dyn_cast<FunctionDecl>(SemaRef. getCurLexicalContext ());
26
29
SemaDiagnosticBuilder::Kind DiagKind = [this , FD] {
27
30
if (!FD)
28
31
return SemaDiagnosticBuilder::K_Nop;
29
- if (getEmissionStatus (FD) == Sema::FunctionEmissionStatus::Emitted)
32
+ if (SemaRef. getEmissionStatus (FD) == Sema::FunctionEmissionStatus::Emitted)
30
33
return SemaDiagnosticBuilder::K_ImmediateWithCallStack;
31
34
return SemaDiagnosticBuilder::K_Deferred;
32
35
}();
33
- return SemaDiagnosticBuilder (DiagKind, Loc, DiagID, FD, * this );
36
+ return SemaDiagnosticBuilder (DiagKind, Loc, DiagID, FD, SemaRef );
34
37
}
35
38
36
- static bool isZeroSizedArray (Sema &SemaRef , QualType Ty) {
37
- if (const auto *CAT = SemaRef .getASTContext ().getAsConstantArrayType (Ty))
39
+ static bool isZeroSizedArray (SemaSYCL &S , QualType Ty) {
40
+ if (const auto *CAT = S .getASTContext ().getAsConstantArrayType (Ty))
38
41
return CAT->isZeroSize ();
39
42
return false ;
40
43
}
41
44
42
- void Sema::deepTypeCheckForSYCLDevice (SourceLocation UsedAt,
45
+ void SemaSYCL::deepTypeCheckForDevice (SourceLocation UsedAt,
43
46
llvm::DenseSet<QualType> Visited,
44
47
ValueDecl *DeclToCheck) {
45
48
assert (getLangOpts ().SYCLIsDevice &&
@@ -51,18 +54,18 @@ void Sema::deepTypeCheckForSYCLDevice(SourceLocation UsedAt,
51
54
auto Check = [&](QualType TypeToCheck, const ValueDecl *D) {
52
55
bool ErrorFound = false ;
53
56
if (isZeroSizedArray (*this , TypeToCheck)) {
54
- SYCLDiagIfDeviceCode (UsedAt, diag::err_typecheck_zero_array_size) << 1 ;
57
+ DiagIfDeviceCode (UsedAt, diag::err_typecheck_zero_array_size) << 1 ;
55
58
ErrorFound = true ;
56
59
}
57
60
// Checks for other types can also be done here.
58
61
if (ErrorFound) {
59
62
if (NeedToEmitNotes) {
60
63
if (auto *FD = dyn_cast<FieldDecl>(D))
61
- SYCLDiagIfDeviceCode (FD->getLocation (),
62
- diag::note_illegal_field_declared_here)
64
+ DiagIfDeviceCode (FD->getLocation (),
65
+ diag::note_illegal_field_declared_here)
63
66
<< FD->getType ()->isPointerType () << FD->getType ();
64
67
else
65
- SYCLDiagIfDeviceCode (D->getLocation (), diag::note_declared_at);
68
+ DiagIfDeviceCode (D->getLocation (), diag::note_declared_at);
66
69
}
67
70
}
68
71
@@ -93,8 +96,8 @@ void Sema::deepTypeCheckForSYCLDevice(SourceLocation UsedAt,
93
96
auto EmitHistory = [&]() {
94
97
// The first element is always nullptr.
95
98
for (uint64_t Index = 1 ; Index < History.size (); ++Index) {
96
- SYCLDiagIfDeviceCode (History[Index]->getLocation (),
97
- diag::note_within_field_of_type)
99
+ DiagIfDeviceCode (History[Index]->getLocation (),
100
+ diag::note_within_field_of_type)
98
101
<< History[Index]->getType ();
99
102
}
100
103
};
@@ -130,3 +133,26 @@ void Sema::deepTypeCheckForSYCLDevice(SourceLocation UsedAt,
130
133
}
131
134
} while (!StackForRecursion.empty ());
132
135
}
136
+
137
+ ExprResult SemaSYCL::BuildUniqueStableNameExpr (SourceLocation OpLoc,
138
+ SourceLocation LParen,
139
+ SourceLocation RParen,
140
+ TypeSourceInfo *TSI) {
141
+ return SYCLUniqueStableNameExpr::Create (getASTContext (), OpLoc, LParen,
142
+ RParen, TSI);
143
+ }
144
+
145
+ ExprResult SemaSYCL::ActOnUniqueStableNameExpr (SourceLocation OpLoc,
146
+ SourceLocation LParen,
147
+ SourceLocation RParen,
148
+ ParsedType ParsedTy) {
149
+ TypeSourceInfo *TSI = nullptr ;
150
+ QualType Ty = SemaRef.GetTypeFromParser (ParsedTy, &TSI);
151
+
152
+ if (Ty.isNull ())
153
+ return ExprError ();
154
+ if (!TSI)
155
+ TSI = getASTContext ().getTrivialTypeSourceInfo (Ty, LParen);
156
+
157
+ return BuildUniqueStableNameExpr (OpLoc, LParen, RParen, TSI);
158
+ }
0 commit comments