[clang] afedb03 - [HLSL] Add parsing for the resource dimension attribute. (#185039)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 10 06:28:11 PDT 2026
Author: Steven Perron
Date: 2026-03-10T09:28:06-04:00
New Revision: afedb030d6c6bfbeec3defeb257ebf94a75af77f
URL: https://github.com/llvm/llvm-project/commit/afedb030d6c6bfbeec3defeb257ebf94a75af77f
DIFF: https://github.com/llvm/llvm-project/commit/afedb030d6c6bfbeec3defeb257ebf94a75af77f.diff
LOG: [HLSL] Add parsing for the resource dimension attribute. (#185039)
The resource attribute was added, but the code to be able to parse it
as we do with other resource attributes was missing. This means we are
not able to test the attribute in isolation.
This change adds the parsing for the attribute, and adds more testing
for it.
Assisted-by: Gemini
<!-- branch-stack-start -->
-------------------------
- main
- https://github.com/llvm/llvm-project/pull/185039 :point_left:
<sup>[Stack](https://www.git-town.com/how-to/proposal-breadcrumb.html)
generated by [Git Town](https://github.com/git-town/git-town)</sup>
<!-- branch-stack-end -->
Added:
clang/test/ParserHLSL/hlsl_resource_dimension_attr.hlsl
clang/test/ParserHLSL/hlsl_resource_dimension_attr_error.hlsl
Modified:
clang/lib/Sema/SemaHLSL.cpp
clang/lib/Sema/SemaType.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 2ef3a72eead83..b37c205b0ad63 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -2142,6 +2142,24 @@ bool SemaHLSL::handleResourceTypeAttr(QualType T, const ParsedAttr &AL) {
break;
}
+ case ParsedAttr::AT_HLSLResourceDimension: {
+ StringRef Identifier;
+ SourceLocation ArgLoc;
+ if (!SemaRef.checkStringLiteralArgumentAttr(AL, 0, Identifier, &ArgLoc))
+ return false;
+
+ // Validate resource dimension value
+ llvm::dxil::ResourceDimension RD;
+ if (!HLSLResourceDimensionAttr::ConvertStrToResourceDimension(Identifier,
+ RD)) {
+ Diag(ArgLoc, diag::warn_attribute_type_not_supported)
+ << "ResourceDimension" << Identifier;
+ return false;
+ }
+ A = HLSLResourceDimensionAttr::Create(getASTContext(), RD, ACI);
+ break;
+ }
+
case ParsedAttr::AT_HLSLROV:
A = HLSLROVAttr::Create(getASTContext(), ACI);
break;
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 2187f7c16eba5..2918538ac0f64 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -9329,6 +9329,7 @@ static void processTypeAttrs(TypeProcessingState &state, QualType &type,
break;
}
case ParsedAttr::AT_HLSLResourceClass:
+ case ParsedAttr::AT_HLSLResourceDimension:
case ParsedAttr::AT_HLSLROV:
case ParsedAttr::AT_HLSLRawBuffer:
case ParsedAttr::AT_HLSLContainedType: {
diff --git a/clang/test/ParserHLSL/hlsl_resource_dimension_attr.hlsl b/clang/test/ParserHLSL/hlsl_resource_dimension_attr.hlsl
new file mode 100644
index 0000000000000..358741fa19f7b
--- /dev/null
+++ b/clang/test/ParserHLSL/hlsl_resource_dimension_attr.hlsl
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -x hlsl -ast-dump -o - %s | FileCheck %s
+
+// CHECK: VarDecl {{.*}} res1D '__hlsl_resource_t
+// CHECK-SAME{LITERAL}: [[hlsl::resource_class(SRV)]] [[hlsl::resource_dimension(1D)]]
+__hlsl_resource_t [[hlsl::resource_class(SRV)]] [[hlsl::dimension("1D")]] res1D;
+
+// CHECK: VarDecl 0x{{[0-9a-f]+}} {{.*}} res2D '__hlsl_resource_t
+// CHECK-SAME{LITERAL}: [[hlsl::resource_class(SRV)]] [[hlsl::resource_dimension(2D)]]
+__hlsl_resource_t [[hlsl::resource_class(SRV)]] [[hlsl::dimension("2D")]] res2D;
+
+// CHECK: VarDecl 0x{{[0-9a-f]+}} {{.*}} res3D '__hlsl_resource_t
+// CHECK-SAME{LITERAL}: [[hlsl::resource_class(SRV)]] [[hlsl::resource_dimension(3D)]]
+__hlsl_resource_t [[hlsl::resource_class(SRV)]] [[hlsl::dimension("3D")]] res3D;
+
+// CHECK: VarDecl 0x{{[0-9a-f]+}} {{.*}} resCube '__hlsl_resource_t
+// CHECK-SAME{LITERAL}: [[hlsl::resource_class(SRV)]] [[hlsl::resource_dimension(Cube)]]
+__hlsl_resource_t [[hlsl::resource_class(SRV)]] [[hlsl::dimension("Cube")]] resCube;
diff --git a/clang/test/ParserHLSL/hlsl_resource_dimension_attr_error.hlsl b/clang/test/ParserHLSL/hlsl_resource_dimension_attr_error.hlsl
new file mode 100644
index 0000000000000..e37405fe348bd
--- /dev/null
+++ b/clang/test/ParserHLSL/hlsl_resource_dimension_attr_error.hlsl
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -x hlsl -o - %s -verify
+
+// expected-error at +1{{'hlsl::dimension' attribute cannot be applied to a declaration}}
+[[hlsl::dimension("2D")]] __hlsl_resource_t e0;
+
+// expected-error at +1{{'hlsl::dimension' attribute takes one argument}}
+__hlsl_resource_t [[hlsl::dimension()]] e1;
+
+// expected-error at +1{{expected string literal as argument of 'dimension' attribute}}
+__hlsl_resource_t [[hlsl::dimension(2)]] e2;
+
+// expected-warning at +1{{ResourceDimension attribute argument not supported: gibberish}}
+__hlsl_resource_t [[hlsl::dimension("gibberish")]] e3;
+
+// expected-error at +1{{'hlsl::dimension' attribute takes one argument}}
+__hlsl_resource_t [[hlsl::dimension("2D", "3D")]] e4;
+
+// expected-error at +1{{attribute 'hlsl::dimension' can be used only on HLSL intangible type '__hlsl_resource_t'}}
+float [[hlsl::dimension("2D")]] e5;
More information about the cfe-commits
mailing list