cmd/compile: validate noescape function bodies - #2220
Conversation
There was a problem hiding this comment.
Review: cmd/compile: validate noescape function bodies
Focused, well-tested change. The directive-scanning logic in internal/packages/pragma.go and the error-gating in loadPackageEx correctly mirror cmd/compile semantics, and the new unit + e2e tests cover the tricky cases (blank-line/comment separation, method///line positions, phase ordering). go test ./internal/packages passes.
A few things I verified that are not problems, for the record:
- Tab-separated argument (
//go:noescape\tignored→ no error, per the test): this matches gc. cmd/compile splits the pragma verb on a literal space only (strings.Index(text, " ")innoder.go), sogo:noescape\tignoredis not recognized asgo:noescapeand a body is not flagged. Thenext == ' 'check is correct here — even thoughisEmbedDirectiveCommentin the same package accepts\t(embed usespragmaFields/isSpace, a different tokenizer). No change needed. errsin thehasSourceErrorsexpression compiles and is in scope (theparseFilesresult). It is slightly redundant with the laterParseErrorscan overlpkg.Errors, but harmless.xfail.yamlremoval offixedbugs/issue18331.go: the errorcheck case also asserts three "is not allowed in the standard library" diagnostics for unknown pragmas that this PR does not implement directly. Those come through from thego listdriver (which is exactly why it stops early before the body check — the scenario this PR targets), so the removal is justified.
Only two minor, low-severity notes inline. No blocking issues.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
CI triage: the Ubuntu Go 1.24 compatibility failure is in Install embedded dependencies → Verify ESP QEMU, before this PR’s tests run: |
cc2236c to
2536a7c
Compare
|
Closing because |
Summary
//go:noescapebody restriction in the source loader when an earlier compiler diagnostic makesgo liststop before reporting it//lineposition semanticsfixedbugs/issue18331.gofrom the Go 1.26 GOROOT xfail listTests and coverage
go test ./internal/packages ./internal/build ./cmd/internal/compile -count=1go test ./internal/packages ./cmd/internal/compile -count=1go test ./test/goroot -count=1fixedbugs/issue18331.goandfixedbugs/issue48097.goNo functional dependency on another PR. #2201 only has a separate test-file overlap; #2218 and #2219 touch different
xfail.yamlentries.CI environment note: #2215 has landed on
mainwith the isolated Ubuntu ESP QEMU package-install fix. This PR does not contain any CI changes.