-
Notifications
You must be signed in to change notification settings - Fork 714
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
Preserve qualifiers on array subscript #4159
Preserve qualifiers on array subscript #4159
Conversation
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!
This change prevents dropping const qualifiers on array subscript operators. Without this change the array subscript operator converts from an lvalue to an rvalue that drops the type qualifiers. Since arrays are actually addresses to the start of the array, it results in dropping the qualifiers on the underlying array, making the array modifyable.
This test was added to verify the compiler doesn't crash in the HLSL SROA pass when writing to InputPatch objects, but InputPatch objects are defined to be constant and should not be writeable.
8fce2aa
to
34bdfc3
Compare
points[0].norm[0] = 1; | ||
points[0].norm[1] = 2; | ||
points[0].norm[0] = 1; // expected-error {{read-only variable is not assignable}} | ||
points[0].norm[1] = 2; // expected-error {{read-only variable is not assignable}} |
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.
I don't think points should be considered const. Or is our subscript operator returning the wrong type here? I believe this is incompatible with fxc with this change.
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.
The docs for InputPatch’s operator[] say “ Gets a read-only resource variable.”, and our implementation returns const.
If that’s not correct we can fix our InputPatch implementation, but that should be orthogonal to this change.
See: https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/sm5-object-inputpatch
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.
I just checked and it turns out FXC doesn't like this code either. Strange as I thought I'd seen this pattern somewhere, and thought this came from some sample (since it's under a path with that implication). So it's all good!
This change prevents dropping const qualifiers on array subscript
operators. Without this change the array subscript operator converts
from an lvalue to an rvalue that drops the type qualifiers. Since
arrays are actually addresses to the start of the array, it results in
dropping the qualifiers on the underlying array, making the array
modifiable.
This resolves #2860