[clang] [HLSL] Rewrite semantics parsing (PR #152537)
Chris B via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 14 06:47:08 PDT 2025
================
@@ -1513,29 +1517,71 @@ bool SemaHLSL::diagnosePositionType(QualType T, const ParsedAttr &AL) {
return true;
}
-void SemaHLSL::handleSV_PositionAttr(Decl *D, const ParsedAttr &AL) {
- auto *VD = cast<ValueDecl>(D);
- if (!diagnosePositionType(VD->getType(), AL))
- return;
-
- D->addAttr(::new (getASTContext()) HLSLSV_PositionAttr(getASTContext(), AL));
-}
+void SemaHLSL::diagnoseSystemSemanticAttr(Decl *D, const ParsedAttr &AL,
+ std::optional<unsigned> Index) {
+ StringRef SemanticName = AL.getAttrName()->getName();
-void SemaHLSL::handleSV_GroupThreadIDAttr(Decl *D, const ParsedAttr &AL) {
auto *VD = cast<ValueDecl>(D);
- if (!diagnoseInputIDType(VD->getType(), AL))
- return;
-
- D->addAttr(::new (getASTContext())
- HLSLSV_GroupThreadIDAttr(getASTContext(), AL));
-}
+ QualType ValueType = VD->getType();
+ if (auto *FD = dyn_cast<FunctionDecl>(D))
+ ValueType = FD->getReturnType();
+
+ bool IsOutput = false;
+ if (HLSLParamModifierAttr *MA = D->getAttr<HLSLParamModifierAttr>()) {
+ if (MA->isOut()) {
+ IsOutput = true;
+ ValueType = cast<ReferenceType>(ValueType)->getPointeeType();
+ }
+ }
-void SemaHLSL::handleSV_GroupIDAttr(Decl *D, const ParsedAttr &AL) {
- auto *VD = cast<ValueDecl>(D);
- if (!diagnoseInputIDType(VD->getType(), AL))
+#define CHECK_OUTPUT_FORBIDDEN(AL) \
+ if (IsOutput) { \
+ Diag(AL.getLoc(), diag::err_hlsl_semantic_output_not_supported) << AL; \
+ }
+
+ Attr *Attribute = nullptr;
+ if (SemanticName == "SV_DISPATCHTHREADID") {
+ diagnoseInputIDType(ValueType, AL);
+ CHECK_OUTPUT_FORBIDDEN(AL);
+ Attribute = createSemanticAttr<HLSLSV_DispatchThreadIDAttr>(AL, Index);
+ } else if (SemanticName == "SV_GROUPINDEX") {
+ CHECK_OUTPUT_FORBIDDEN(AL);
+ Attribute = createSemanticAttr<HLSLSV_GroupIndexAttr>(AL, Index);
+ } else if (SemanticName == "SV_GROUPTHREADID") {
+ diagnoseInputIDType(ValueType, AL);
+ CHECK_OUTPUT_FORBIDDEN(AL);
+ Attribute = createSemanticAttr<HLSLSV_GroupThreadIDAttr>(AL, Index);
+ } else if (SemanticName == "SV_GROUPID") {
+ diagnoseInputIDType(ValueType, AL);
+ CHECK_OUTPUT_FORBIDDEN(AL);
+ Attribute = createSemanticAttr<HLSLSV_GroupIDAttr>(AL, Index);
+ } else if (SemanticName == "SV_POSITION") {
----------------
llvm-beanz wrote:
I worry a little bit about this if/else statement just becoming a bit of a mess, but it's probably fine for now. We can always refactor it later as it grows and we have a clearer understanding of all the cases it needs to handle.
https://github.com/llvm/llvm-project/pull/152537
More information about the cfe-commits
mailing list