Skip to content

cmd/compile: odd bounds check elimination #25537

@zhengxiaoyao0716

Description

@zhengxiaoyao0716

What version of Go are you using (go version)?

image

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

image

image

What did you do?

package main

// Closure .
func Closure(as []interface{}, bs []interface{}) {
	_ = func() {
		_ = as[:len(as)] // [L6:9] checked?
		_ = bs[:len(bs)] // [L7:9] checked?
		// swap
		_ = as[:len(bs)] // checked, that's right.
		_ = bs[:len(as)] // checked, that's right.
	}
}

// NoClosure .
func NoClosure(as []interface{}, bs []interface{}) {
	_ = as[:len(as)] // eliminatd, that's right.
	_ = bs[:len(bs)] // eliminatd, that's right.
	// swap
	_ = as[:len(bs)] // checked, that's right.
	_ = bs[:len(as)] // checked, that's right.
}

// ClosureAssert .
func ClosureAssert(as []interface{}, bs []interface{}) {
	_ = func() {
		if len(as) == len(bs) {
			_ = as[:len(bs)] // [L27] eliminatd, why?
			_ = bs[:len(as)] // [L28] eliminatd, why?
			_ = as[:len(as)] // [L29:10] checked, why?
			_ = bs[:len(bs)] // [L30:10] checked, why?
		}
	}
}

func main() {}
go build -gcflags="-d=ssa/check_bce/debug=1" main.go

What did you expect to see?

See the comments of the code above.

What did you see instead?

image

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.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions