Skip to content

Conversation

@Nielsbishere
Copy link
Contributor

#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.

…'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.
@github-actions
Copy link
Contributor

github-actions bot commented Sep 3, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@s-perron
Copy link
Collaborator

s-perron commented Nov 4, 2025

/AzurePipelines run

@azure-pipelines
Copy link

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);
Copy link
Collaborator

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); ?

Copy link
Collaborator

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?

Copy link
Contributor Author

@Nielsbishere Nielsbishere Nov 5, 2025

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...

Copy link
Collaborator

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.

Copy link
Contributor Author

@Nielsbishere Nielsbishere Nov 5, 2025

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);
};

Copy link
Contributor Author

@Nielsbishere Nielsbishere Nov 5, 2025

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);
Copy link
Collaborator

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)
Copy link
Collaborator

@bob80905 bob80905 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@hekota hekota left a 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.

Comment on lines +1028 to +1029
def err_hlsl_expected_hlsl_attribute : Error <
"Syntax indicated an hlsl attribute (: packoffset() or : register()), but unexpected attribute '%0' was used instead.">;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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 hekota self-assigned this Nov 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

4 participants