Repository navigation
compiler: report errors for misused pragmas - #5936
Merged
Merged
Conversation
Before this change, most pragmas silently did nothing when they had extra parameters, were on the wrong kind of function, or were in a package that does not import unsafe. A //go:align without a parameter caused a panic. These mistakes are easy to make and hard to find, because the build passes and only the generated code is different. Flag pragmas such as //go:noinline and //go:noheap now reject parameters with one shared check. Each pragma then checks its own placement rules. The rules for //go:noescape are the same as in gc. The checks for the other pragmas follow the conditions that TinyGo already used to decide whether to apply them.
Contributor
Author
|
Thanks for merging #5894 , that change unblocked this which adds stricter validation for pragmas rather than silently ignoring them. |
dgryski
approved these changes
Oct 19, 2026
Member
|
Thanks for the addition @davecheney and to @dgryski for review. Now merging. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Report malformed pragma parameters and invalid placements instead of silently ignoring them. Reject invalid global extern, align, and section parameters without panicking.
Use source AST bodies for function placement checks, including generic origins and unbuilt dependencies. Preserve package-level unsafe gating and report each source pragma error once.
Add regression coverage for declarations, definitions, methods, generic instantiations, and exact diagnostics.
Verified with
TINYGOROOT="$PWD" go test -tags=llvm22 ./cgo ./compiler ./transform -count=1and the root pragma, noruntime, and noruntime-use error tests.