Skip to content
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

Passing string literal to templated function causes validation errors when optimizations are disabled #6154

Open
mateeeeeee opened this issue Jan 16, 2024 · 3 comments
Labels
bug Bug, regression, crash incorrect-code Issues relating to handling of incorrect code

Comments

@mateeeeeee
Copy link

mateeeeeee commented Jan 16, 2024

Description
Passing string literal to templated function causes validation errors when optimizations are disabled (using -Od) but works fine with optimizations enabled.

Steps to Reproduce
Minimal reproducible example: godbolt

I am not sure what is expected behavior, should the dxc reject or accept the code but it should behave the same despite different optimization flags.

Environment

  • DXC version 1.7.2207, 1.7.2308
  • Windows 21H2
@mateeeeeee mateeeeeee added bug Bug, regression, crash needs-triage Awaiting triage labels Jan 16, 2024
@pow2clk pow2clk added incorrect-code Issues relating to handling of incorrect code and removed needs-triage Awaiting triage labels Jan 17, 2024
@llvm-beanz
Copy link
Collaborator

This only "works" with optimized code because we optimize the string away entirely. Strings are not supported in HLSL, but our enforcement of that is post-optimization. We should error about strings earlier.

@KStocky
Copy link

KStocky commented Feb 18, 2024

I assume if you were to error about strings earlier then strings used for rootsignatures would need to be treated as a special case then?

@llvm-beanz
Copy link
Collaborator

I assume if you were to error about strings earlier then strings used for rootsignatures would need to be treated as a special case then?

Not any more than they already are. String-literal arguments to attributes aren't really strings (i.e. you can't declare a string variable and pass it to an attribute). Here's a C++ example using MSVC's UUID attribute.

Attribute grammars aren't yet documented in the HLSL draft specification, but I have written down the parsing grammar for the C++ attributes that I want to include in HLSL 202x here (microsoft/hlsl-specs#65). The really relevant bit is that attribute arguments are balanced-token which means they're grammar tokens not typed literal expressions.

That all said, I don't think we're likely to change how we handle strings in DXC (even if it isn't strictly accurate), because we do want to someday support string literals for printf. We're resource constrained enough that I'd rather we leave this bug lie around for a while and resolve issues with strings as part of larger feature work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug, regression, crash incorrect-code Issues relating to handling of incorrect code
Projects
Status: Triaged
Development

No branches or pull requests

4 participants