Fix typo of register -> registers crashes DXC with segfault #7729
Conversation
…'t segfault the compiler anymore. Instead, it assumes that when you write : MYTEST() that you're intending to make it into a register, will parse the register the normal way to skip invalid syntax and will show an error that you shouldn't do that.
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
…iler into fix_registers_segfault
|
/AzurePipelines run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
| // RUN: %dxc -T lib_6_3 -verify %s | ||
|
|
||
| // expected-error@+1 {{Syntax similar to : register() was used but unexpected keyword 'registers' was used instead.}} | ||
| RWStructuredBuffer<float4> uav1 : registers(u3); |
There was a problem hiding this comment.
Does this also work with : register (u3); ?
There was a problem hiding this comment.
Also would you be able to add a case for an incorrectly spelled pack offset?
There was a problem hiding this comment.
Wow I think you're correct there, I've never heard of that syntax before. Will fix it and add a test for it.
: register (u3) uses the same parsing as before (I only moved it), so that should still work. I can still add a test for it though.
The pack offset is pretty annoying, because from what I saw in #hlsl code horrors... I'll let the code speak for itself:
struct PSInput {
float4 color : COLOR;
};
cbuffer test {
Texture2D horrors : register(t0);
};
float4 PSMain(PSInput input) : SV_TARGET {
return input.color * horrors[0.xx];
}So I can't automatically exclude this error when it's parsing a constant buffer. I guess the way would be to fallback to parsing that syntax (packoffset syntax) if it fails to be parsed as a register...
There was a problem hiding this comment.
Ah yes, HLSL horrors beyond comprehension.
I meant adding a test case for packoffset, not exactly sure what you mean by fix it.
You might consider making the error diagnostic more generic, like "unexpected identifier %s, expected an hlsl attribute " or something to that effect. That way if the packoffset parsing fails you can reuse the same error.
I'm not sure falling back would work either because we only attempt to parse the register if the next token is detected to be a register token.
There was a problem hiding this comment.
and... packoffset allows unions apparently.
cbuffer ohno {
float a : packoffset(c0.x);
float b : packoffset(c0.x);
};There was a problem hiding this comment.
What I mean is that packoffset likely will get unintentionally parsed as register() as you suggested. I think I might be able to correctly identify it's misspelled packoffset as long as the rest of the syntax is similar.
…ork for packoffset and register. This simplifies it a ton, at the cost of being able to detect further register or packoffset errors, but at least it doesn't crash.
| cbuffer buf { | ||
|
|
||
| // expected-error@+1 {{Syntax indicated an hlsl attribute (: packoffset() or : register()), but unexpected attribute 'packofset' was used instead.}} | ||
| float4 v0 : packofset(c0); |
There was a problem hiding this comment.
Would you be able to add packoffsets so that it is tested the same way like registers?
I.E., a correct spelling with extra garbage at the end of the token.
This is effectively duplicating testing UNDEFINED_MACRO as is.
…alid packoffset syntax (same test as with uav2)
| def err_hlsl_expected_hlsl_attribute : Error < | ||
| "Syntax indicated an hlsl attribute (: packoffset() or : register()), but unexpected attribute '%0' was used instead.">; |
There was a problem hiding this comment.
| def err_hlsl_expected_hlsl_attribute : Error < | |
| "Syntax indicated an hlsl attribute (: packoffset() or : register()), but unexpected attribute '%0' was used instead.">; | |
| def err_hlsl_expected_hlsl_attribute : Error < | |
| "Unexpected `(` in semantic annotation. Did you mean 'packoffset()' or 'register()'?">; |
|
@hekota updated description, better? |
Great! Thank you :) |
|
/AzurePipelines run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Fix crash when parsing mistyped HLSL semantics (e.g.
registers()).Add diagnostic for unexpected '(' in semantic annotation and skip safely.
Add tests for common misspellings/macros that previously caused a segfault.
Fixes #6599