[clang] Implement resource binding type prefix mismatch diagnostic infrastructure (PR #97103)

Joshua Batista via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 22 15:53:05 PDT 2024


================
@@ -0,0 +1,76 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -o - -fsyntax-only %s -verify
+
+// This test validates the diagnostics that are emitted when a variable with a "resource" type
+// is bound to a register using the register annotation
+
+// expected-error at +1  {{binding type 'b' only applies to constant buffer resources}}
+RWBuffer<int> a : register(b2, space1);
----------------
bob80905 wrote:

I don't think we should remove all instances of RWBuffer in testing. Although we plan to eventually move all hlsl resources into an appropriate header, with the corresponding spellable hlsl attributes, as it stands now RWBuffer is defined in HLSLExternalSemaSource.cpp within a template specialization decl. There is code in this change that specifically accounts for this, and by removing RWBuffer entirely from the tests, it would become dead code. 
Specifically, `getSpecifiedHLSLAttrFromRecordDecl` has an if condition to check if the record decl is a `ClassTemplateSpecializationDecl`, which is only the case for types declared in HLSLExternalSemaSource.cpp. 
This change should test both user defined types that have the spellable attribute of interest, but ideally the end goal is that it works with actual practical HLSL resources, like RWBuffer. 

https://github.com/llvm/llvm-project/pull/97103


More information about the cfe-commits mailing list