You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
cmd/compile: internal compiler error in midway rewriter on 'for range N' inside SIMD-using function #81264
The crash happens in CopySimpleStmt's *syntax.RangeClause handling at deepcopy.go:522-525:
} else {
newS.Lhs=c.CopyExpr(s.Lhs) // returns nil when s.Lhs is nil
}
newS.Lhs.SetPos(s.Lhs.Pos()) // panics: nil.SetPos() (and nil.Pos())
For the Go 1.22 integer-range form for range N (no LHS variable, not even _), s.Lhs is nil, so newS.Lhs becomes nil and both newS.Lhs.SetPos(...) and s.Lhs.Pos() on line 525 dereference nil.
Trigger matrix
Code inside function
Result
for range 1 {} in a function that references a simd.* type
crash
for i := range 1 { _ = i } in the same function
ok
for j := 0; j < 1; j++ {} in the same function
ok
for range 1 {} in a package that uses no SIMD types
ok
So the trigger is: (a) the enclosing function is rewritten by the midway pass — any use of a SIMD type is sufficient — AND (b) the loop is an integer-range with no LHS.
Suggested fix
Guard both the copy and the SetPos on s.Lhs != nil:
ifs.Lhs!=nil {
// existing dispatch on ListExpr / Name / elsenewS.Lhs.SetPos(s.Lhs.Pos())
}
It seems to me we could just remove that newS.Lhs.SetPos(s.Lhs.Pos()) entirely, since both c.CopyName and c.CopyExpr return the copied node with position already set.
Activity
gabyhelp commentedon Sep 1, 2026
Related Issues
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
cuonglm commentedon Sep 1, 2026
It seems to me we could just remove that
newS.Lhs.SetPos(s.Lhs.Pos())entirely, since bothc.CopyNameandc.CopyExprreturn the copied node with position already set.gopherbot commentedon Sep 1, 2026
Change https://go.dev/cl/825524 mentions this issue:
cmd/compile: fix ICE with for range clause in midway passcmd/compile: fix ICE with for range clause in midway pass