[clang] [HLSL] Rewrite semantics parsing (PR #152537)
Nathan Gauër via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 25 05:02:58 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") {
----------------
Keenuts wrote:
Yes, once the main bits are implemented we should see how to refactorize this.
https://github.com/llvm/llvm-project/pull/152537
More information about the cfe-commits
mailing list