https://github.com/s-perron updated https://github.com/llvm/llvm-project/pull/185039
>From fb36d4478797b179c499989d8f72c7262c1d3c10 Mon Sep 17 00:00:00 2001 From: Steven Perron <[email protected]> Date: Fri, 6 Mar 2026 11:46:08 -0500 Subject: [PATCH] [HLSL] Add parsing for the resource dimension attribute. 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 --- clang/lib/Sema/SemaHLSL.cpp | 18 ++++++++++++++++++ clang/lib/Sema/SemaType.cpp | 1 + .../hlsl_resource_dimension_attr.hlsl | 17 +++++++++++++++++ .../hlsl_resource_dimension_attr_error.hlsl | 19 +++++++++++++++++++ 4 files changed, 55 insertions(+) create mode 100644 clang/test/ParserHLSL/hlsl_resource_dimension_attr.hlsl create mode 100644 clang/test/ParserHLSL/hlsl_resource_dimension_attr_error.hlsl diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp index 5701b76427d60..8fe10fb67a74d 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 6406ee06e757b..8b7070e52e3e5 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -9310,6 +9310,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@+1{{'hlsl::dimension' attribute cannot be applied to a declaration}} +[[hlsl::dimension("2D")]] __hlsl_resource_t e0; + +// expected-error@+1{{'hlsl::dimension' attribute takes one argument}} +__hlsl_resource_t [[hlsl::dimension()]] e1; + +// expected-error@+1{{expected string literal as argument of 'dimension' attribute}} +__hlsl_resource_t [[hlsl::dimension(2)]] e2; + +// expected-warning@+1{{ResourceDimension attribute argument not supported: gibberish}} +__hlsl_resource_t [[hlsl::dimension("gibberish")]] e3; + +// expected-error@+1{{'hlsl::dimension' attribute takes one argument}} +__hlsl_resource_t [[hlsl::dimension("2D", "3D")]] e4; + +// expected-error@+1{{attribute 'hlsl::dimension' can be used only on HLSL intangible type '__hlsl_resource_t'}} +float [[hlsl::dimension("2D")]] e5; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
