2410 Commits

Author SHA1 Message Date
Robert Griesemer
238d7bddeb go/types, types2: in range-over-func, the yield function cannot be variadic
Fixes #78483.
For #78314.

Change-Id: If83983c0bf79840aa02dc0d2fa8945f5e8b4e969
Reviewed-on: https://go-review.googlesource.com/c/go/+/761682
Auto-Submit: Robert Griesemer <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jakub Ciolek <jakub@ciolek.dev>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Mark Freeman <markfreeman@google.com>
2026-04-01 16:39:05 -07:00
Cuong Manh Le
f665ff8bc1 cmd/compile: fix wrong label loop during rangefunc rewrite
During the rangefunc rewrite, the compiler must correctly identify
the target of branch statements. When a label is defined within a
nested scope - such as inside a function literal or a closure - it
can shadow a label with the same name in the outer scope.

If the rewrite logic does not account for this shadowing, it may
incorrectly associate a branch with a nested label rather than the
intended loop label. Since the typechecker already guarantees that
labels are unique within their respective scopes, any duplicate label
name encountered must belong to a nested scope. These should be
skipped to ensure branch computing correctly targets the current
range-loop scope.

Fixes #78408

Change-Id: I4dce8a4d956f41b3a717a509f8c3f7478720be9f
Reviewed-on: https://go-review.googlesource.com/c/go/+/761420
Reviewed-by: Keith Randall <khr@golang.org>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jakub Ciolek <jakub@ciolek.dev>
Reviewed-by: Junyang Shao <shaojunyang@google.com>
Reviewed-by: Keith Randall <khr@google.com>
2026-03-31 10:58:57 -07:00
Cuong Manh Le
9002bd9fa1 cmd/compile: ensure map/slice clearing expressions are walked
The order pass ensures that initialization operations for clear(expr)
are scheduled. However, if 'expr' is a conversion that the walk pass
subsequently optimizes away or transforms, the resulting nodes can
be left in an un-walked state.

These un-walked nodes reach the SSA backend, which does not expect
high-level IR, resulting in an ICE.

This change ensures the expression is always walked during the
transformation of the 'clear' builtin.

Fixes #78410

Change-Id: I1997a28af020f39b2d325a58429eff9495048b1f
Reviewed-on: https://go-review.googlesource.com/c/go/+/760981
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Junyang Shao <shaojunyang@google.com>
Reviewed-by: David Chase <drchase@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2026-03-31 10:58:53 -07:00
Mateusz Poliwczak
09031d907c cmd/compile/internal/devirtualize: use pointer identity for type comparison
Fixes #78404

Change-Id: I6adc1fb42ad6a3acce21333c6819d0796a6a6964
Reviewed-on: https://go-review.googlesource.com/c/go/+/760161
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
2026-03-30 07:27:52 -07:00
Cuong Manh Le
b77fdc333a cmd/compile: skip incomplete types in needWrapper
A recursive pointer type *T may still be a TFORW when the compiler
determines if method wrappers are needed. This leads to an incorrect
decision and triggers an internal compiler error.

Fix this by skipping incomplete types during the method wrapper
generation check.

Fixes #78295

Change-Id: I4005e525e9b076c6656aed5419283c0418edcac6
Reviewed-on: https://go-review.googlesource.com/c/go/+/758922
Reviewed-by: Jakub Ciolek <jakub@ciolek.dev>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2026-03-26 09:01:18 -07:00
Jorropo
5edb5d729d cmd/compile: do not invert loops that would overflow or underflow
On the final iteration we need space below start (which becomes end)
such that i-step does not overflow or underflow.

In other words the code used to assume that the last time the loop header
execute `start < i - step` (or `<=`, `>` `>=` based on the loop)
is always false.

And it seems correct since by definition the only way for it to be the
last's loop header execution is when the condition becomes false.

However here is an example with uint (even tho the code doesn't
already support them) to make things simpler:
  start = 1
  i = 2
  step = 100

We do 2 - 100 which should give us 1 < -98 == false breaking the loop;
Instead we get 18446744073709551518 which gives
1 < 18446744073709551518 == true which keeps the loop going.

This patch fixes this issue by ensuring that in the last execution of
a loop header the induction variable does not underflow or overflow.

Fixes #78303

Change-Id: I64e8e8592b023d79fdbc7f1598d584726ed601f5
Reviewed-on: https://go-review.googlesource.com/c/go/+/758801
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Auto-Submit: Jorropo <jorropo.pgm@gmail.com>
Reviewed-by: Jakub Ciolek <jakub@ciolek.dev>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2026-03-26 09:01:13 -07:00
Cuong Manh Le
286a79658e cmd/compile: fix missing walk for OAS2RECV node
When channel receive operator is used in the context that requires
conversion to destination type, there's an implicit conversion operator
inserted by typecheck. This typecheck-ed node is un-walked, then passing
to the backend as-is, causing the ICE.

Fixes #78313

Change-Id: Ibbc70cbd2d8069cc7cf81934406aa68c4da2686a
Reviewed-on: https://go-review.googlesource.com/c/go/+/758660
Reviewed-by: Keith Randall <khr@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Jakub Ciolek <jakub@ciolek.dev>
Reviewed-by: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2026-03-26 08:54:42 -07:00
Cuong Manh Le
670038a5a5 cmd/compile: preserve variadic signature on range-over-func
When rewriting range-over-func loops, copy the variadic bit from the
original function type into the synthesized body closure's type info.
This keeps the generated closure signature aligned with the source
function and avoids losing variadic-ness during rewrite.

Fixes #78314

Change-Id: I4b5f4628e8c8c14d4ff89dd6b996837264c5cb61
Reviewed-on: https://go-review.googlesource.com/c/go/+/758041
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jakub Ciolek <jakub@ciolek.dev>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2026-03-25 13:06:06 -07:00
Keith Randall
c60392da8b Revert "runtime: disable test for 78081"
This reverts commit bfa3dc4028.

Reason for revert: re-enabling the test, after CL 757343 is in.

Change-Id: I78ebb000b95a14f39fc1f62a1013bc83849a0a37
Reviewed-on: https://go-review.googlesource.com/c/go/+/757226
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
2026-03-20 18:56:10 -07:00
Robert Griesemer
2de90fd48f cmd/compile/internal/noder: don't shoot oneself (fix silly mistake)
When reading multiple promoted fields in a struct literal from UIR,
don't overwrite the (top-level) struct literal type needed for the
next field.

Fixes #78262.
For #9859.

Change-Id: Ifac64537bebcb7dbb79a6173d0cd032cbf0b8ed8
Reviewed-on: https://go-review.googlesource.com/c/go/+/757225
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
2026-03-20 17:58:12 -07:00
Keith Randall
bfa3dc4028 runtime: disable test for 78081
The stack we're trying to revert for this issue is tripping
on the test for it. The test fails halfway through the revert stack.
Disable it for now, we can re-enable once the whole revert stack is in.

Change-Id: I3bc2d2f069030d865f799a63ad0f267aa667db07
Reviewed-on: https://go-review.googlesource.com/c/go/+/757224
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2026-03-20 17:29:41 -07:00
Robert Griesemer
9f7e98d263 go/types, types2: allow promoted field names as keys in struct literals
For #9859.

Change-Id: Ie4823e726ab43fe2ce1e96c279f63dad6c1f9873
Reviewed-on: https://go-review.googlesource.com/c/go/+/751702
Reviewed-by: Mark Freeman <markfreeman@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Griesemer <gri@google.com>
2026-03-19 14:32:21 -07:00
Keith Randall
72327dd645 runtime: add a test for issue 78081
Contrive to have a bunch of stack shrinking going on during
memclrNoHeapPointersPreemptible calls.

Fails at tip with this patch:

--- a/src/runtime/malloc.go
+++ b/src/runtime/malloc.go
@@ -2184,6 +2184,7 @@ func reusableSize(size uintptr) bool {
 // Use this with care; if the data being cleared is tagged to contain
 // pointers, this allows the GC to run before it is all cleared.
 func memclrNoHeapPointersChunked(size uintptr, x unsafe.Pointer) {
+       y := uintptr(x)
        if getg().preempt {
                // TODO: no need for this, except to test that
                // the preemption point is ok for small zeroings.
@@ -2193,6 +2194,7 @@ func memclrNoHeapPointersChunked(size uintptr, x unsafe.Pointer) {
                // may hold locks, e.g., profiling
                goschedguarded()
        }
+       x = unsafe.Pointer(y)
        // got this from benchmarking. 128k is too small, 512k is too large.
        const chunkBytes = 256 * 1024
        for size > chunkBytes {

Update #78081

Change-Id: Id8f87a4b0d0970cbf971c90ab87703a9e5b3f121
Reviewed-on: https://go-review.googlesource.com/c/go/+/755942
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Keith Randall <khr@google.com>
2026-03-18 09:19:06 -07:00
Oliver Eikemeier
45c6fb4b9b cmd/compile: unwrap OCONVIFACE in staticinit for OAS2
Static initialization only expected OCONVNOP wrappings.
Unwrap OCONVIFACE too, since it occurs when multiple return values
of an OAS2FUNC are implicitly converted to an interface.

Fixes #78016

Change-Id: Ic3fd6151403aabfc087d3240c1fcfabe7108cc0e
GitHub-Last-Rev: 98976d9e64
GitHub-Pull-Request: golang/go#78017
Reviewed-on: https://go-review.googlesource.com/c/go/+/752780
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Mark Freeman <markfreeman@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
2026-03-10 20:51:48 -07:00
dorbmon
38ac6577cb cmd/compile: forward small Load through Move to avoid redundant copies
Fixes #77720

Add a generic SSA rewrite that forwards `Load` from a `Move` destination
back to the `Move` source when it is provably safe, so field reads like
`s.h.Value().typ` don’t force a full struct copy.

- Add `Load <- Move` rewrite in `generic.rules` with safety guard:
  non-volatile source
- Tweak `fixedbugs/issue22200*` so that it can still trigger the "stack frame too large" error.
- Regenerate `rewritegeneric.go`.
- Add `test/codegen/moveload.go` to assert no `MOVUPS` and direct `MOVBLZX`
  in both direct and inlined forms.

Benchmark results (linux/amd64, i7-14700KF):

$ go test cmd/compile/internal/test -run='^$' -bench='MoveLoad' -count=20

Before:
  BenchmarkMoveLoadTypViaValue-20  ~76.9 ns/op
  BenchmarkMoveLoadTypViaPtr-20    ~1.97 ns/op

After:
  BenchmarkMoveLoadTypViaValue-20  ~1.894 ns/op
  BenchmarkMoveLoadTypViaPtr-20    ~1.905 ns/op

The rewrite removes the redundant struct copy in
`s.h.Value().typ`, bringing it in line with the direct pointer form.

Change-Id: Iddf2263e390030ba013e0642a695b87c75f899da
Reviewed-on: https://go-review.googlesource.com/c/go/+/748200
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@golang.org>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Mark Freeman <markfreeman@google.com>
2026-03-10 20:06:05 -07:00
Cuong Manh Le
28b1d8886b cmd/compile: fix ICE when checking slice cap
CL 226737 optimized len check when make slice in common case when len is
within range of cap. However, the generated code does not walk the AST
for the if condition, causing un-walked nodes passed to the backend.

Fixes #78028

Change-Id: I492fb230c10e585dc09391728ef4df2c0058ce12
Reviewed-on: https://go-review.googlesource.com/c/go/+/753100
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jakub Ciolek <jakub@ciolek.dev>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Keith Randall <khr@google.com>
2026-03-10 04:42:57 -07:00
qmuntal
b0057a4e0c test/fixedbugs: increase issue46234 test timeout
issue46234 is flaky on slow machines, so increase the timeout to 90s.

Note that that test timeout already got increased from 30s to 45s in
CL 382774, but it was still not enough.

Fixes #50973
Fixes #67558
Fixes #74277
Updates #65040

Cq-Include-Trybots: luci.golang.try:gotip-darwin-amd64_14
Change-Id: I809249a05c6ca65fb6c44375c8de5758f21dbb91
Reviewed-on: https://go-review.googlesource.com/c/go/+/747520
Auto-Submit: Quim Muntal <quimmuntal@gmail.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2026-03-10 00:37:14 -07:00
Cuong Manh Le
bf1b0973db 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

Change-Id: Ibc137c84792d4898eb073cdeabac175684f73746
Reviewed-on: https://go-review.googlesource.com/c/go/+/751040
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2026-03-06 10:31:11 -08:00
Keith Randall
e7a09d1ffb cmd/compile: use tail calls for wrappers for embedded interfaces
type I interface {
    foo()
}

type S struct {
    I
}

Because I is embedded in S, S needs a foo method.  We generate a
wrapper function to implement (*S).foo.  It just loads the embedded
field I out of S and calls foo on it.

When the thing in S.I itself needs a wrapper, then we have a wrapper
calling another wrapper. This can continue, leaving a potentially long
sequence of wrappers on the stack. When we then call runtime.Callers
or friends, we have to walk an unbounded number of frames to find a
bounded number of non-wrapper frames.

This really happens, for instance with I = context.Context, S =
context.ValueCtx, and runtime.Callers = pprof sample (for any of
context.Context's methods).

To fix, make the interface call in the wrapper a tail call.
That way, the number of wrapper frames on the stack does not
increase when there are lots of wrappers happening.

Fixes #75764
Fixes #77781

Change-Id: I03b1731159d9218c7f14f72ecbbac822d6a6bb87
Reviewed-on: https://go-review.googlesource.com/c/go/+/751465
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
2026-03-06 10:28:08 -08:00
Mateusz Poliwczak
b16360470c cmd/compile: fix ICE when indexing zero-sized arrays of non-SSAable types
Fixes #77868

Change-Id: I3348825e24a71595c514113497db365a6a6a6964
Reviewed-on: https://go-review.googlesource.com/c/go/+/749881
Reviewed-by: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: David Chase <drchase@google.com>
2026-03-04 13:26:19 -08:00
Francisco Ferraz
244b156e67 cmd/compile: fix internal compiler error: bad write barrier type
This change fixes an issue where the compiler panics with 'bad
write barrier type' for zero-sized arrays. The loops in
storeTypeScalars and storeTypePtrs erroneously processed
zero-sized arrays causing invalid operations. This ignores them.

Fixes #77815

Change-Id: I0db1b924fc63a75f1bed7488e2dc54d2de5dc0b2
Reviewed-on: https://go-review.googlesource.com/c/go/+/749380
Reviewed-by: Keith Randall <khr@google.com>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2026-02-27 20:20:22 -08:00
khr@golang.org
0886e65b11 cmd/compile: treat all zero-sized values as SSA-able
Might as well, we don't need any registers for such values.

Fixes #77635

Change-Id: Iedc1bc3f13662b043b183228bcc1dc4e6c91da81
Reviewed-on: https://go-review.googlesource.com/c/go/+/747780
Reviewed-by: Junyang Shao <shaojunyang@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drchase@google.com>
2026-02-25 16:52:27 -08:00
Keith Randall
1aa534dbb8 cmd/compile: ensure StructMake/ArrayMake1 of direct interfaces are unwrapped
Ensures that deeply nested structs that have the underlying shape
of a pointer get unwrapped properly.

Update #77534

Change-Id: I004f424d2c62ec7026281daded9b3d96c021e2e1
Reviewed-on: https://go-review.googlesource.com/c/go/+/747760
Reviewed-by: Mark Freeman <markfreeman@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drchase@google.com>
2026-02-25 13:58:41 -08:00
Keith Randall
60dc96479a reflect: use &zeroVal[0] instead of nil for data field for zero-sized payloads
Because our wrapper functions barf if the pointer is nil, even if
we don't actually dereference the pointer.

Fixes #77779

Change-Id: Ib1b93d9f0fdc771cd884137007508ba2b1da4b7a
Reviewed-on: https://go-review.googlesource.com/c/go/+/748660
Reviewed-by: Ian Lance Taylor <iant@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Keith Randall <khr@google.com>
2026-02-24 20:51:17 -08:00
Keith Randall
6435bf46c1 cmd/compile: pointer-shaped types are SSAable even if lots of 0-sized fields
Normally we don't SSA-ify variables with types that have more than
4 fields. But we really do want to SSA-ify them if they are pointer
shaped.

An odd case, but the compiler shouldn't barf on them.

Failure probably started with CL 714421.

Fixes #77534

Change-Id: I51ef87676cc31df1e51e164bbd58d58c0ab72436
Reviewed-on: https://go-review.googlesource.com/c/go/+/744280
Reviewed-by: Junyang Shao <shaojunyang@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drchase@google.com>
2026-02-21 10:38:20 -08:00
khr@golang.org
f65692ea56 cmd/compile: don't drop same register twice
For instructions that clobber both of their input registers, make
sure we don't clobber the same register twice when both input
registers are the same.

This is rare, but it can happen.

Fixes #77604

Change-Id: I794249cf43a8cc4ab3262055daef9193e2442f73
Reviewed-on: https://go-review.googlesource.com/c/go/+/745621
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jorropo <jorropo.pgm@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2026-02-15 07:19:01 -08:00
Youlin Feng
3c8b5e6738 cmd/compile: avoid folding 64-bit integers into 32-bit constants
Folding a 64-bit integer into a 32-bit constant may result in a negative
integer if the value exceeds math.MaxInt32 (the maximum value of a 32-
bit signed integer). This negative value will be sign-extended to 64
bits at runtime, leading to unexpected results when used in bitwise
AND/OR operations.

Fixes #77613

Change-Id: Idb081a3c20c28bddddcc8eff1225d62123b37a2d
Reviewed-on: https://go-review.googlesource.com/c/go/+/745581
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2026-02-14 12:18:00 -08:00
Keith Randall
b8bccb9798 cmd/compile: don't double-walk the map argument of clear
mkcallstmt1 already walks the map argument of clear. mapClear then
walks it again, which can cause problems if it is some syntax that is
non-idempotent under walk.  That is the case for the new way map
lookups are being lowered in CL 736020.

Fixes #77435

Change-Id: Ib2f6d7f2270308c2462aa276ed4413aaf7799fe3
Reviewed-on: https://go-review.googlesource.com/c/go/+/742120
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2026-02-04 17:48:06 -08:00
fumiyanokesinn
cf0c42c2ca cmd/compile/internal/reflectdata: fix divide by zero for zero-size array elements
When generating equality signatures for arrays with zero-size ASPECIAL
elements (e.g., [3]struct{_ [0]float64}), the compiler crashed with
a divide by zero error when computing the loop unroll factor.

Skip comparison code generation for zero-size elements since they
need no comparison.

Fixes #77303

Change-Id: Ib432cfece22b1cb714de4f0a0b0d1a2d89bb0d33
Reviewed-on: https://go-review.googlesource.com/c/go/+/738841
Reviewed-by: Cherry Mui <cherryyz@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Keith Randall <khr@google.com>
2026-01-26 18:28:40 -08:00
Alan Donovan
532e320349 go/types,cmd/compile/internal/types2: better diagnostic for type shadowing
This change causes the "x is not a type" diagnostic to describe
x's actual kind, helping to reveal when shadowing is at work.

(The kind description could improve other errors too.)

Fixes #76877

Change-Id: Ia3484998bb384ff570c20b6792cf8461c60aa38c
Reviewed-on: https://go-review.googlesource.com/c/go/+/731180
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Robert Griesemer <gri@google.com>
2026-01-15 15:10:27 -08:00
Cuong Manh Le
b6b8b2fe6e cmd/compile: handle propagating an out-of-range jump table index
For an out-of-range jump table index, the constant facts should not be
propagated to the destinations.

Fixes #76950

Change-Id: Iff29814cb466c7aaa432cec212e5387665c45afc
Reviewed-on: https://go-review.googlesource.com/c/go/+/731860
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-12-23 07:32:56 -08:00
Cuong Manh Le
f84f8d86be cmd/compile: fix mis-infer bounds in slice len/cap calculations
CL 704875 enhanced prove to infer bounds when index have a relationship
with len(A) - K. However, the change incorrectly infer "K - len(A)" case,
causing wrong bounds information.

Fixing this by matching exactly "len(A) - K" case.

Fixes #76709

Change-Id: Ibeedff55520658401af5bd3aa7e98cc1bcf38fd6
Reviewed-on: https://go-review.googlesource.com/c/go/+/727180
Reviewed-by: Cherry Mui <cherryyz@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jakub Ciolek <jakub@ciolek.dev>
Reviewed-by: David Chase <drchase@google.com>
2025-12-05 08:02:02 -08:00
Mark Freeman
3531ac23d4 go/types, types2: replace setDefType with pending type check
Given a type definition of the form:

  type T RHS

The setDefType function would set T.fromRHS as soon as we knew its
top-level type. For instance, in:

  type S struct { ... }

S.fromRHS is set to a struct type before type-checking anything inside
the struct.

This permit access to the (incomplete) RHS type in a cyclic type
declaration. Accessing this information is fraught (as it's incomplete),
but was used for reporting certain types of cycles.

This CL replaces setDefType with a check that ensures no value of type
T is used before its RHS is set up.

This CL is strictly more complete than what setDefType achieved. For
instance, it enables correct reporting for the below cycles:

  type A [unsafe.Sizeof(A{})]int

  var v any = 42
  type B [v.(B)]int

  func f() C {
    return C{}
  }
  type C [unsafe.Sizeof(f())]int

Fixes #76383
Fixes #76384

Change-Id: I9dfab5b708013b418fa66e43362bb4d8483fedec
Reviewed-on: https://go-review.googlesource.com/c/go/+/724140
Auto-Submit: Mark Freeman <markfreeman@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-11-26 16:15:28 -08:00
Keith Randall
03ed43988f cmd/compile: allow multi-field structs to be stored directly in interfaces
If the struct is a bunch of 0-sized fields and one pointer field.

Merged revert-of-revert for 4 CLs.

original  revert
681937    695016
693415    694996
693615    695015
694195    694995

Fixes #74092
Update #74888
Update #74908
Update #74935
(updated issues are bugs in the last attempt at this)

Change-Id: I32246d49b8bac3bb080972dc06ab432a5480d560
Reviewed-on: https://go-review.googlesource.com/c/go/+/714421
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
2025-11-14 12:37:44 -08:00
matloob@golang.org
d50a571ddf test: fix tests to work with sizespecializedmalloc turned off
Cq-Include-Trybots: luci.golang.try:gotip-linux-386-nosizespecializedmalloc,gotip-linux-amd64-nosizespecializedmalloc,gotip-linux-arm64-nosizespecializedmalloc
Change-Id: I6a6a696465004b939c989afc058c4c3e1fb7134f
Reviewed-on: https://go-review.googlesource.com/c/go/+/720401
Auto-Submit: Michael Matloob <matloob@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Matloob <matloob@google.com>
2025-11-13 16:57:31 -08:00
Russ Cox
9035f7aea5 runtime: use internal/strconv
Runtime doing its own number formatting dates back to
when runtime was the bottom-most Go package.
Those days are long gone. Use internal/strconv to avoid
duplicating code and also to get better floating-point
formatting:

% go1.24.6 run x.go
+1.234568e+004
% go run x.go
12345.678
%

With accurate floating point it becomes necessary to
introduce separate printers for float32 vs float64 and
for complex64 vs complex128. Otherwise float32(93.7)
prints as 93.69999694824219.

Change-Id: I25ae3f09519342dc3d1dcabf4711651423e00128
Reviewed-on: https://go-review.googlesource.com/c/go/+/716002
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-29 11:00:23 -07:00
Keith Randall
bd4dc413cd cmd/compile: don't optimize away a panicing interface comparison
We can't do direct pointer comparisons if the type is not a
comparable type.

Fixes #76008

Change-Id: I1687acff21832d2c2e8f3b875e7b5ec125702ef3
Reviewed-on: https://go-review.googlesource.com/c/go/+/713840
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Keith Randall <khr@google.com>
2025-10-28 10:24:14 -07:00
Michael Matloob
19a30ea3f2 cmd/compile: call generated size-specialized malloc functions directly
This change creates calls to size-specialized malloc functions instead
of calls to newObject when we know the size of the allocation at
compilation time. Most of it is a matter of calling the newObject
function (which will create calls to the size-specialized functions)
rather then the newObjectNonSpecialized function (which won't). In the
newHeapaddr, small, non-pointer case, we'll create a non specialized
newObject and transform that into the appropriate size-specialized
function when we produce the mallocgc in flushPendingHeapAllocations.

We have to update some of the rewrites in generic.rules to also apply to
the size-specialized functions when they apply to newObject.

The messiest thing is we have to adjust the offset we use to save the
memory profiler stack, because the depth of the call to profilealloc is
two frames fewer in the size-specialized malloc functions compared to
when newObject calls mallocgc. A bunch of tests have been adjusted to
account for that.

Change-Id: I6a6a6964c9037fb6719e392c4a498ed700b617d7
Reviewed-on: https://go-review.googlesource.com/c/go/+/707856
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Michael Matloob <matloob@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@golang.org>
2025-10-09 14:59:40 -07:00
Mateusz Poliwczak
de9da0de30 cmd/compile/internal/devirtualize: improve concrete type analysis
This change improves the concrete type analysis in the devirtualizer,
it not longer relies on ir.Reassigned, it now statically tries to
determine the concrete type of an interface, even when assigned
multiple times, following type assertions and iface conversions.

Alternative to CL 649195

Updates #69521
Fixes #64824

Change-Id: Ib1656e19f3619ab2e1e6b2c78346cc320490b2af
GitHub-Last-Rev: e8fa0b12f0
GitHub-Pull-Request: golang/go#71935
Reviewed-on: https://go-review.googlesource.com/c/go/+/652036
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Keith Randall <khr@golang.org>
2025-10-08 14:09:22 -07:00
Keith Randall
f15cd63ec4 cmd/compile: don't rely on loop info when there are irreducible loops
Loop information is sketchy when there are irreducible loops.
Sometimes blocks inside 2 loops can be recorded as only being part of
the outer loop. That causes tighten to move values that want to move
into such a block to move out of the loop altogether, breaking the
invariant that operations have to be scheduled after their args.

Fixes #75569

Change-Id: Idd80e6d2268094b8ae6387563081fdc1e211856a
Reviewed-on: https://go-review.googlesource.com/c/go/+/706355
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
2025-09-24 15:24:36 -07:00
Jake Bailey
a67977da5e cmd/compile/internal/inline: ignore superfluous slicing
When slicing, ignore expressions which could be elided, as in slicing
starting at 0 or ending at len(v).

Fixes #75278

Change-Id: I9c18e29c3d4da9bef89bd25bb261d3cb60e66392
Reviewed-on: https://go-review.googlesource.com/c/go/+/701216
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Mark Freeman <markfreeman@google.com>
2025-09-09 12:10:10 -07:00
Keith Randall
af03343f93 cmd/compile: fix bounds check report
For constant-index, variable length situations.

Inadvertant shadowing of the yVal variable. Oops.

Fixes #75327

Change-Id: I3403066fc39b7664222a3098cf0f22b5761ea66a
Reviewed-on: https://go-review.googlesource.com/c/go/+/702015
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-09-09 07:37:40 -07:00
ZhouGuangyuan
1ad30844d9 cmd/asm: process forward jump to PCALIGN
The forward jump target are not processed when the target is PCALIGN, so
process it before emit nops for PCALIGN.

Fixes #74648

Change-Id: I690fbfacf79e26d7a37628a2551729b2381616c5
Reviewed-on: https://go-review.googlesource.com/c/go/+/696915
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-08-21 18:51:39 -07:00
Keith Randall
5a56d8848b cmd/compile: ensure we use allowed registers for input-clobbering instructions
For instructions which clobber their input register, we make a second
copy of the input value so it is still available in a register for
future instructions.

That second copy might not respect the register input restrictions
for the instruction. So the second copy we make here can't actually
be used by the instruction - it should use the first copy, the second
copy is the one that will persist beyond the clobber.

Fixes #75063

Change-Id: I99acdc63f0c4e54567a174ff7ada601ae4e796b7
Reviewed-on: https://go-review.googlesource.com/c/go/+/697015
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-08-18 12:15:08 -07:00
Cherry Mui
00a7bdcb55 all: delete aliastypeparams GOEXPERIMENT
Always enable aliastypeparams and remove the GOEXPERIMENT.

Change-Id: Ic38fe25b0bba312a7f83f7bb94b57ab75ce0f0c3
Reviewed-on: https://go-review.googlesource.com/c/go/+/691956
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Mark Freeman <markfreeman@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
2025-08-12 06:28:26 -07:00
Keith Randall
c31359138c Revert "cmd/compile: allow StructSelect [x] of interface data fields for x>0"
This reverts commit bcd25c79aa (CL 693415)

Reason for revert: still causing compiler failures on Google test code

Change-Id: I887edcff56bde3ffa316f2b629021ad323a357fa
Reviewed-on: https://go-review.googlesource.com/c/go/+/694996
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2025-08-11 22:36:26 -07:00
Keith Randall
7248995b60 Revert "cmd/compile: allow more args in StructMake folding rule"
This reverts commit 72e8237cc1 (CL 693615)

Reason for revert: still causing compiler failures on Google test code

Change-Id: I4a7850c321d95ed7803d56866bb0c524c7a377d3
Reviewed-on: https://go-review.googlesource.com/c/go/+/695015
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Keith Randall <khr@google.com>
2025-08-11 22:36:20 -07:00
Keith Randall
caf9fc3ccd Revert "reflect: handle zero-sized fields of directly-stored structures correctly"
This reverts commit b3388569a1 (CL 694195)

Reason for revert: still causing compiler failures on Google test code

Change-Id: I2a9b0f9a57fe2b6977238bbfbefb572545210b9f
Reviewed-on: https://go-review.googlesource.com/c/go/+/694995
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2025-08-11 22:36:13 -07:00
Keith Randall
b3388569a1 reflect: handle zero-sized fields of directly-stored structures correctly
type W struct {
	E struct{}
	X *byte
}

type W is a "direct" type. That is, it is a pointer-ish type that can
be stored directly as the second word of an interface.

But if we ask reflect for W's first field, that value must *not* be
direct, as zero-sized things cannot be stored directly.

This was a problem introduced in CL 681937. Before that, types like W
were not eligible for directness.

Fixes #74935

Change-Id: Idefb55c23eaa59153009f863bad611593981e5cb
Reviewed-on: https://go-review.googlesource.com/c/go/+/694195
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2025-08-08 06:51:37 -07:00
Keith Randall
72e8237cc1 cmd/compile: allow more args in StructMake folding rule
imakeOfStructMake does the right thing, but we never call it
when the StructMake has more than one argument.

Fixes #74908

Change-Id: Ib4b1a025bfb1fa69a325207e47b74bd6217092bf
Reviewed-on: https://go-review.googlesource.com/c/go/+/693615
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-08-06 11:04:07 -07:00