Skip to content

x/tools/go/analysis/passes/unsafeptr: verify that unsafe pointer arithmetic happens within one expression #76657

@DanielMorsing

Description

@DanielMorsing

From the unsafe.Pointer docs:

Note that both conversions must appear in the same expression, with only the intervening arithmetic between them:

// INVALID: uintptr cannot be stored in variable
// before conversion back to Pointer.
u := uintptr(p)
p = unsafe.Pointer(u + offset)

I have definitely seen (and written) this idiom before in the runtime code (although a specific example eludes me at the moment). We should verify this in the unsafeptr analysis pass

Metadata

Metadata

Assignees

No one assigned

    Labels

    AnalysisIssues related to static analysis (vet, x/tools/go/analysis)FeatureRequestIssues asking for a new feature that does not need a proposal.ToolsThis label describes issues relating to any tools in the x/tools repository.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions