From 07559ceb721f4d1fff3186b9a481e2c0da1e0d4a Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Wed, 22 Mar 2023 17:45:07 +0700 Subject: [PATCH] cmd/compile: mark negative size memclr non-inlineable Fixes #59174 Change-Id: I72b2b068830b90d42a0186addd004fb3175b9126 Reviewed-on: https://go-review.googlesource.com/c/go/+/478375 Reviewed-by: Cherry Mui Run-TryBot: Cuong Manh Le Auto-Submit: Keith Randall Reviewed-by: Keith Randall Reviewed-by: Jakub Ciolek Reviewed-by: Keith Randall TryBot-Result: Gopher Robot --- src/cmd/compile/internal/ssa/rewrite.go | 3 +++ test/fixedbugs/issue59174.go | 12 ++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 test/fixedbugs/issue59174.go diff --git a/src/cmd/compile/internal/ssa/rewrite.go b/src/cmd/compile/internal/ssa/rewrite.go index 54ea2d3f4f..afd56018d3 100644 --- a/src/cmd/compile/internal/ssa/rewrite.go +++ b/src/cmd/compile/internal/ssa/rewrite.go @@ -1370,6 +1370,9 @@ func zeroUpper56Bits(x *Value, depth int) bool { } func isInlinableMemclr(c *Config, sz int64) bool { + if sz < 0 { + return false + } // TODO: expand this check to allow other architectures // see CL 454255 and issue 56997 switch c.arch { diff --git a/test/fixedbugs/issue59174.go b/test/fixedbugs/issue59174.go new file mode 100644 index 0000000000..33a19a4653 --- /dev/null +++ b/test/fixedbugs/issue59174.go @@ -0,0 +1,12 @@ +// compile + +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +func p() { + s := make([]int, copy([]byte{' '}, "")-1) + _ = append([]int{}, make([]int, len(s))...) +} -- 2.50.0