Skip to content

cmd/compile: prove pass misses bounds checks across 32/64-bit integer conversions #81390

Open

Description

@Lnoot

When indexing a slice with a 32-bit integer after checking against uint32(len(s)) or int32(len(s)), the prove pass fails to eliminate the bounds check on 64-bit architectures:

func f(s []byte, x uint32, y int32) byte {
    if uint32(len(s)) > x {
        _ = s[x] // bounds check not eliminated
    }
    if y >= 0 && int32(len(s)) > y {
        return s[y] // bounds check not eliminated
    }
    return 0
}

Because addValueFact does not record relational facts for OpTrunc*, OpZeroExt*, or OpSignExt* in the poset, inequalities established on narrow integers are lost when zero- or sign-extended back to 64-bit for slice indexing.

Recording these relations in addValueFact eliminates 41 bounds checks across std (primarily in debug/elf, debug/macho, debug/pe, and encoding/binary).

Activity

  1. gopherbot commented on Sep 8, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/829264 mentions this issue: cmd/compile: record poset relations for integer conversions in prove pass

  2. JunyangShao commented on Sep 11, 2026

    @JunyangShao
    Contributor

    @golang/compiler

  3. added
    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
    on Sep 11, 2026
  4. gopherbot commented on Sep 25, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/838825 mentions this issue: cmd/compile: propagate bitwise AND limits and slice/div/mod poset relations

  5. gopherbot commented on Sep 25, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/838826 mentions this issue: cmd/compile: prove subslice bounds for constant-delta and negative-offset additions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.compiler/runtimeIssues related to the Go compiler and/or runtime.

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions