Skip to content

[HLSL][RootSignature] Use "stringified" version for diagnostic output of punctuator tokens #145827

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 26, 2025

Conversation

inbelic
Copy link
Contributor

@inbelic inbelic commented Jun 26, 2025

This pr will corrects the output with a stringified version of a puncuator (eg ')') instead of its ascii value.

  • Update LexHLSLRootSignature to fix the DiagnosticBuilder operator<< overload to correclty format the puncuator
  • Add testcase demonstrating the stringified version is output

Resolves #145814.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" HLSL HLSL Language Support labels Jun 26, 2025
@inbelic inbelic changed the title [HLSL][RootSignature] Output stringified punctuator in diagnostics [HLSL][RootSignature] Use "stringified" version for diagnostic output of punctuator tokens Jun 26, 2025
@llvmbot
Copy link
Member

llvmbot commented Jun 26, 2025

@llvm/pr-subscribers-clang

Author: Finn Plummer (inbelic)

Changes

This pr will corrects the output with a stringified version of a puncuator (eg ')') instead of its ascii value.

  • Update LexHLSLRootSignature to fix the DiagnosticBuilder operator&lt;&lt; overload to correclty format the puncuator
  • Add testcase demonstrating the stringified version is output

Resolves #145814.


Full diff: https://github.com/llvm/llvm-project/pull/145827.diff

2 Files Affected:

  • (modified) clang/include/clang/Lex/LexHLSLRootSignature.h (+4)
  • (modified) clang/test/SemaHLSL/RootSignature-err.hlsl (+4)
diff --git a/clang/include/clang/Lex/LexHLSLRootSignature.h b/clang/include/clang/Lex/LexHLSLRootSignature.h
index 9275e0d75840b..9901485b44d38 100644
--- a/clang/include/clang/Lex/LexHLSLRootSignature.h
+++ b/clang/include/clang/Lex/LexHLSLRootSignature.h
@@ -50,6 +50,10 @@ operator<<(const DiagnosticBuilder &DB, const RootSignatureToken::Kind Kind) {
   case RootSignatureToken::Kind::X:                                            \
     DB << SPELLING;                                                            \
     break;
+#define PUNCTUATOR(X, SPELLING)                                                \
+  case RootSignatureToken::Kind::pu_##X:                                       \
+    DB << #SPELLING;                                                           \
+    break;
 #include "clang/Lex/HLSLRootSignatureTokenKinds.def"
   }
   return DB;
diff --git a/clang/test/SemaHLSL/RootSignature-err.hlsl b/clang/test/SemaHLSL/RootSignature-err.hlsl
index f544247f4db2a..aec8a15f8ed7f 100644
--- a/clang/test/SemaHLSL/RootSignature-err.hlsl
+++ b/clang/test/SemaHLSL/RootSignature-err.hlsl
@@ -18,3 +18,7 @@ void bad_root_signature_3() {}
 
 [RootSignature("DescriptorTable(), invalid")] // expected-error {{expected end of stream to denote end of parameters, or, another valid parameter of RootSignature}}
 void bad_root_signature_4() {}
+
+// expected-error@+1 {{expected ')' to denote end of parameters, or, another valid parameter of RootConstants}}
+[RootSignature("RootConstants(b0, num32BitConstants = 1, invalid)")]
+void bad_root_signature_5() {}

@llvmbot
Copy link
Member

llvmbot commented Jun 26, 2025

@llvm/pr-subscribers-hlsl

Author: Finn Plummer (inbelic)

Changes

This pr will corrects the output with a stringified version of a puncuator (eg ')') instead of its ascii value.

  • Update LexHLSLRootSignature to fix the DiagnosticBuilder operator&lt;&lt; overload to correclty format the puncuator
  • Add testcase demonstrating the stringified version is output

Resolves #145814.


Full diff: https://github.com/llvm/llvm-project/pull/145827.diff

2 Files Affected:

  • (modified) clang/include/clang/Lex/LexHLSLRootSignature.h (+4)
  • (modified) clang/test/SemaHLSL/RootSignature-err.hlsl (+4)
diff --git a/clang/include/clang/Lex/LexHLSLRootSignature.h b/clang/include/clang/Lex/LexHLSLRootSignature.h
index 9275e0d75840b..9901485b44d38 100644
--- a/clang/include/clang/Lex/LexHLSLRootSignature.h
+++ b/clang/include/clang/Lex/LexHLSLRootSignature.h
@@ -50,6 +50,10 @@ operator<<(const DiagnosticBuilder &DB, const RootSignatureToken::Kind Kind) {
   case RootSignatureToken::Kind::X:                                            \
     DB << SPELLING;                                                            \
     break;
+#define PUNCTUATOR(X, SPELLING)                                                \
+  case RootSignatureToken::Kind::pu_##X:                                       \
+    DB << #SPELLING;                                                           \
+    break;
 #include "clang/Lex/HLSLRootSignatureTokenKinds.def"
   }
   return DB;
diff --git a/clang/test/SemaHLSL/RootSignature-err.hlsl b/clang/test/SemaHLSL/RootSignature-err.hlsl
index f544247f4db2a..aec8a15f8ed7f 100644
--- a/clang/test/SemaHLSL/RootSignature-err.hlsl
+++ b/clang/test/SemaHLSL/RootSignature-err.hlsl
@@ -18,3 +18,7 @@ void bad_root_signature_3() {}
 
 [RootSignature("DescriptorTable(), invalid")] // expected-error {{expected end of stream to denote end of parameters, or, another valid parameter of RootSignature}}
 void bad_root_signature_4() {}
+
+// expected-error@+1 {{expected ')' to denote end of parameters, or, another valid parameter of RootConstants}}
+[RootSignature("RootConstants(b0, num32BitConstants = 1, invalid)")]
+void bad_root_signature_5() {}

@@ -18,3 +18,7 @@ void bad_root_signature_3() {}

[RootSignature("DescriptorTable(), invalid")] // expected-error {{expected end of stream to denote end of parameters, or, another valid parameter of RootSignature}}
void bad_root_signature_4() {}

// expected-error@+1 {{expected ')' to denote end of parameters, or, another valid parameter of RootConstants}}
[RootSignature("RootConstants(b0, num32BitConstants = 1, invalid)")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I missing a detail here? The parens are matched in this test case right? If so this error message would send me down a very wrong path.

Maybe that is because I'm not familiar with rootsigs, maybe someone more familiar with them would understand the error better

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also I'm aware this comment isn't related to the actual fix of the PR so it's not blocking, just a side point

Copy link
Contributor Author

@inbelic inbelic Jun 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the feedback, when you work with the code for months and write the diagnostic it is always makes sense to yourself.

Note: There is some missing info here, as it doesn't have where the diagnostic is pointing in the source location.
In this case it would be pointing right after the comma, and the desired interpretation would be:
"after this comma it is expected that we should either have a ')' to denote the end of parameters or another valid parameter of RootConstants".

With that being said, I am very open to feedback and I can see the confusion!

I will create a todo to take another look at clarifying the diagnostic messages.

@inbelic inbelic merged commit 2e39959 into llvm:main Jun 26, 2025
12 checks passed
anthonyhatran pushed a commit to anthonyhatran/llvm-project that referenced this pull request Jun 26, 2025
… of punctuator tokens (llvm#145827)

This pr will corrects the output with a stringified version of a
puncuator (eg `')'`) instead of its ascii value.

- Update `LexHLSLRootSignature` to fix the `DiagnosticBuilder`
`operator<<` overload to correclty format the puncuator
- Add testcase demonstrating the stringified version is output

Resolves llvm#145814.
rlavaee pushed a commit to rlavaee/llvm-project that referenced this pull request Jul 1, 2025
… of punctuator tokens (llvm#145827)

This pr will corrects the output with a stringified version of a
puncuator (eg `')'`) instead of its ascii value.

- Update `LexHLSLRootSignature` to fix the `DiagnosticBuilder`
`operator<<` overload to correclty format the puncuator
- Add testcase demonstrating the stringified version is output

Resolves llvm#145814.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category HLSL HLSL Language Support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[HLSL][RootSignature] Fix formatting of puncuator Tokens in LexHLSL
4 participants