Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ line upon naming the release. Refer to previous for appropriate section names.

- Fixed an optimizer crash when scalarizing an out-of-bounds vector access
[#8940](https://github.com/microsoft/DirectXShaderCompiler/issues/8940).
- Assigning to a conditional operator on objects, such as `(c ? a : b) = buf`
with resources, is now an "expression is not assignable" error like for
other types, instead of asserting or being silently dropped
[#8579](https://github.com/microsoft/DirectXShaderCompiler/issues/8579).

### Upcoming Preview Release

Expand Down
8 changes: 7 additions & 1 deletion tools/clang/lib/Sema/SemaHLSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11159,8 +11159,14 @@ HLSLExternalSource::CheckVectorConditional(ExprResult &Cond, ExprResult &LHS,
rightObjectKind == AR_TOBJ_MATRIX;

if (!leftIsSimple || !rightIsSimple) {
if (leftObjectKind == AR_TOBJ_OBJECT && leftObjectKind == AR_TOBJ_OBJECT) {
if (leftObjectKind == AR_TOBJ_OBJECT && rightObjectKind == AR_TOBJ_OBJECT) {
if (leftType == rightType) {
// As for the other types, the result is not an lvalue, so it can't be
// assigned to.
if (LHS.get()->isLValue())

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I believe we want to gate this behavior on the language version, and preserve this older behavior, according to this document:
https://hlsl-tc57.github.io/tc57/proposal/0017/
See if you can add a condition here to ensure that the language version is at least 202x.

LHS.set(CreateLValueToRValueCast(LHS.get()));
if (RHS.get()->isLValue())
RHS.set(CreateLValueToRValueCast(RHS.get()));
return leftType;
}
}
Expand Down
22 changes: 22 additions & 0 deletions tools/clang/test/SemaHLSL/conditional-object-not-assignable.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// RUN: %dxc -Tcs_6_0 -verify %s

// Like for scalars, vectors and matrices, a conditional operator on objects
// yields an rvalue, so it can't be assigned to.

RWByteAddressBuffer gBuf0 : register(u0);
RWByteAddressBuffer gBuf1 : register(u1);

[numthreads(1, 1, 1)]
void main(uint3 tid : SV_DispatchThreadID) {
RWByteAddressBuffer a = gBuf0;
RWByteAddressBuffer b = gBuf1;
(true ? a : b) = gBuf1; /* expected-error {{expression is not assignable}} */

uint x = 1, y = 2;
(true ? x : y) = 5; /* expected-error {{expression is not assignable}} */

// Using the result as an rvalue is still fine.
RWByteAddressBuffer c = true ? a : b;
c.Store(0, 1);
(false ? a : b).Store(4, 2);
}
Loading