Skip to content

cl: preserve recover-visible panic source lines - #2293

Open
cpunion wants to merge 5 commits into
xgo-dev:mainfrom
cpunion:codex/goroot-panic-pcline-20260811
Open

cl: preserve recover-visible panic source lines#2293
cpunion wants to merge 5 commits into
xgo-dev:mainfrom
cpunion:codex/goroot-panic-pcline-20260811

Conversation

@cpunion

@cpunion cpunion commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • retain same-package synchronous call paths whose panic PCs can be observed by a recovering defer
  • emit statement PC anchors at existing implicit panic sites without broadening panic generation
  • enable 5 unique GOROOT compatibility cases, removing 15 platform/version xfail entries

GOROOT cases

  • fixedbugs/bug347.go
  • fixedbugs/bug348.go
  • fixedbugs/issue27201.go
  • fixedbugs/issue29504.go
  • fixedbugs/issue4562.go

Scope

Depends on #2034 for the recover-time panic stack snapshot. The new work is kept in four layered commits: regression tests, implementation, tracking-rule documentation, and xfail cleanup.

This intentionally excludes the nil-check cases handled by #2256 and unrelated GC/finalizer timing failures.

Validation

  • go test ./cl -run "TestRuntimeCallerFuncSetKeepsRecoverObservableCallees|TestCompileRuntimeCallerPanicPCLineMetadata|TestRuntimeCallerPackageDetection|TestRuntimeCallerAnalysisEdgeCases" -count=1
  • go test -vet=off ./test/go -run "^TestRuntimeStatementLineInfo$" -count=1
  • macOS/arm64, Go 1.26.5: all 5 GOROOT cases passed with empty xfail/not-applicable files
  • Linux/arm64, Go 1.26.5: all 5 GOROOT cases passed with empty xfail/not-applicable files
  • Linux/amd64, Go 1.26.5: PR primary build, both test shards, release artifact test, and coverage passed

@cpunion cpunion added the go-test-compat Go standard-library and GOROOT test compatibility label Aug 11, 2026

@fennoai fennoai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review summary

Careful, well-documented rework of LLGo's recover/panic model: a panicNode linked list on g, per-invocation recover-frame binding, transparent-wrapper aliasing, volatile recover slots, and a conservative mayRecover propagation across cl/, ssa/, and the runtime. The PanicTypeAssert signature change is applied uniformly (verified against the _testrt/_testgo CHECK lines), and nil-handling in the new SSA helpers is solid and test-covered (ssa/recover_metadata_test.go). SIGBUS wiring (SIGBUS != 0 guard + per-platform constants, Linux 0x7, Darwin 0xa) is correct.

One correctness divergence and a few compile-time performance notes are inline. No memory-safety defects were found in the moveToDefer/Recover/abortPanics unlink-and-free ordering.

Non-blocking confirmation (pre-existing, not changed here): Panic still stores the panic value in a non-GC c.Malloc'd node (arg any, z_rt.go:~204), same as before this PR. Since deferred functions run arbitrary allocating user code between the longjmp and Recover, the panic value's GC reachability while a panic is in flight is worth confirming — but this property predates the PR and is out of its scope.

Comment thread runtime/internal/runtime/z_baremetal.go
Comment thread cl/compile.go Outdated
Comment thread cl/compile.go Outdated
Comment thread cl/instr.go Outdated
Comment thread cl/instr.go Outdated
@github-actions

github-actions Bot commented Aug 11, 2026

Copy link
Copy Markdown

LLGo baseline benchmarks

58e3ace843f6 | workflow run | long-term charts

Program measurements

Platform Workload File size vs base Build vs base Run vs base
Linux cprintf 18656 B +0.0% 310.592 ms +0.6% (worse) 1.363 ms -0.1% (better)
Linux fmtprintf 4561936 B +142.4% (worse) 3.498 s +13.1% (worse) 9.780 ms +83.2% (worse)
Linux println 68512 B +0.0% 311.598 ms +1.1% (worse) 1.761 ms -0.7% (better)
macOS cprintf 84672 B +0.0% 320.115 ms +4.1% (worse) 2.495 ms -26.5% (better)
macOS fmtprintf 2990064 B +58.3% (worse) 2.507 s +10.3% (worse) 13.919 ms +13.9% (worse)
macOS println 121216 B +0.0% 294.650 ms +4.7% (worse) 3.097 ms +2.9% (worse)
Core language and compiler benchmarks
Platform Benchmark ns/op vs base
Linux BenchmarkLookupPCRandom 12.260 ns/op +0.0%
Linux BenchmarkMergeCompilerFlags 145.600 ns/op +0.4% (worse)
Linux BenchmarkMergeLinkerFlags 98.050 ns/op +3.7% (worse)
Linux BenchmarkChannelBuffered 36.390 ns/op -0.4% (better)
Linux BenchmarkChannelHandoff 25477 ns/op +5.7% (worse)
Linux BenchmarkDefer 48.370 ns/op -7.2% (better)
Linux BenchmarkDirectCall 1.757 ns/op -0.1% (better)
Linux BenchmarkGlobalRead 1.757 ns/op -0.1% (better)
Linux BenchmarkGlobalWrite 2.805 ns/op -0.0% (better)
Linux BenchmarkGoroutine 29778 ns/op -1.1% (better)
Linux BenchmarkInterfaceCall 8.443 ns/op -1.3% (better)
Linux BenchmarkRuntimeGetG 2.116 ns/op -14.0% (better)
macOS BenchmarkLookupPCRandom 10.670 ns/op -1.1% (better)
macOS BenchmarkMergeCompilerFlags 108.800 ns/op -31.8% (better)
macOS BenchmarkMergeLinkerFlags 59.760 ns/op -25.9% (better)
macOS BenchmarkChannelBuffered 20.420 ns/op -4.4% (better)
macOS BenchmarkChannelHandoff 6089 ns/op -4.8% (better)
macOS BenchmarkDefer 24.580 ns/op -12.6% (better)
macOS BenchmarkDirectCall 0.946 ns/op -6.6% (better)
macOS BenchmarkGlobalRead 1.016 ns/op -2.4% (better)
macOS BenchmarkGlobalWrite 0.945 ns/op -8.8% (better)
macOS BenchmarkGoroutine 24367 ns/op -19.9% (better)
macOS BenchmarkInterfaceCall 4.089 ns/op -9.7% (better)
macOS BenchmarkRuntimeGetG 1.887 ns/op -9.8% (better)

Compared with 6bc422655d08 measured in the same runner job.

@codecov

codecov Bot commented Aug 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.55556% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cl/instr.go 94.87% 2 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@cpunion
cpunion force-pushed the codex/goroot-panic-pcline-20260811 branch 2 times, most recently from 3ccd9d5 to bc06013 Compare August 11, 2026 04:52
@cpunion
cpunion force-pushed the codex/goroot-panic-pcline-20260811 branch from bc06013 to e60b5fc Compare August 11, 2026 04:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go-test-compat Go standard-library and GOROOT test compatibility

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant