cmd/compile/internal/typecheck: simplify tcSliceHeader
types2 handles all constant-related bounds checks in user Go code now,
so it's safe to remove all constants checking in tcSliceHeader function.
Fixed #77919
diff --git a/src/cmd/compile/internal/typecheck/expr.go b/src/cmd/compile/internal/typecheck/expr.go
index 44a69f0..7dc2963 100644
--- a/src/cmd/compile/internal/typecheck/expr.go
+++ b/src/cmd/compile/internal/typecheck/expr.go
@@ -7,7 +7,6 @@
import (
"fmt"
"go/constant"
- "go/token"
"internal/types/errors"
"strings"
@@ -826,18 +825,6 @@
n.Len = DefaultLit(Expr(n.Len), types.Types[types.TINT])
n.Cap = DefaultLit(Expr(n.Cap), types.Types[types.TINT])
- if ir.IsConst(n.Len, constant.Int) && ir.Int64Val(n.Len) < 0 {
- base.Fatalf("len for OSLICEHEADER must be non-negative")
- }
-
- if ir.IsConst(n.Cap, constant.Int) && ir.Int64Val(n.Cap) < 0 {
- base.Fatalf("cap for OSLICEHEADER must be non-negative")
- }
-
- if ir.IsConst(n.Len, constant.Int) && ir.IsConst(n.Cap, constant.Int) && constant.Compare(n.Len.Val(), token.GTR, n.Cap.Val()) {
- base.Fatalf("len larger than cap for OSLICEHEADER")
- }
-
return n
}
diff --git a/test/fixedbugs/issue77919.go b/test/fixedbugs/issue77919.go
new file mode 100644
index 0000000..834331e
--- /dev/null
+++ b/test/fixedbugs/issue77919.go
@@ -0,0 +1,15 @@
+// compile
+
+// Copyright 2026 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 main
+
+var sink any
+
+func main() {
+ i := 0
+ output := make([]string, 8, i)
+ sink = output
+}
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Auto-Submit | +1 |
| Commit-Queue | +1 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Auto-Submit | +1 |
| Commit-Queue | +1 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
1 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted one.
cmd/compile/internal/typecheck: simplify tcSliceHeader
types2 handles all constant-related bounds checks in user Go code now,
so it's safe to remove all constants checking in tcSliceHeader function.
Fixed #77919
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
[release-branch.go1.25] cmd/compile/internal/typecheck: simplify tcSliceHeader
types2 handles all constant-related bounds checks in user Go code now,
so it's safe to remove all constants checking in tcSliceHeader function.
Fixed #77921
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
[release-branch.go1.26] cmd/compile/internal/typecheck: simplify tcSliceHeader
types2 handles all constant-related bounds checks in user Go code now,
so it's safe to remove all constants checking in tcSliceHeader function.
Fixed #77922
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +1 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +1 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
[release-branch.go1.25] cmd/compile/internal/typecheck: simplify tcSliceHeader
types2 handles all constant-related bounds checks in user Go code now,
so it's safe to remove all constants checking in tcSliceHeader function.
Fixed #77921
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
[release-branch.go1.26] cmd/compile/internal/typecheck: simplify tcSliceHeader
types2 handles all constant-related bounds checks in user Go code now,
so it's safe to remove all constants checking in tcSliceHeader function.
Fixed #77922
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |