31 "Should only be called during SYCL compilation");
33 SemaDiagnosticBuilder::Kind DiagKind = [
this, FD] {
35 return SemaDiagnosticBuilder::K_Nop;
37 return SemaDiagnosticBuilder::K_ImmediateWithCallStack;
38 return SemaDiagnosticBuilder::K_Deferred;
45 return CAT->isZeroSize();
50 llvm::DenseSet<QualType>
Visited,
53 "Should only be called during SYCL compilation");
56 bool NeedToEmitNotes =
true;
59 bool ErrorFound =
false;
66 if (NeedToEmitNotes) {
67 if (
auto *FD = dyn_cast<FieldDecl>(
D))
69 diag::note_illegal_field_declared_here)
70 << FD->getType()->isPointerType() << FD->getType();
81 StackForRecursion.push_back(DeclToCheck);
85 History.push_back(
nullptr);
88 const ValueDecl *Next = StackForRecursion.pop_back_val();
90 assert(!History.empty());
97 if (!
Visited.insert(NextTy).second)
100 auto EmitHistory = [&]() {
102 for (uint64_t Index = 1; Index < History.size(); ++Index) {
104 diag::note_within_field_of_type)
105 << History[Index]->getType();
109 if (Check(NextTy, Next)) {
112 NeedToEmitNotes =
false;
123 if (Check(NextTy, Next)) {
126 NeedToEmitNotes =
false;
131 if (
auto *NextFD = dyn_cast<FieldDecl>(Next))
132 History.push_back(NextFD);
135 StackForRecursion.push_back(
nullptr);
136 llvm::copy(RecDecl->fields(), std::back_inserter(StackForRecursion));
138 }
while (!StackForRecursion.empty());
166 const auto *FD = cast<FunctionDecl>(
D);
168 assert(FT &&
"Function template is expected");
172 if (TL->
size() < 2) {
173 Diag(FT->
getLocation(), diag::warn_sycl_kernel_num_of_template_params);
178 for (
unsigned I = 0; I < 2; ++I) {
180 if (isa<NonTypeTemplateParmDecl>(TParam)) {
182 diag::warn_sycl_kernel_invalid_template_param_type);
189 Diag(FT->
getLocation(), diag::warn_sycl_kernel_num_of_function_params);
200 handleSimpleAttribute<SYCLKernelAttr>(*
this,
D, AL);
207 assert(TSI &&
"no type source info for attribute argument");
221 if (
const TagType *TT = dyn_cast<TagType>(
T))
222 Loc = TT->getDecl()->getLocation();
224 Loc = ObjCIT->getDecl()->getLocation();
241 S.
Diag(
Loc, diag::warn_sycl_kernel_name_not_a_class_type) << KernelName;
244 S.
Diag(DeclTypeLoc, diag::note_entity_declared_at) << KernelName;
254 SYCLKernelEntryPointAttr *SKEPAttr =
nullptr;
255 for (
auto *SAI : FD->
specific_attrs<SYCLKernelEntryPointAttr>()) {
261 SKEPAttr->getKernelName())) {
262 Diag(SAI->getLocation(), diag::err_sycl_entry_point_invalid_redeclaration)
263 << SAI->getKernelName() << SKEPAttr->getKernelName();
264 Diag(SKEPAttr->getLocation(), diag::note_previous_attribute);
265 SAI->setInvalidAttr();
267 Diag(SAI->getLocation(),
268 diag::warn_sycl_entry_point_redundant_declaration);
269 Diag(SKEPAttr->getLocation(), diag::note_previous_attribute);
272 assert(SKEPAttr &&
"Missing sycl_kernel_entry_point attribute");
275 if (!SKEPAttr->getKernelName()->isDependentType() &&
277 SKEPAttr->getKernelName()))
278 SKEPAttr->setInvalidAttr();
284 const auto *PrevSKEPAttr = PrevFD->
getAttr<SYCLKernelEntryPointAttr>();
285 if (PrevSKEPAttr && !PrevSKEPAttr->isInvalidAttr()) {
287 PrevSKEPAttr->getKernelName())) {
288 Diag(SKEPAttr->getLocation(),
289 diag::err_sycl_entry_point_invalid_redeclaration)
290 << SKEPAttr->getKernelName() << PrevSKEPAttr->getKernelName();
291 Diag(PrevSKEPAttr->getLocation(), diag::note_previous_decl) << PrevFD;
292 SKEPAttr->setInvalidAttr();
297 if (
const auto *MD = dyn_cast<CXXMethodDecl>(FD)) {
298 if (!MD->isStatic()) {
299 Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
301 SKEPAttr->setInvalidAttr();
306 Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
308 SKEPAttr->setInvalidAttr();
312 Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
314 SKEPAttr->setInvalidAttr();
316 Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
318 SKEPAttr->setInvalidAttr();
322 Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
324 SKEPAttr->setInvalidAttr();
326 Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
328 SKEPAttr->setInvalidAttr();
332 Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
334 SKEPAttr->setInvalidAttr();
338 Diag(SKEPAttr->getLocation(),
339 diag::err_sycl_entry_point_deduced_return_type);
340 SKEPAttr->setInvalidAttr();
343 Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_return_type);
344 SKEPAttr->setInvalidAttr();
348 !SKEPAttr->isInvalidAttr()) {
357 diag::note_previous_declaration);
358 SKEPAttr->setInvalidAttr();
Defines the Diagnostic-related interfaces.
llvm::DenseSet< const void * > Visited
This file declares types used to describe SYCL kernels.
static SourceLocation SourceLocationForUserDeclaredType(QualType QT)
static bool isZeroSizedArray(SemaSYCL &S, QualType Ty)
static bool CheckSYCLKernelName(Sema &S, SourceLocation Loc, QualType KernelName)
This file declares semantic analysis for SYCL constructs.
Allows QualTypes to be sorted and hence used in maps and sets.
const ConstantArrayType * getAsConstantArrayType(QualType T) const
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location,...
void registerSYCLEntryPointFunction(FunctionDecl *FD)
Generates and stores SYCL kernel metadata for the provided SYCL kernel entry point function.
const SYCLKernelInfo * findSYCLKernelInfo(QualType T) const
Returns a pointer to the metadata generated from the corresponding SYCLkernel entry point if the prov...
Decl - This represents one declaration (or definition), e.g.
bool isTemplated() const
Determine whether this declaration is a templated entity (whether it is.
bool isInvalidDecl() const
llvm::iterator_range< specific_attr_iterator< T > > specific_attrs() const
SourceLocation getLocation() const
Represents a function declaration or definition.
bool isNoReturn() const
Determines whether this function is known to be 'noreturn', through an attribute on its declaration o...
QualType getReturnType() const
bool isVariadic() const
Whether this function is variadic.
bool isDeleted() const
Whether this function has been deleted.
bool isConstexpr() const
Whether this is a (C++11) constexpr function or constexpr constructor.
bool isDefaulted() const
Whether this function is defaulted.
Declaration of a template function.
This represents a decl that may have a name.
Interfaces are the core concept in Objective-C for object oriented design.
ParsedAttr - Represents a syntactic attribute.
const ParsedType & getTypeArg() const
A (possibly-)qualified type.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
decl_type * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
const FunctionDecl * getKernelEntryPointDecl() const
static SYCLUniqueStableNameExpr * Create(const ASTContext &Ctx, SourceLocation OpLoc, SourceLocation LParen, SourceLocation RParen, TypeSourceInfo *TSI)
A generic diagnostic builder for errors which may or may not be deferred.
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
ASTContext & getASTContext() const
const LangOptions & getLangOpts() const
SemaDiagnosticBuilder DiagIfDeviceCode(SourceLocation Loc, unsigned DiagID)
Creates a SemaDiagnosticBuilder that emits the diagnostic if the current context is "used as device c...
ExprResult BuildUniqueStableNameExpr(SourceLocation OpLoc, SourceLocation LParen, SourceLocation RParen, TypeSourceInfo *TSI)
void handleKernelEntryPointAttr(Decl *D, const ParsedAttr &AL)
void deepTypeCheckForDevice(SourceLocation UsedAt, llvm::DenseSet< QualType > Visited, ValueDecl *DeclToCheck)
void handleKernelAttr(Decl *D, const ParsedAttr &AL)
void CheckSYCLEntryPointFunctionDecl(FunctionDecl *FD)
ExprResult ActOnUniqueStableNameExpr(SourceLocation OpLoc, SourceLocation LParen, SourceLocation RParen, ParsedType ParsedTy)
Sema - This implements semantic analysis and AST building for C.
ASTContext & getASTContext() const
DeclContext * getCurLexicalContext() const
FunctionEmissionStatus getEmissionStatus(const FunctionDecl *Decl, bool Final=false)
static QualType GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo=nullptr)
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Stores a list of template parameters for a TemplateDecl and its derived classes.
NamedDecl * getParam(unsigned Idx)
A container of type source information.
The base class of the type hierarchy.
bool isReferenceType() const
const Type * getArrayElementTypeNoTypeQual() const
If this is an array type, return the element type of the array, potentially with type qualifiers miss...
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
bool isUndeducedType() const
Determine whether this type is an undeduced type, meaning that it somehow involves a C++11 'auto' typ...
bool isStructureOrClassType() const
bool isAnyPointerType() const
const Type * getUnqualifiedDesugaredType() const
Return the specified type with any "sugar" removed from the type, removing any typedefs,...
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
The JSON file list parser is used to communicate input to InstallAPI.
QualType getFunctionOrMethodResultType(const Decl *D)
const FunctionProtoType * T
unsigned getFunctionOrMethodNumParams(const Decl *D)
getFunctionOrMethodNumParams - Return number of function or method parameters.
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.