Skip to content

False positives on stack-local variables (named returns, parameters, locals) #20

@kolkov

Description

@kolkov

Problem

The racedetector reports false positive data races on stack-local variables that cannot actually have data races because each goroutine has its own stack.

Affected Patterns

Fixed in v0.7.2 (Quick Fix)

  • ✅ Named return values: func foo() (result int, err error)
  • ✅ Function parameters: func process(x int)

Still Affected (Phase 2)

  • ❌ Local variables: var x int inside function
  • ❌ Loop variables: for i, v := range items
  • ❌ Short-lived variables in expressions

Root Cause

Our AST-based instrumentor lacks escape analysis that the standard Go race detector has (SSA-based with full type information). We instrument ALL variable accesses without knowing if they're stack-local or heap-allocated.

See internal analysis document: FALSE_POSITIVES_ANALYSIS.md

Solution Roadmap

  • Phase 1 (v0.7.2): Skip named returns and parameters
  • Phase 2: Add heuristics for loop variables, short-lived locals
  • Phase 3: Integrate go/types for escape analysis

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions