88// This implements Semantic Analysis for SYCL constructs.
99// ===----------------------------------------------------------------------===//
1010
11+ #include " clang/Sema/SemaSYCL.h"
1112#include " clang/AST/Mangle.h"
1213#include " clang/Sema/Sema.h"
1314#include " clang/Sema/SemaDiagnostic.h"
@@ -18,28 +19,30 @@ using namespace clang;
1819// SYCL device specific diagnostics implementation
1920// -----------------------------------------------------------------------------
2021
21- Sema::SemaDiagnosticBuilder Sema::SYCLDiagIfDeviceCode (SourceLocation Loc,
22+ SemaSYCL::SemaSYCL (Sema &S) : SemaBase(S) {}
23+
24+ Sema::SemaDiagnosticBuilder SemaSYCL::DiagIfDeviceCode (SourceLocation Loc,
2225 unsigned DiagID) {
2326 assert (getLangOpts ().SYCLIsDevice &&
2427 " Should only be called during SYCL compilation" );
25- FunctionDecl *FD = dyn_cast<FunctionDecl>(getCurLexicalContext ());
28+ FunctionDecl *FD = dyn_cast<FunctionDecl>(SemaRef. getCurLexicalContext ());
2629 SemaDiagnosticBuilder::Kind DiagKind = [this , FD] {
2730 if (!FD)
2831 return SemaDiagnosticBuilder::K_Nop;
29- if (getEmissionStatus (FD) == Sema::FunctionEmissionStatus::Emitted)
32+ if (SemaRef. getEmissionStatus (FD) == Sema::FunctionEmissionStatus::Emitted)
3033 return SemaDiagnosticBuilder::K_ImmediateWithCallStack;
3134 return SemaDiagnosticBuilder::K_Deferred;
3235 }();
33- return SemaDiagnosticBuilder (DiagKind, Loc, DiagID, FD, * this );
36+ return SemaDiagnosticBuilder (DiagKind, Loc, DiagID, FD, SemaRef );
3437}
3538
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))
3841 return CAT->isZeroSize ();
3942 return false ;
4043}
4144
42- void Sema::deepTypeCheckForSYCLDevice (SourceLocation UsedAt,
45+ void SemaSYCL::deepTypeCheckForDevice (SourceLocation UsedAt,
4346 llvm::DenseSet<QualType> Visited,
4447 ValueDecl *DeclToCheck) {
4548 assert (getLangOpts ().SYCLIsDevice &&
@@ -51,18 +54,18 @@ void Sema::deepTypeCheckForSYCLDevice(SourceLocation UsedAt,
5154 auto Check = [&](QualType TypeToCheck, const ValueDecl *D) {
5255 bool ErrorFound = false ;
5356 if (isZeroSizedArray (*this , TypeToCheck)) {
54- SYCLDiagIfDeviceCode (UsedAt, diag::err_typecheck_zero_array_size) << 1 ;
57+ DiagIfDeviceCode (UsedAt, diag::err_typecheck_zero_array_size) << 1 ;
5558 ErrorFound = true ;
5659 }
5760 // Checks for other types can also be done here.
5861 if (ErrorFound) {
5962 if (NeedToEmitNotes) {
6063 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)
6366 << FD->getType ()->isPointerType () << FD->getType ();
6467 else
65- SYCLDiagIfDeviceCode (D->getLocation (), diag::note_declared_at);
68+ DiagIfDeviceCode (D->getLocation (), diag::note_declared_at);
6669 }
6770 }
6871
@@ -93,8 +96,8 @@ void Sema::deepTypeCheckForSYCLDevice(SourceLocation UsedAt,
9396 auto EmitHistory = [&]() {
9497 // The first element is always nullptr.
9598 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)
98101 << History[Index]->getType ();
99102 }
100103 };
@@ -130,3 +133,26 @@ void Sema::deepTypeCheckForSYCLDevice(SourceLocation UsedAt,
130133 }
131134 } while (!StackForRecursion.empty ());
132135}
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