Skip to content

Commit

Permalink
internal/shader: bug fix: xor-assignment operator didn't work correctly
Browse files Browse the repository at this point in the history
Closes #3140
  • Loading branch information
hajimehoshi committed Oct 21, 2024
1 parent d69d079 commit aeff4c2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion internal/shader/stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,12 @@ func (cs *compileState) parseStmt(block *block, fname string, stmt ast.Stmt, inP
if op == shaderir.And || op == shaderir.Or || op == shaderir.Xor || op == shaderir.LeftShift || op == shaderir.RightShift {
if lts[0].Main != shaderir.Int && !lts[0].IsIntVector() {
cs.addError(stmt.Pos(), fmt.Sprintf("invalid operation: operator %s not defined on %s", stmt.Tok, lts[0].String()))
return nil, false
}
if rts[0].Main != shaderir.Int && !rts[0].IsIntVector() {
cs.addError(stmt.Pos(), fmt.Sprintf("invalid operation: operator %s not defined on %s", stmt.Tok, rts[0].String()))
return nil, false
}
return nil, false
}
if lts[0].Main == shaderir.Int && rhs[0].Const != nil {
if !cs.forceToInt(stmt, &rhs[0]) {
Expand Down
6 changes: 6 additions & 0 deletions internal/shader/testdata/xorassign.expected.vs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
int F0(in int l0);

int F0(in int l0) {
l0 = (l0) ^ (l0);
return l0;
}
6 changes: 6 additions & 0 deletions internal/shader/testdata/xorassign.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package main

func Foo(x int) int {
x ^= x
return x
}

0 comments on commit aeff4c2

Please sign in to comment.