[clang] [ParserHLSL] Attempt to parse HLSL annotations on Field Decls. (PR #96346)

Joshua Batista via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 26 12:04:59 PDT 2024


================
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -x hlsl -o - %s -verify
+
+// previously, this test would result in an error shown below on the line that 
+// declares variable a in struct Eg9:
+// error: use of undeclared identifier
+//     'SV_DispatchThreadID'
+// This is because the annotation is parsed as if it was a c++ bit field, and an identifier
+// that represents an integer is expected, but not found.
+
+// This test ensures that hlsl annotations are attempted to be parsed when parsing struct decls.
+// Ideally, we'd validate this behavior by ensuring the annotation is parsed and properly
+// attached as an attribute to the member in the struct in the AST. However, in this case
+// this can't happen presently because there are other issues with annotations on field decls.
+// This test just ensures we make progress by moving the validation error from the realm of
+// C++ and expecting bitfields, to HLSL and a specialized error for the recognized annotation.
+
+struct Eg9{
+// expected-error at +1{{attribute 'SV_DispatchThreadID' only applies to parameter}}
+  int a : SV_DispatchThreadID;
----------------
bob80905 wrote:

Though the attribute being allowed to apply to struct members was understood, I underwent some extra effort in understanding why the attribute wasn't supported, but didn't find any good reason. I removed the diagnostic block preventing the attribute from being parsed when on a field decl, and added a test that validates the annotation gets added as an attribute on the AST.

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


More information about the cfe-commits mailing list