From 74f812dd33e6c978f2af17fc41ec7c70e929609a Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 21 Oct 2024 14:53:53 +0900 Subject: [PATCH] internal/shader: bug fix: xor-assignment operator didn't work correctly Closes #3140 --- internal/shader/stmt.go | 3 ++- internal/shader/testdata/xorassign.expected.vs | 6 ++++++ internal/shader/testdata/xorassign.go | 6 ++++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 internal/shader/testdata/xorassign.expected.vs create mode 100644 internal/shader/testdata/xorassign.go diff --git a/internal/shader/stmt.go b/internal/shader/stmt.go index 448aef3e6..e7f87250a 100644 --- a/internal/shader/stmt.go +++ b/internal/shader/stmt.go @@ -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]) { diff --git a/internal/shader/testdata/xorassign.expected.vs b/internal/shader/testdata/xorassign.expected.vs new file mode 100644 index 000000000..8e4668719 --- /dev/null +++ b/internal/shader/testdata/xorassign.expected.vs @@ -0,0 +1,6 @@ +int F0(in int l0); + +int F0(in int l0) { + l0 = (l0) ^ (l0); + return l0; +} diff --git a/internal/shader/testdata/xorassign.go b/internal/shader/testdata/xorassign.go new file mode 100644 index 000000000..1df02805e --- /dev/null +++ b/internal/shader/testdata/xorassign.go @@ -0,0 +1,6 @@ +package main + +func Foo(x int) int { + x ^= x + return x +}