Nathan =?utf-8?q?Gauër?= <brio...@google.com>, Nathan =?utf-8?q?Gauër?= <brio...@google.com>, Nathan =?utf-8?q?Gauër?= <brio...@google.com> Message-ID: In-Reply-To: <llvm.org/llvm/llvm-project/pull/159...@github.com>
================ @@ -769,23 +769,80 @@ void SemaHLSL::ActOnTopLevelFunction(FunctionDecl *FD) { } } -bool SemaHLSL::isSemanticValid(FunctionDecl *FD, DeclaratorDecl *D) { - const auto *AnnotationAttr = D->getAttr<HLSLAnnotationAttr>(); - if (AnnotationAttr) { - CheckSemanticAnnotation(FD, D, AnnotationAttr); - return true; +HLSLSemanticAttr *SemaHLSL::createSemantic(const SemanticInfo &Info, + Decl *TargetDecl) { + std::string SemanticName = Info.Semantic->getAttrName()->getName().upper(); + + if (SemanticName == "SV_DISPATCHTHREADID") { + return createSemanticAttr<HLSLSV_DispatchThreadIDAttr>( + *Info.Semantic, TargetDecl, Info.Index); + } else if (SemanticName == "SV_GROUPINDEX") { + return createSemanticAttr<HLSLSV_GroupIndexAttr>(*Info.Semantic, TargetDecl, + Info.Index); + } else if (SemanticName == "SV_GROUPTHREADID") { + return createSemanticAttr<HLSLSV_GroupThreadIDAttr>(*Info.Semantic, + TargetDecl, Info.Index); + } else if (SemanticName == "SV_GROUPID") { + return createSemanticAttr<HLSLSV_GroupIDAttr>(*Info.Semantic, TargetDecl, + Info.Index); + } else if (SemanticName == "SV_POSITION") { + return createSemanticAttr<HLSLSV_PositionAttr>(*Info.Semantic, TargetDecl, + Info.Index); + } else + Diag(Info.Semantic->getLoc(), diag::err_hlsl_unknown_semantic) + << *Info.Semantic; + + return nullptr; +} + +bool SemaHLSL::isSemanticOnScalarValid(FunctionDecl *FD, DeclaratorDecl *D, + SemanticInfo &ActiveSemantic) { + if (ActiveSemantic.Semantic == nullptr) { + ActiveSemantic.Semantic = D->getAttr<HLSLSemanticAttr>(); + if (ActiveSemantic.Semantic && + ActiveSemantic.Semantic->isSemanticIndexExplicit()) + ActiveSemantic.Index = ActiveSemantic.Semantic->getSemanticIndex(); + } + + if (!ActiveSemantic.Semantic) { + Diag(D->getLocation(), diag::err_hlsl_missing_semantic_annotation); + return false; + } + + auto *A = createSemantic(ActiveSemantic, D); + if (!A) + return false; + + checkSemanticAnnotation(FD, D, A); + FD->addAttr(A); ---------------- s-perron wrote: Attaching the attribute in a function called `isSemanticOnScalarValid` is misleading. From the function name, I would not expect it to modify anything. https://github.com/llvm/llvm-project/pull/159047 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits