-
Notifications
You must be signed in to change notification settings - Fork 808
Fix typo of register -> registers crashes DXC with segfault #7729
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
base: main
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this also work with : register (u3); ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also would you be able to add a case for an incorrectly spelled pack offset?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and... packoffset allows unions apparently.
cbuffer ohno {
float a : packoffset(c0.x);
float b : packoffset(c0.x);
};There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)
bob80905
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look good, just one suggestion on the error message text.
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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()'?">; |
#6599
The issue is that it tries to parse a register definition as a semantic and the remainder
(space1)will be unrecognized and completely mess everything up.Instead, I still try to parse it as a register and give the errors you'd get if it was a real register. Of course it isn't a register, so the register assignment will get dropped and an error gets given instead:
Syntax similar to : register() was used but unexpected keyword 'registers' was used instead.