Repository navigation
Preserve qualifiers on array subscript - #4159
Chris B (llvm-beanz) merged 2 commits into
Conversation
Grace Jennings (gracejennings)
left a comment
There was a problem hiding this comment.
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.
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.
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.
There was a problem hiding this comment.
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