internal/shader: bug fix: xor-assignment operator didn't work correctly

Closes #3140
This commit is contained in:
Hajime Hoshi 2024-10-21 14:53:53 +09:00
parent 366f4899a2
commit 74f812dd33
3 changed files with 14 additions and 1 deletions

View File

@ -117,12 +117,13 @@ 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 op == shaderir.And || op == shaderir.Or || op == shaderir.Xor || op == shaderir.LeftShift || op == shaderir.RightShift {
if lts[0].Main != shaderir.Int && !lts[0].IsIntVector() { 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())) 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() { 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())) 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 lts[0].Main == shaderir.Int && rhs[0].Const != nil {
if !cs.forceToInt(stmt, &rhs[0]) { if !cs.forceToInt(stmt, &rhs[0]) {
return nil, false return nil, false

View File

@ -0,0 +1,6 @@
int F0(in int l0);
int F0(in int l0) {
l0 = (l0) ^ (l0);
return l0;
}

6
internal/shader/testdata/xorassign.go vendored Normal file
View File

@ -0,0 +1,6 @@
package main
func Foo(x int) int {
x ^= x
return x
}