33 "Device diagnostics Should only be issued during device compilation");
34 SemaDiagnosticBuilder::Kind DiagKind = SemaDiagnosticBuilder::K_Nop;
40 DiagKind = SemaDiagnosticBuilder::K_ImmediateWithCallStack;
44 DiagKind = SemaDiagnosticBuilder::K_Deferred;
47 llvm_unreachable(
"OMPDiscarded unexpected in SYCL device compilation");
49 llvm_unreachable(
"CUDADiscarded unexpected in SYCL device compilation");
57 return CAT->isZeroSize();
62 llvm::DenseSet<QualType> Visited,
65 "Should only be called during SYCL compilation");
68 bool NeedToEmitNotes =
true;
71 bool ErrorFound =
false;
78 if (NeedToEmitNotes) {
79 if (
auto *FD = dyn_cast<FieldDecl>(D))
81 diag::note_illegal_field_declared_here)
82 << FD->getType()->isPointerType() << FD->getType();
93 StackForRecursion.push_back(DeclToCheck);
97 History.push_back(
nullptr);
102 assert(!History.empty());
109 if (!Visited.insert(NextTy).second)
112 auto EmitHistory = [&]() {
114 for (uint64_t Index = 1; Index < History.size(); ++Index) {
116 diag::note_within_field_of_type)
117 << History[Index]->getType();
121 if (Check(NextTy,
Next)) {
124 NeedToEmitNotes =
false;
135 if (Check(NextTy,
Next)) {
138 NeedToEmitNotes =
false;
143 if (
auto *NextFD = dyn_cast<FieldDecl>(
Next))
144 History.push_back(NextFD);
147 StackForRecursion.push_back(
nullptr);
148 llvm::append_range(StackForRecursion, RecDecl->fields());
150 }
while (!StackForRecursion.empty());
180 assert(FT &&
"Function template is expected");
184 if (TL->
size() < 2) {
185 Diag(FT->
getLocation(), diag::warn_sycl_kernel_num_of_template_params);
190 for (
unsigned I = 0; I < 2; ++I) {
194 diag::warn_sycl_kernel_invalid_template_param_type);
201 Diag(FT->
getLocation(), diag::warn_sycl_kernel_num_of_function_params);
218 (void)
SemaRef.GetTypeFromParser(PT, &TSI);
219 assert(TSI &&
"no type source info for attribute argument");
221 SYCLKernelEntryPointAttr(
SemaRef.Context, AL, TSI));
226 "Should only be called during SYCL device compilation");
231 if (
const auto *SKEPAttr = FD->getAttr<SYCLKernelEntryPointAttr>()) {
232 if (
SemaRef.currentEvaluationContext().isPotentiallyEvaluated()) {
250 if (
const TagType *TT = dyn_cast<TagType>(T))
251 Loc = TT->getDecl()->getLocation();
252 else if (
const auto *ObjCIT = dyn_cast<ObjCInterfaceType>(T))
253 Loc = ObjCIT->getDecl()->getLocation();
270 S.
Diag(Loc, diag::warn_sycl_kernel_name_not_a_class_type) << KernelName;
273 S.
Diag(DeclTypeLoc, diag::note_entity_declared_at) << KernelName;
281 const auto *SEAttr = FD->
getAttr<SYCLExternalAttr>();
282 assert(SEAttr &&
"Missing sycl_external attribute");
287 Diag(SEAttr->getLocation(), diag::err_sycl_external_invalid_linkage)
291 Diag(SEAttr->getLocation(),
292 diag::err_sycl_external_invalid_deleted_function)
300 SYCLKernelEntryPointAttr *SKEPAttr =
nullptr;
301 for (
auto *SAI : FD->
specific_attrs<SYCLKernelEntryPointAttr>()) {
307 SKEPAttr->getKernelName())) {
308 Diag(SAI->getLocation(), diag::err_sycl_entry_point_invalid_redeclaration)
309 << SKEPAttr << SAI->getKernelName() << SKEPAttr->getKernelName();
310 Diag(SKEPAttr->getLocation(), diag::note_previous_attribute);
311 SAI->setInvalidAttr();
313 Diag(SAI->getLocation(),
314 diag::warn_sycl_entry_point_redundant_declaration)
316 Diag(SKEPAttr->getLocation(), diag::note_previous_attribute);
319 assert(SKEPAttr &&
"Missing sycl_kernel_entry_point attribute");
322 if (!SKEPAttr->getKernelName()->isDependentType() &&
324 SKEPAttr->getKernelName()))
325 SKEPAttr->setInvalidAttr();
331 const auto *PrevSKEPAttr = PrevFD->
getAttr<SYCLKernelEntryPointAttr>();
332 if (PrevSKEPAttr && !PrevSKEPAttr->isInvalidAttr()) {
334 PrevSKEPAttr->getKernelName())) {
335 Diag(SKEPAttr->getLocation(),
336 diag::err_sycl_entry_point_invalid_redeclaration)
337 << SKEPAttr << SKEPAttr->getKernelName()
338 << PrevSKEPAttr->getKernelName();
339 Diag(PrevSKEPAttr->getLocation(), diag::note_previous_decl) << PrevFD;
340 SKEPAttr->setInvalidAttr();
346 Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
347 << SKEPAttr << diag::InvalidSKEPReason::Constructor;
348 SKEPAttr->setInvalidAttr();
351 Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
352 << SKEPAttr << diag::InvalidSKEPReason::Destructor;
353 SKEPAttr->setInvalidAttr();
355 if (
const auto *MD = dyn_cast<CXXMethodDecl>(FD)) {
356 if (MD->isExplicitObjectMemberFunction()) {
357 Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
358 << SKEPAttr << diag::InvalidSKEPReason::ExplicitObjectFn;
359 SKEPAttr->setInvalidAttr();
364 Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
365 << SKEPAttr << diag::InvalidSKEPReason::VariadicFn;
366 SKEPAttr->setInvalidAttr();
370 Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
371 << SKEPAttr << diag::InvalidSKEPReason::DefaultedFn;
372 SKEPAttr->setInvalidAttr();
374 Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
375 << SKEPAttr << diag::InvalidSKEPReason::DeletedFn;
376 SKEPAttr->setInvalidAttr();
380 Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
381 << SKEPAttr << diag::InvalidSKEPReason::ConstevalFn;
382 SKEPAttr->setInvalidAttr();
384 Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
385 << SKEPAttr << diag::InvalidSKEPReason::ConstexprFn;
386 SKEPAttr->setInvalidAttr();
390 Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
391 << SKEPAttr << diag::InvalidSKEPReason::NoreturnFn;
392 SKEPAttr->setInvalidAttr();
396 Diag(SKEPAttr->getLocation(),
397 diag::err_sycl_entry_point_deduced_return_type)
399 SKEPAttr->setInvalidAttr();
402 Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_return_type)
404 SKEPAttr->setInvalidAttr();
408 !SKEPAttr->isInvalidAttr()) {
418 diag::note_previous_declaration);
419 SKEPAttr->setInvalidAttr();
431 assert(
SemaRef.CurContext == FD &&
"The current declaration context does not "
432 "match the requested function context");
443 Ctx.
Idents.
get(
"sycl_kernel_launch", tok::TokenKind::identifier);
478 IdExpr =
SemaRef.BuildPossibleImplicitMemberExpr(
507 assert(SemaRef.
CurContext == FD &&
"The current declaration context does not "
508 "match the requested function context");
515 KernelName.size() + 1);
518 Expr *KernelNameExpr =
520 false, KernelNameArrayTy, Loc);
521 Args.push_back(KernelNameExpr);
526 QualType ParamType = PVD->getOriginalType().getNonReferenceType();
530 if (!PVD->getType()->isLValueReferenceType())
536 Args.push_back(E.
get());
559 if (BuildSYCLKernelLaunchCallArgs(SemaRef, FD, SKI, Args, Loc))
591class OutlinedFunctionDeclBodyInstantiator
592 :
public TreeTransform<OutlinedFunctionDeclBodyInstantiator> {
594 using ParmDeclMap = llvm::DenseMap<ParmVarDecl *, VarDecl *>;
596 OutlinedFunctionDeclBodyInstantiator(Sema &S, ParmDeclMap &M,
598 : TreeTransform<OutlinedFunctionDeclBodyInstantiator>(S), SemaRef(S),
602 bool AlwaysRebuild() {
return true; }
605 ExprResult TransformDeclRefExpr(DeclRefExpr *DRE) {
606 const ParmVarDecl *PVD = dyn_cast<ParmVarDecl>(DRE->
getDecl());
608 ParmDeclMap::iterator I = MapRef.find(PVD);
609 if (I != MapRef.end()) {
610 VarDecl *VD = I->second;
626 ExprResult TransformCXXThisExpr(CXXThisExpr *CTE) {
628 SemaRef.
Diag(CTE->
getExprLoc(), diag::err_sycl_entry_point_invalid_this)
630 << FD->
getAttr<SYCLKernelEntryPointAttr>();
644 using ParmDeclMap = OutlinedFunctionDeclBodyInstantiator::ParmDeclMap;
659 OutlinedFunctionDeclBodyInstantiator OFDBodyInstantiator(SemaRef, ParmMap,
661 Stmt *OFDBody = OFDBodyInstantiator.TransformStmt(Body).get();
672 Expr *LaunchIdExpr) {
679 assert(
SemaRef.CurContext == FD &&
"The current declaration context does not "
680 "match the requested function context");
682 const auto *SKEPAttr = FD->
getAttr<SYCLKernelEntryPointAttr>();
683 assert(SKEPAttr &&
"Missing sycl_kernel_entry_point attribute");
684 assert(!SKEPAttr->isInvalidAttr() &&
685 "sycl_kernel_entry_point attribute is invalid");
692 "SYCL kernel name conflict");
696 BuildSYCLKernelEntryPointOutline(
SemaRef, FD, Body);
703 BuildSYCLKernelLaunchCallStmt(
SemaRef, FD, &SKI, LaunchIdExpr, Loc);
714 Expr *LaunchIdExpr) {
Defines the Diagnostic-related interfaces.
This file declares types used to describe SYCL kernels.
static bool isZeroSizedArray(const ConstantArrayType *CAT)
static SourceLocation SourceLocationForUserDeclaredType(QualType QT)
static bool CheckSYCLKernelName(Sema &S, SourceLocation Loc, QualType KernelName)
This file declares semantic analysis for SYCL constructs.
This file defines SYCL AST classes used to represent calls to SYCL kernels.
Allows QualTypes to be sorted and hence used in maps and sets.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
const ConstantArrayType * getAsConstantArrayType(QualType T) const
QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize, const Expr *SizeExpr, ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return the unique reference to the type for a constant array of the specified element type.
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location,...
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
void registerSYCLEntryPointFunction(FunctionDecl *FD)
Generates and stores SYCL kernel metadata for the provided SYCL kernel entry point function.
const SYCLKernelInfo & getSYCLKernelInfo(QualType T) const
Given a type used as a SYCL kernel name, returns a reference to the metadata generated from the corre...
QualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
static bool hasSameUnqualifiedType(QualType T1, QualType T2)
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
const SYCLKernelInfo * findSYCLKernelInfo(QualType T) const
Returns a pointer to the metadata generated from the corresponding SYCLkernel entry point if the prov...
Represents a C++ nested-name-specifier or a global scope specifier.
QualType withConst() const
Retrieves a version of this type with const applied.
CompoundStmt - This represents a group of statements like { stmt stmt }.
SourceLocation getLBracLoc() const
static CompoundStmt * Create(const ASTContext &C, ArrayRef< Stmt * > Stmts, FPOptionsOverride FPFeatures, SourceLocation LB, SourceLocation RB)
DeclarationNameInfo getNameInfo() const
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
static DeclRefExpr * Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *D, bool RefersToEnclosingVariableOrCapture, SourceLocation NameLoc, QualType T, ExprValueKind VK, NamedDecl *FoundD=nullptr, const TemplateArgumentListInfo *TemplateArgs=nullptr, NonOdrUseReason NOUR=NOUR_None)
NestedNameSpecifierLoc getQualifierLoc() const
If the name was qualified, retrieves the nested-name-specifier that precedes the name,...
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
void setIsUsed()
Set whether the declaration is used, in the sense of odr-use.
This represents one expression.
bool isImplicitCXXThis() const
Whether this expression is an implicit reference to 'this' in C++.
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Represents difference between two FPOptions values.
Represents a function declaration or definition.
bool isFunctionTemplateSpecialization() const
Determine whether this function is a function template specialization.
bool isNoReturn() const
Determines whether this function is known to be 'noreturn', through an attribute on its declaration o...
QualType getReturnType() const
ArrayRef< ParmVarDecl * > parameters() const
bool hasPrototype() const
Whether this function has a prototype, either because one was explicitly written or because it was "i...
FunctionTemplateSpecializationInfo * getTemplateSpecializationInfo() const
If this function is actually a function template specialization, retrieve information about this func...
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 isDeletedAsWritten() const
bool isDefaulted() const
Whether this function is defaulted.
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
FunctionDecl * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
Declaration of a template function.
bool isExplicitSpecialization() const
One of these records is kept for each identifier that is lexed.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat, FPOptionsOverride FPO)
static ImplicitParamDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, ImplicitParamKind ParamKind)
Create implicit parameter.
Represents the results of name lookup.
This represents a decl that may have a name.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
bool isExternallyVisible() const
Represents a partial function definition.
static OutlinedFunctionDecl * Create(ASTContext &C, DeclContext *DC, unsigned NumParams)
void setNothrow(bool Nothrow=true)
void setParam(unsigned i, ImplicitParamDecl *P)
Represents a parameter to a function.
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.
bool isMoreQualifiedThan(QualType Other, const ASTContext &Ctx) const
Determine whether this type is more qualified than the other given type, requiring exact equality for...
SYCLKernelCallStmt represents the transformation that is applied to the body of a function declared w...
const std::string & GetKernelName() const
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.
ASTContext & getASTContext() const
const LangOptions & getLangOpts() const
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
StmtResult BuildUnresolvedSYCLKernelCallStmt(CompoundStmt *Body, Expr *LaunchIdExpr)
Builds an UnresolvedSYCLKernelCallStmt to wrap 'Body'.
StmtResult BuildSYCLKernelCallStmt(FunctionDecl *FD, CompoundStmt *Body, Expr *LaunchIdExpr)
Builds a SYCLKernelCallStmt to wrap 'Body' and to be used as the body of 'FD'.
SemaDiagnosticBuilder DiagIfDeviceCode(SourceLocation Loc, unsigned DiagID)
Creates a SemaDiagnosticBuilder that emits the diagnostic if the current context is "used as device c...
void CheckSYCLExternalFunctionDecl(FunctionDecl *FD)
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)
void CheckDeviceUseOfDecl(NamedDecl *ND, SourceLocation Loc)
Issues a deferred diagnostic if use of the declaration designated by 'ND' is invalid in a device cont...
ExprResult BuildSYCLKernelLaunchIdExpr(FunctionDecl *FD, QualType KernelName)
Builds an expression for the lookup of a 'sycl_kernel_launch' template with 'KernelName' as an explic...
ExprResult ActOnUniqueStableNameExpr(SourceLocation OpLoc, SourceLocation LParen, SourceLocation RParen, ParsedType ParsedTy)
RAII object to ensure that a code synthesis context is popped on scope exit.
Sema - This implements semantic analysis and AST building for C.
Scope * getCurScope() const
Retrieve the parser's current scope.
@ LookupOrdinaryName
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc....
FunctionEmissionStatus
Status of the function emission on the CUDA/HIP/OpenMP host/device attrs.
const ExpressionEvaluationContextRecord & currentEvaluationContext() const
ASTContext & getASTContext() const
DeclRefExpr * BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, SourceLocation Loc, const CXXScopeSpec *SS=nullptr)
ExprResult BuildCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc, MultiExprArg ArgExprs, SourceLocation RParenLoc, Expr *ExecConfig=nullptr, bool IsExecConfig=false, bool AllowRecovery=false)
BuildCallExpr - Handle a call to Fn with the specified array of arguments.
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
Expr * MaybeCreateExprWithCleanups(Expr *SubExpr)
MaybeCreateExprWithCleanups - If the current full-expression requires any cleanups,...
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
Stmt - This represents one statement.
static StringLiteral * Create(const ASTContext &Ctx, StringRef Str, StringLiteralKind Kind, bool Pascal, QualType Ty, ArrayRef< SourceLocation > Locs)
This is the "fully general" constructor that allows representation of strings formed from one or more...
A convenient class for passing around template argument information.
void addArgument(const TemplateArgumentLoc &Loc)
Location wrapper for a TemplateArgument.
Represents a template argument.
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.
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
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,...
static UnresolvedSYCLKernelCallStmt * Create(const ASTContext &C, CompoundStmt *CS, Expr *IdExpr)
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.
bool isa(CodeGen::Address addr)
QualType getFunctionOrMethodResultType(const Decl *D)
@ Result
The result type of a method or function.
void handleSimpleAttribute(SemaBase &S, Decl *D, const AttributeCommonInfo &CI)
Applies the given attribute to the Decl without performing any additional semantic checking.
@ VK_XValue
An x-value expression is a reference to an object with independent storage but which can be "moved",...
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
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.
U cast(CodeGen::Address addr)
OpaquePtr< QualType > ParsedType
An opaque type for threading parsed type information through the parser.
ActionResult< Expr * > ExprResult
@ Other
Other implicit parameter.
ActionResult< Stmt * > StmtResult
A context in which code is being synthesized (where a source location alone is not sufficient to iden...
enum clang::Sema::CodeSynthesisContext::SynthesisKind Kind
unsigned NumCallArgs
The number of expressions in CallArgs.
const Expr *const * CallArgs
The list of argument expressions in a synthesized call.
@ SYCLKernelLaunchOverloadResolution
We are performing overload resolution for a call to a function template or variable template named 's...
@ SYCLKernelLaunchLookup
We are performing name lookup for a function template or variable template named 'sycl_kernel_launch'...
Decl * Entity
The entity that is being synthesized.
bool isPotentiallyEvaluated() const