Skip to content

cmd/compile: unnecessary bounds check when indexing relative to the end #51622

Closed
@dsnet

Description

@dsnet

Using go1.17.5

Consider the following:

len(b) >= 3 && b[len(b)-3] == '#'

Part of the assembly includes:

0x002f 00047 (main.go:6)	CALL	runtime.panicIndex(SB)

This should be unnecessary since the previous len(b) >= 3 check ensures that the buffer must contain the len(b)-3 element. Thus, there is no possibility of the index panicking.

\cc @martisch @randall77

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions