Skip to content

Fix slice-to-array conversion panics#1899

Draft
cpunion wants to merge 2 commits into
xgo-dev:mainfrom
cpunion:codex/goroot-convert-coverage
Draft

Fix slice-to-array conversion panics#1899
cpunion wants to merge 2 commits into
xgo-dev:mainfrom
cpunion:codex/goroot-convert-coverage

Conversation

@cpunion
Copy link
Copy Markdown
Collaborator

@cpunion cpunion commented May 22, 2026

Summary

  • pass slice-to-array conversion panic helper arguments as target length, slice length
  • preserve nil-deref side effects for unused slice derefs produced by zero-length slice-to-array conversions
  • make explicit nil-deref assertions recover as runtime errors, matching signal-based nil pointer panics
  • add focused test/go coverage and remove fixed convert4.go goroot xfails

Tests

  • go test ./test/go -run 'TestSliceToArrayConversion' -count=1
  • go test ./ssa -count=1
  • go test ./cl -run 'TestRunAndTestFromTestrt|TestSkipUnusedArrayDeref' -count=1
  • (cd runtime && go test ./internal/runtime -count=1)
  • go run ./cmd/llgo test -run 'TestSliceToArrayConversion' ./test/go
  • go test ./test/goroot -count=1 -run TestGoRootRunCases -args -goroot "$(go env GOROOT)" -dirs . -case '^convert4\.go$' -directive-mode legacy -xfail /tmp/llgo-empty-xfail.yaml -progress 30s
  • go test ./test/goroot -count=1 -run TestGoRootRunCases -args -goroot "$(go env GOROOT)" -dirs . -case '^convert4\.go$' -directive-mode legacy -progress 30s

Notes

  • Local GOROOT source: $(go env GOROOT) ($(go env GOVERSION), $(go env GOOS)/$(go env GOARCH)).
  • Full GOROOT CI is slow/disabled; this PR relies on normal PR CI plus the targeted convert4.go goroot run above.
  • Stable coverage is in test/go/slice_array_convert_test.go, so the fix is not covered only by test/goroot.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 22, 2026

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 98.21429% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cl/compile.go 87.50% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@cpunion
Copy link
Copy Markdown
Collaborator Author

cpunion commented May 24, 2026

Conversion-only update for this draft PR.

Changes in f1f0a989d18194c1f220fd83cf858db7aba17149:

  • Fixed float-to-integer conversion bounds in SSA codegen: signed targets saturate with NaN -> 0; uint32/uint64/uintptr clamp negative/NaN to 0 and overflow/Inf to max; narrow unsigned targets keep the signed-intermediate truncation behavior needed for Go compatibility.
  • Added stable test/go coverage in TestFloatToIntegerConversionSemantics.
  • Updated IR/runtime fixtures affected by the conversion lowering.
  • Removed goroot xfails for convert5.go and convinline.go. convert4.go was already passing. Kept only the existing darwin convinline.go timeout entries because those are timeout controls, not conversion failures.

Goroot case status:

  • convert4.go: passes without xfail.
  • convert5.go: passes without xfail after this fix.
  • convinline.go: passes without xfail; this shared the same float-to-int conversion root cause, not a separate runoutput generation fix.

Local validation:

  • go test ./test/go -count=1
  • go test ./ssa -count=1
  • go test ./cl -count=1
  • go test ./ssa -run TestFromTestrt/cast -count=1 -v
  • go test ./cl -run TestRunAndTestFromTestrt/cast -count=1 -v
  • go test ./test/goroot -run TestGoRootRunCases -count=1 -args -goroot /Users/lijie/sdk/go1.26.0 -dirs . -case '^(convert4|convert5|convinline)\\.go$' -directive-mode ci -xfail /tmp/llgo-no-xfail.yaml -run-timeout 4m -progress 30s
  • Previously also spot-checked convinline.go without xfail on local Go 1.24.11 and Go 1.25.0.

PR is still draft. CI has started on the new head.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants