Lines Matching +full:diag +full:- +full:version
1 //===- SemaHLSL.cpp - Semantic Analysis for HLSL constructs ---------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 //===----------------------------------------------------------------------===//
48 // https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-packing-rules
53 if (const RecordType *RT = T->getAs<RecordType>()) { in calculateLegacyCbufferSize()
54 const RecordDecl *RD = RT->getDecl(); in calculateLegacyCbufferSize()
55 for (const FieldDecl *Field : RD->fields()) { in calculateLegacyCbufferSize()
56 QualType Ty = Field->getType(); in calculateLegacyCbufferSize()
59 if (Ty->isAggregateType()) in calculateLegacyCbufferSize()
65 if (unsigned ElementCount = AT->getSize().getZExtValue()) { in calculateLegacyCbufferSize()
67 calculateLegacyCbufferSize(Context, AT->getElementType()); in calculateLegacyCbufferSize()
69 Size = AlignedElementSize * (ElementCount - 1) + ElementSize; in calculateLegacyCbufferSize()
71 } else if (const VectorType *VT = T->getAs<VectorType>()) { in calculateLegacyCbufferSize()
72 unsigned ElementCount = VT->getNumElements(); in calculateLegacyCbufferSize()
74 calculateLegacyCbufferSize(Context, VT->getElementType()); in calculateLegacyCbufferSize()
84 BufDecl->setRBraceLoc(RBrace); in ActOnFinishBuffer()
90 for (auto *Field : BufDecl->decls()) { in ActOnFinishBuffer()
94 if (Field->hasAttr<HLSLPackOffsetAttr>()) { in ActOnFinishBuffer()
95 PackOffsetVec.emplace_back(Var, Field->getAttr<HLSLPackOffsetAttr>()); in ActOnFinishBuffer()
103 Diag(BufDecl->getLocation(), diag::warn_hlsl_packoffset_mix); in ActOnFinishBuffer()
112 return LHS.second->getOffset() < RHS.second->getOffset(); in ActOnFinishBuffer()
115 for (unsigned i = 0; i < PackOffsetVec.size() - 1; i++) { in ActOnFinishBuffer()
118 unsigned Size = calculateLegacyCbufferSize(Context, Var->getType()); in ActOnFinishBuffer()
119 unsigned Begin = Attr->getOffset() * 32; in ActOnFinishBuffer()
121 unsigned NextBegin = PackOffsetVec[i + 1].second->getOffset() * 32; in ActOnFinishBuffer()
124 Diag(NextVar->getLocation(), diag::err_hlsl_packoffset_overlap) in ActOnFinishBuffer()
136 if (HLSLNumThreadsAttr *NT = D->getAttr<HLSLNumThreadsAttr>()) { in mergeNumThreadsAttr()
137 if (NT->getX() != X || NT->getY() != Y || NT->getZ() != Z) { in mergeNumThreadsAttr()
138 Diag(NT->getLocation(), diag::err_hlsl_attribute_param_mismatch) << AL; in mergeNumThreadsAttr()
139 Diag(AL.getLoc(), diag::note_conflicting_attribute); in mergeNumThreadsAttr()
150 if (HLSLShaderAttr *NT = D->getAttr<HLSLShaderAttr>()) { in mergeShaderAttr()
151 if (NT->getType() != ShaderType) { in mergeShaderAttr()
152 Diag(NT->getLocation(), diag::err_hlsl_attribute_param_mismatch) << AL; in mergeShaderAttr()
153 Diag(AL.getLoc(), diag::note_conflicting_attribute); in mergeShaderAttr()
164 // combinations of duplicated attributes are ill-formed. in mergeParamModifierAttr()
165 if (HLSLParamModifierAttr *PA = D->getAttr<HLSLParamModifierAttr>()) { in mergeParamModifierAttr()
166 if ((PA->isIn() && Spelling == HLSLParamModifierAttr::Keyword_out) || in mergeParamModifierAttr()
167 (PA->isOut() && Spelling == HLSLParamModifierAttr::Keyword_in)) { in mergeParamModifierAttr()
168 D->dropAttr<HLSLParamModifierAttr>(); in mergeParamModifierAttr()
169 SourceRange AdjustedRange = {PA->getLocation(), AL.getRange().getEnd()}; in mergeParamModifierAttr()
174 Diag(AL.getLoc(), diag::err_hlsl_duplicate_parameter_modifier) << AL; in mergeParamModifierAttr()
175 Diag(PA->getLocation(), diag::note_conflicting_attribute); in mergeParamModifierAttr()
184 if (FD->getName() != TargetInfo.getTargetOpts().HLSLEntry) in ActOnTopLevelFunction()
189 if (const auto *Shader = FD->getAttr<HLSLShaderAttr>()) { in ActOnTopLevelFunction()
190 // The entry point is already annotated - check that it matches the in ActOnTopLevelFunction()
192 if (Shader->getType() != Env) { in ActOnTopLevelFunction()
193 Diag(Shader->getLocation(), diag::err_hlsl_entry_shader_attr_mismatch) in ActOnTopLevelFunction()
195 FD->setInvalidDecl(); in ActOnTopLevelFunction()
200 FD->addAttr(HLSLShaderAttr::CreateImplicit(getASTContext(), Env, in ActOnTopLevelFunction()
201 FD->getBeginLoc())); in ActOnTopLevelFunction()
215 const auto *ShaderAttr = FD->getAttr<HLSLShaderAttr>(); in CheckEntryPoint()
217 llvm::Triple::EnvironmentType ST = ShaderAttr->getType(); in CheckEntryPoint()
231 if (const auto *NT = FD->getAttr<HLSLNumThreadsAttr>()) { in CheckEntryPoint()
236 FD->setInvalidDecl(); in CheckEntryPoint()
243 if (!FD->hasAttr<HLSLNumThreadsAttr>()) { in CheckEntryPoint()
244 Diag(FD->getLocation(), diag::err_hlsl_missing_numthreads) in CheckEntryPoint()
246 FD->setInvalidDecl(); in CheckEntryPoint()
253 for (ParmVarDecl *Param : FD->parameters()) { in CheckEntryPoint()
254 if (const auto *AnnotationAttr = Param->getAttr<HLSLAnnotationAttr>()) { in CheckEntryPoint()
258 // See: https://github.com/llvm/llvm-project/issues/57875 in CheckEntryPoint()
259 Diag(FD->getLocation(), diag::err_hlsl_missing_semantic_annotation); in CheckEntryPoint()
260 Diag(Param->getLocation(), diag::note_previous_decl) << Param; in CheckEntryPoint()
261 FD->setInvalidDecl(); in CheckEntryPoint()
270 auto *ShaderAttr = EntryPoint->getAttr<HLSLShaderAttr>(); in CheckSemanticAnnotation()
272 llvm::Triple::EnvironmentType ST = ShaderAttr->getType(); in CheckSemanticAnnotation()
274 switch (AnnotationAttr->getKind()) { in CheckSemanticAnnotation()
295 Diag(A->getLoc(), diag::err_hlsl_attr_unsupported_in_stage) in DiagnoseAttrStageMismatch()
317 Diag(AL.getArgAsExpr(0)->getExprLoc(), in handleNumThreadsAttr()
318 diag::err_hlsl_numthreads_argument_oor) in handleNumThreadsAttr()
326 Diag(AL.getArgAsExpr(1)->getExprLoc(), in handleNumThreadsAttr()
327 diag::err_hlsl_numthreads_argument_oor) in handleNumThreadsAttr()
335 SemaRef.Diag(AL.getArgAsExpr(2)->getExprLoc(), in handleNumThreadsAttr()
336 diag::err_hlsl_numthreads_argument_oor) in handleNumThreadsAttr()
342 Diag(AL.getLoc(), diag::err_hlsl_numthreads_invalid) << ThreadMax; in handleNumThreadsAttr()
348 D->addAttr(NewAttr); in handleNumThreadsAttr()
352 if (!T->hasUnsignedIntegerRepresentation()) in isLegalTypeForHLSLSV_DispatchThreadID()
354 if (const auto *VT = T->getAs<VectorType>()) in isLegalTypeForHLSLSV_DispatchThreadID()
355 return VT->getNumElements() <= 3; in isLegalTypeForHLSLSV_DispatchThreadID()
361 if (!isLegalTypeForHLSLSV_DispatchThreadID(VD->getType())) { in handleSV_DispatchThreadIDAttr()
362 Diag(AL.getLoc(), diag::err_hlsl_attr_invalid_type) in handleSV_DispatchThreadIDAttr()
367 D->addAttr(::new (getASTContext()) in handleSV_DispatchThreadIDAttr()
372 if (!isa<VarDecl>(D) || !isa<HLSLBufferDecl>(D->getDeclContext())) { in handlePackOffsetAttr()
373 Diag(AL.getLoc(), diag::err_hlsl_attr_invalid_ast_node) in handlePackOffsetAttr()
385 QualType T = cast<VarDecl>(D)->getType().getCanonicalType(); in handlePackOffsetAttr()
388 bool IsAggregateTy = (T->isArrayType() || T->isStructureType()); in handlePackOffsetAttr()
394 Diag(AL.getLoc(), diag::err_hlsl_packoffset_cross_reg_boundary); in handlePackOffsetAttr()
399 Diag(AL.getLoc(), diag::err_hlsl_packoffset_cross_reg_boundary); in handlePackOffsetAttr()
403 if (const auto *VT = T->getAs<VectorType>()) in handlePackOffsetAttr()
404 EltTy = VT->getElementType(); in handlePackOffsetAttr()
409 Diag(AL.getLoc(), diag::err_hlsl_packoffset_alignment_mismatch) in handlePackOffsetAttr()
416 D->addAttr(::new (getASTContext()) HLSLPackOffsetAttr( in handlePackOffsetAttr()
428 Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) in handleShaderAttr()
437 D->addAttr(NewAttr); in handleShaderAttr()
442 Diag(AL.getLoc(), diag::err_attribute_argument_type) in handleResourceClassAttr()
448 StringRef Identifier = Loc->Ident->getName(); in handleResourceClassAttr()
449 SourceLocation ArgLoc = Loc->Loc; in handleResourceClassAttr()
454 Diag(ArgLoc, diag::warn_attribute_type_not_supported) in handleResourceClassAttr()
459 D->addAttr(HLSLResourceClassAttr::Create(getASTContext(), RC, ArgLoc)); in handleResourceClassAttr()
467 Diag(AL.getLoc(), diag::err_attribute_argument_type) in handleResourceBindingAttr()
473 StringRef Str = Loc->Ident->getName(); in handleResourceBindingAttr()
474 SourceLocation ArgLoc = Loc->Loc; in handleResourceBindingAttr()
480 Diag(AL.getLoc(), diag::err_attribute_argument_type) in handleResourceBindingAttr()
486 Space = Loc->Ident->getName(); in handleResourceBindingAttr()
487 SpaceArgLoc = Loc->Loc; in handleResourceBindingAttr()
501 Diag(ArgLoc, diag::err_hlsl_unsupported_register_type) in handleResourceBindingAttr()
509 Diag(ArgLoc, diag::err_hlsl_unsupported_register_number); in handleResourceBindingAttr()
515 Diag(SpaceArgLoc, diag::err_hlsl_expected_space) << Space; in handleResourceBindingAttr()
521 Diag(SpaceArgLoc, diag::err_hlsl_expected_space) << Space; in handleResourceBindingAttr()
526 // https://github.com/llvm/llvm-project/issues/57886. in handleResourceBindingAttr()
530 D->addAttr(NewAttr); in handleResourceBindingAttr()
538 D->addAttr(NewAttr); in handleParamModifierAttr()
580 // (int)(llvm::Triple::Pixel - llvm::Triple::Pixel) == 0
581 // (int)(llvm::Triple::Compute - llvm::Triple::Pixel) == 5
594 // depend only on shader model version because they would be duplicate.
601 assert((unsigned)(ShaderType - llvm::Triple::Pixel) < 31 && in SetShaderStageContext()
605 unsigned bitmapIndex = ShaderType - llvm::Triple::Pixel; in SetShaderStageContext()
660 FunctionDecl *FD = llvm::dyn_cast<FunctionDecl>(DRE->getDecl()); in VisitDeclRefExpr()
667 FunctionDecl *FD = llvm::dyn_cast<FunctionDecl>(ME->getMemberDecl()); in VisitMemberExpr()
679 // has a definition -> add to stack to be scanned in HandleFunctionOrMethodRef()
681 if (FD->hasBody(FDWithBody)) { in HandleFunctionOrMethodRef()
687 // no body -> diagnose availability in HandleFunctionOrMethodRef()
691 FD, AA, SourceRange(RefExpr->getBeginLoc(), RefExpr->getEndLoc())); in HandleFunctionOrMethodRef()
698 // that have a body (definiton), run diag scan on each, setting appropriate in RunOnTranslationUnit()
707 for (auto &D : DC->decls()) { in RunOnTranslationUnit()
709 if (D->isImplicit()) in RunOnTranslationUnit()
721 if (!FD || !FD->isThisDeclarationADefinition()) in RunOnTranslationUnit()
725 if (HLSLShaderAttr *ShaderAttr = FD->getAttr<HLSLShaderAttr>()) { in RunOnTranslationUnit()
726 SetShaderStageContext(ShaderAttr->getType()); in RunOnTranslationUnit()
733 bool isExport = FD->isInExportDeclContext(); in RunOnTranslationUnit()
735 for (const auto *Redecl : FD->redecls()) { in RunOnTranslationUnit()
736 if (Redecl->isInExportDeclContext()) { in RunOnTranslationUnit()
770 TraverseStmt(FD->getBody()); in RunOnFunction()
776 IdentifierInfo *IIEnvironment = AA->getEnvironment(); in HasMatchingEnvironmentOrNone()
785 AvailabilityAttr::getEnvironmentType(IIEnvironment->getName()); in HasMatchingEnvironmentOrNone()
796 for (const auto *A : D->attrs()) { in FindAvailabilityAttr()
798 StringRef AttrPlatform = Avail->getPlatform()->getName(); in FindAvailabilityAttr()
814 // Check availability against target shader model version and current shader
820 IdentifierInfo *IIEnv = AA->getEnvironment(); in CheckDeclAvailability()
823 // The availability attribute does not have environment -> it depends only in CheckDeclAvailability()
824 // on shader model version and not on specific the shader stage. in CheckDeclAvailability()
827 // strict (-fhlsl-strict-availability) because all relevant diagnostics in CheckDeclAvailability()
833 // Do not report shader-stage-independent issues if scanning a function in CheckDeclAvailability()
840 // The availability attribute has environment -> we need to know in CheckDeclAvailability()
846 // Check introduced version and if environment matches in CheckDeclAvailability()
848 VersionTuple Introduced = AA->getIntroduced(); in CheckDeclAvailability()
864 AA->getEnvironment() ? AA->getEnvironment()->getName() : ""; in CheckDeclAvailability()
868 SemaRef.Diag(Range.getBegin(), diag::warn_hlsl_availability) in CheckDeclAvailability()
872 SemaRef.Diag(Range.getBegin(), diag::warn_hlsl_availability_unavailable) in CheckDeclAvailability()
876 SemaRef.Diag(D->getLocation(), diag::note_partial_availability_specified_here) in CheckDeclAvailability()
886 // strict (-fhlsl-strict-availability) and the target shader stage is known in DiagnoseAvailabilityViolations()
899 assert(TheCall->getNumArgs() > 1); in CheckVectorElementCallArgs()
900 ExprResult A = TheCall->getArg(0); in CheckVectorElementCallArgs()
902 QualType ArgTyA = A.get()->getType(); in CheckVectorElementCallArgs()
904 auto *VecTyA = ArgTyA->getAs<VectorType>(); in CheckVectorElementCallArgs()
905 SourceLocation BuiltinLoc = TheCall->getBeginLoc(); in CheckVectorElementCallArgs()
907 for (unsigned i = 1; i < TheCall->getNumArgs(); ++i) { in CheckVectorElementCallArgs()
908 ExprResult B = TheCall->getArg(i); in CheckVectorElementCallArgs()
909 QualType ArgTyB = B.get()->getType(); in CheckVectorElementCallArgs()
910 auto *VecTyB = ArgTyB->getAs<VectorType>(); in CheckVectorElementCallArgs()
916 if (VecTyA->getElementType() != VecTyB->getElementType()) { in CheckVectorElementCallArgs()
919 S->Diag(TheCall->getBeginLoc(), in CheckVectorElementCallArgs()
920 diag::err_vec_builtin_incompatible_vector) in CheckVectorElementCallArgs()
921 << TheCall->getDirectCallee() << /*useAllTerminology*/ true in CheckVectorElementCallArgs()
922 << SourceRange(A.get()->getBeginLoc(), B.get()->getEndLoc()); in CheckVectorElementCallArgs()
925 if (VecTyA->getNumElements() != VecTyB->getNumElements()) { in CheckVectorElementCallArgs()
929 S->Diag(BuiltinLoc, diag::err_vec_builtin_incompatible_vector) in CheckVectorElementCallArgs()
930 << TheCall->getDirectCallee() << /*useAllTerminology*/ true in CheckVectorElementCallArgs()
931 << SourceRange(TheCall->getArg(0)->getBeginLoc(), in CheckVectorElementCallArgs()
932 TheCall->getArg(1)->getEndLoc()); in CheckVectorElementCallArgs()
941 S->Diag(BuiltinLoc, diag::err_vec_builtin_non_vector) in CheckVectorElementCallArgs()
942 << TheCall->getDirectCallee() << /*useAllTerminology*/ true in CheckVectorElementCallArgs()
943 << SourceRange(TheCall->getArg(0)->getBeginLoc(), in CheckVectorElementCallArgs()
944 TheCall->getArg(1)->getEndLoc()); in CheckVectorElementCallArgs()
951 for (unsigned i = 0; i < TheCall->getNumArgs(); ++i) { in CheckArgsTypesAreCorrect()
952 QualType PassedType = TheCall->getArg(i)->getType(); in CheckArgsTypesAreCorrect()
954 if (auto *VecTyA = PassedType->getAs<VectorType>()) in CheckArgsTypesAreCorrect()
955 ExpectedType = S->Context.getVectorType( in CheckArgsTypesAreCorrect()
956 ExpectedType, VecTyA->getNumElements(), VecTyA->getVectorKind()); in CheckArgsTypesAreCorrect()
957 S->Diag(TheCall->getArg(0)->getBeginLoc(), in CheckArgsTypesAreCorrect()
958 diag::err_typecheck_convert_incompatible) in CheckArgsTypesAreCorrect()
967 auto checkAllFloatTypes = [](clang::QualType PassedType) -> bool { in CheckAllArgsHaveFloatRepresentation()
968 return !PassedType->hasFloatingRepresentation(); in CheckAllArgsHaveFloatRepresentation()
970 return CheckArgsTypesAreCorrect(S, TheCall, S->Context.FloatTy, in CheckAllArgsHaveFloatRepresentation()
975 auto checkFloatorHalf = [](clang::QualType PassedType) -> bool { in CheckFloatOrHalfRepresentations()
977 PassedType->isVectorType() in CheckFloatOrHalfRepresentations()
978 ? PassedType->getAs<clang::VectorType>()->getElementType() in CheckFloatOrHalfRepresentations()
980 return !BaseType->isHalfType() && !BaseType->isFloat32Type(); in CheckFloatOrHalfRepresentations()
982 return CheckArgsTypesAreCorrect(S, TheCall, S->Context.FloatTy, in CheckFloatOrHalfRepresentations()
987 auto checkDoubleVector = [](clang::QualType PassedType) -> bool { in CheckNoDoubleVectors()
988 if (const auto *VecTy = PassedType->getAs<VectorType>()) in CheckNoDoubleVectors()
989 return VecTy->getElementType()->isDoubleType(); in CheckNoDoubleVectors()
992 return CheckArgsTypesAreCorrect(S, TheCall, S->Context.FloatTy, in CheckNoDoubleVectors()
997 auto checkAllUnsignedTypes = [](clang::QualType PassedType) -> bool { in CheckUnsignedIntRepresentation()
998 return !PassedType->hasUnsignedIntegerRepresentation(); in CheckUnsignedIntRepresentation()
1000 return CheckArgsTypesAreCorrect(S, TheCall, S->Context.UnsignedIntTy, in CheckUnsignedIntRepresentation()
1006 auto *VecTyA = TheCall->getArg(0)->getType()->getAs<VectorType>(); in SetElementTypeAsReturnType()
1008 ReturnType = S->Context.getVectorType(ReturnType, VecTyA->getNumElements(), in SetElementTypeAsReturnType()
1010 TheCall->setType(ReturnType); in SetElementTypeAsReturnType()
1030 TheCall->getArg(0)->getType()->hasFloatingRepresentation())) in CheckBuiltinFunctionCall()
1086 TheCall->getArg(0)->getType()->hasFloatingRepresentation())) in CheckBuiltinFunctionCall()