Skip to content

Preserve qualifiers on array subscript - #4159

Merged
Chris B (llvm-beanz) merged 2 commits into
microsoft:masterfrom
llvm-beanz:cbieneman/array-preserve-qualifiers
Dec 30, 2021
Merged

Chris B (llvm-beanz) merged 2 commits into
microsoft:masterfrom
llvm-beanz:cbieneman/array-preserve-qualifiers

Conversation

@llvm-beanz

Copy link
Copy Markdown
Collaborator

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

@AppVeyorBot

Copy link
Copy Markdown

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@llvm-beanz
Chris B (llvm-beanz) deleted the cbieneman/array-preserve-qualifiers branch December 22, 2021 00:47
@llvm-beanz
Chris B (llvm-beanz) restored the cbieneman/array-preserve-qualifiers branch December 22, 2021 00:47
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.
@llvm-beanz
Chris B (llvm-beanz) force-pushed the cbieneman/array-preserve-qualifiers branch from 8fce2aa to 34bdfc3 Compare December 22, 2021 00:50
@AppVeyorBot

Copy link
Copy Markdown

@llvm-beanz
Chris B (llvm-beanz) merged commit 36764f6 into microsoft:master Dec 30, 2021
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}}

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Collaborator Author

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

Copy link
Copy Markdown
Contributor

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!

@llvm-beanz
Chris B (llvm-beanz) deleted the cbieneman/array-preserve-qualifiers branch July 19, 2024 23:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DXC allows assigning to members of a const struct variable

4 participants