Skip to content

Commit

Permalink
Update to Go 1.23.5
Browse files Browse the repository at this point in the history
  • Loading branch information
mpminardi committed Jan 28, 2025
2 parents 161c3b7 + ab44565 commit 64f7854
Show file tree
Hide file tree
Showing 44 changed files with 1,035 additions and 379 deletions.
4 changes: 2 additions & 2 deletions VERSION
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
go1.23.3
time 2024-11-06T18:46:45Z
go1.23.5
time 2025-01-10T16:44:59Z
57 changes: 52 additions & 5 deletions src/cmd/cgo/internal/testcarchive/carchive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"unicode"
)

var globalSkip = func(t *testing.T) {}
var globalSkip = func(t testing.TB) {}

// Program to run.
var bin []string
Expand All @@ -59,12 +59,12 @@ func TestMain(m *testing.M) {

func testMain(m *testing.M) int {
if testing.Short() && os.Getenv("GO_BUILDER_NAME") == "" {
globalSkip = func(t *testing.T) { t.Skip("short mode and $GO_BUILDER_NAME not set") }
globalSkip = func(t testing.TB) { t.Skip("short mode and $GO_BUILDER_NAME not set") }
return m.Run()
}
if runtime.GOOS == "linux" {
if _, err := os.Stat("/etc/alpine-release"); err == nil {
globalSkip = func(t *testing.T) { t.Skip("skipping failing test on alpine - go.dev/issue/19938") }
globalSkip = func(t testing.TB) { t.Skip("skipping failing test on alpine - go.dev/issue/19938") }
return m.Run()
}
}
Expand Down Expand Up @@ -1291,8 +1291,8 @@ func TestPreemption(t *testing.T) {
}
}

// Issue 59294. Test calling Go function from C after using some
// stack space.
// Issue 59294 and 68285. Test calling Go function from C after with
// various stack space.
func TestDeepStack(t *testing.T) {
globalSkip(t)
testenv.MustHaveGoBuild(t)
Expand Down Expand Up @@ -1350,6 +1350,53 @@ func TestDeepStack(t *testing.T) {
}
}

func BenchmarkCgoCallbackMainThread(b *testing.B) {
// Benchmark for calling into Go fron C main thread.
// See issue #68587.
//
// It uses a subprocess, which is a C binary that calls
// Go on the main thread b.N times. There is some overhead
// for launching the subprocess. It is probably fine when
// b.N is large.

globalSkip(b)
testenv.MustHaveGoBuild(b)
testenv.MustHaveCGO(b)
testenv.MustHaveBuildMode(b, "c-archive")

if !testWork {
defer func() {
os.Remove("testp10" + exeSuffix)
os.Remove("libgo10.a")
os.Remove("libgo10.h")
}()
}

cmd := exec.Command("go", "build", "-buildmode=c-archive", "-o", "libgo10.a", "./libgo10")
out, err := cmd.CombinedOutput()
b.Logf("%v\n%s", cmd.Args, out)
if err != nil {
b.Fatal(err)
}

ccArgs := append(cc, "-o", "testp10"+exeSuffix, "main10.c", "libgo10.a")
out, err = exec.Command(ccArgs[0], ccArgs[1:]...).CombinedOutput()
b.Logf("%v\n%s", ccArgs, out)
if err != nil {
b.Fatal(err)
}

argv := cmdToRun("./testp10")
argv = append(argv, fmt.Sprint(b.N))
cmd = exec.Command(argv[0], argv[1:]...)

b.ResetTimer()
err = cmd.Run()
if err != nil {
b.Fatal(err)
}
}

func TestSharedObject(t *testing.T) {
// Test that we can put a Go c-archive into a C shared object.
globalSkip(t)
Expand Down
12 changes: 12 additions & 0 deletions src/cmd/cgo/internal/testcarchive/testdata/libgo10/a.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright 2024 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

import "C"

//export GoF
func GoF() {}

func main() {}
22 changes: 21 additions & 1 deletion src/cmd/cgo/internal/testcarchive/testdata/libgo9/a.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,29 @@ package main

import "runtime"

// extern void callGoWithVariousStack(int);
import "C"

func main() {}

//export GoF
func GoF() { runtime.GC() }
func GoF(p int32) {
runtime.GC()
if p != 0 {
panic("panic")
}
}

//export callGoWithVariousStackAndGoFrame
func callGoWithVariousStackAndGoFrame(p int32) {
if p != 0 {
defer func() {
e := recover()
if e == nil {
panic("did not panic")
}
runtime.GC()
}()
}
C.callGoWithVariousStack(C.int(p));
}
22 changes: 22 additions & 0 deletions src/cmd/cgo/internal/testcarchive/testdata/main10.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2024 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.

#include <stdio.h>
#include <stdlib.h>

#include "libgo10.h"

int main(int argc, char **argv) {
int n, i;

if (argc != 2) {
perror("wrong arg");
return 2;
}
n = atoi(argv[1]);
for (i = 0; i < n; i++)
GoF();

return 0;
}
16 changes: 12 additions & 4 deletions src/cmd/cgo/internal/testcarchive/testdata/main9.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,27 @@

void use(int *x) { (*x)++; }

void callGoFWithDeepStack() {
void callGoFWithDeepStack(int p) {
int x[10000];

use(&x[0]);
use(&x[9999]);

GoF();
GoF(p);

use(&x[0]);
use(&x[9999]);
}

void callGoWithVariousStack(int p) {
GoF(0); // call GoF without using much stack
callGoFWithDeepStack(p); // call GoF with a deep stack
GoF(0); // again on a shallow stack
}

int main() {
GoF(); // call GoF without using much stack
callGoFWithDeepStack(); // call GoF with a deep stack
callGoWithVariousStack(0);

callGoWithVariousStackAndGoFrame(0); // normal execution
callGoWithVariousStackAndGoFrame(1); // panic and recover
}
11 changes: 6 additions & 5 deletions src/cmd/compile/internal/escape/solve.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,10 @@ func containsClosure(f, c *ir.Func) bool {
return false
}

// Closures within function Foo are named like "Foo.funcN..." or "Foo-rangeN".
// TODO(mdempsky): Better way to recognize this.
fn := f.Sym().Name
cn := c.Sym().Name
return len(cn) > len(fn) && cn[:len(fn)] == fn && (cn[len(fn)] == '.' || cn[len(fn)] == '-')
for p := c.ClosureParent; p != nil; p = p.ClosureParent {
if p == f {
return true
}
}
return false
}
17 changes: 17 additions & 0 deletions src/cmd/compile/internal/importer/gcimporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,23 @@ func TestIssue25596(t *testing.T) {
compileAndImportPkg(t, "issue25596")
}

func TestIssue70394(t *testing.T) {
testenv.MustHaveGoBuild(t)

// This package only handles gc export data.
if runtime.Compiler != "gc" {
t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler)
}

pkg := compileAndImportPkg(t, "alias")
obj := lookupObj(t, pkg.Scope(), "A")

typ := obj.Type()
if _, ok := typ.(*types2.Alias); !ok {
t.Fatalf("type of %s is %s, wanted an alias", obj, typ)
}
}

func importPkg(t *testing.T, path, srcDir string) *types2.Package {
pkg, err := Import(make(map[string]*types2.Package), path, srcDir, nil)
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions src/cmd/compile/internal/importer/testdata/alias.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright 2024 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 testdata

type A = int32
8 changes: 3 additions & 5 deletions src/cmd/compile/internal/importer/ureader.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@ func ReadPackage(ctxt *types2.Context, imports map[string]*types2.Package, input
pr := pkgReader{
PkgDecoder: input,

ctxt: ctxt,
imports: imports,
// Currently, the compiler panics when using Alias types.
// TODO(gri) set to true once this is fixed (issue #66873)
enableAlias: false,
ctxt: ctxt,
imports: imports,
enableAlias: true,

posBases: make([]*syntax.PosBase, input.NumElems(pkgbits.RelocPosBase)),
pkgs: make([]*types2.Package, input.NumElems(pkgbits.RelocPkg)),
Expand Down
6 changes: 6 additions & 0 deletions src/cmd/compile/internal/ir/func.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ import (
// the generated ODCLFUNC, but there is no
// pointer from the Func back to the OMETHVALUE.
type Func struct {
// if you add or remove a field, don't forget to update sizeof_test.go

miniNode
Body Nodes

Expand All @@ -76,6 +78,9 @@ type Func struct {
// Populated during walk.
Closures []*Func

// Parent of a closure
ClosureParent *Func

// Parents records the parent scope of each scope within a
// function. The root scope (0) has no parent, so the i'th
// scope's parent is stored at Parents[i-1].
Expand Down Expand Up @@ -512,6 +517,7 @@ func NewClosureFunc(fpos, cpos src.XPos, why Op, typ *types.Type, outerfn *Func,

fn.Nname.Defn = fn
pkg.Funcs = append(pkg.Funcs, fn)
fn.ClosureParent = outerfn

return fn
}
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/ir/sizeof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestSizeof(t *testing.T) {
_32bit uintptr // size on 32bit platforms
_64bit uintptr // size on 64bit platforms
}{
{Func{}, 176, 296},
{Func{}, 180, 304},
{Name{}, 96, 168},
}

Expand Down
24 changes: 24 additions & 0 deletions src/cmd/compile/internal/rangefunc/rangefunc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2099,3 +2099,27 @@ func TestTwoLevelReturnCheck(t *testing.T) {
t.Errorf("Expected y=3, got y=%d\n", y)
}
}

func Bug70035(s1, s2, s3 []string) string {
var c1 string
for v1 := range slices.Values(s1) {
var c2 string
for v2 := range slices.Values(s2) {
var c3 string
for v3 := range slices.Values(s3) {
c3 = c3 + v3
}
c2 = c2 + v2 + c3
}
c1 = c1 + v1 + c2
}
return c1
}

func Test70035(t *testing.T) {
got := Bug70035([]string{"1", "2", "3"}, []string{"a", "b", "c"}, []string{"A", "B", "C"})
want := "1aABCbABCcABC2aABCbABCcABC3aABCbABCcABC"
if got != want {
t.Errorf("got %v, want %v", got, want)
}
}
15 changes: 15 additions & 0 deletions src/cmd/compile/internal/ssa/writebarrier.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ func writebarrier(f *Func) {
var start, end int
var nonPtrStores int
values := b.Values
hasMove := false
FindSeq:
for i := len(values) - 1; i >= 0; i-- {
w := values[i]
Expand All @@ -263,6 +264,9 @@ func writebarrier(f *Func) {
end = i + 1
}
nonPtrStores = 0
if w.Op == OpMoveWB {
hasMove = true
}
case OpVarDef, OpVarLive:
continue
case OpStore:
Expand All @@ -273,6 +277,17 @@ func writebarrier(f *Func) {
if nonPtrStores > 2 {
break FindSeq
}
if hasMove {
// We need to ensure that this store happens
// before we issue a wbMove, as the wbMove might
// use the result of this store as its source.
// Even though this store is not write-barrier
// eligible, it might nevertheless be the store
// of a pointer to the stack, which is then the
// source of the move.
// See issue 71228.
break FindSeq
}
default:
if last == nil {
continue
Expand Down
16 changes: 15 additions & 1 deletion src/cmd/go/internal/modfetch/codehost/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,21 @@ func (r *gitRepo) statLocal(ctx context.Context, version, rev string) (*RevInfo,
}
}
}
sort.Strings(info.Tags)

// Git 2.47.1 does not send the tags during shallow clone anymore
// (perhaps the exact version that changed behavior is an earlier one),
// so we have to also add tags from the refs list we fetched with ls-remote.
if refs, err := r.loadRefs(ctx); err == nil {
for ref, h := range refs {
if h == hash {
if tag, found := strings.CutPrefix(ref, "refs/tags/"); found {
info.Tags = append(info.Tags, tag)
}
}
}
}
slices.Sort(info.Tags)
info.Tags = slices.Compact(info.Tags)

// Used hash as info.Version above.
// Use caller's suggested version if it appears in the tag list
Expand Down
5 changes: 5 additions & 0 deletions src/cmd/trace/gstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ func (gs *gState[R]) stop(ts trace.Time, stack trace.Stack, ctx *traceContext) {
if gs.lastStopStack != trace.NoStack {
stk = ctx.Stack(viewerFrames(gs.lastStopStack))
}
var endStk int
if stack != trace.NoStack {
endStk = ctx.Stack(viewerFrames(stack))
}
// Check invariants.
if gs.startRunningTime == 0 {
panic("silently broken trace or generator invariant (startRunningTime != 0) not held")
Expand All @@ -270,6 +274,7 @@ func (gs *gState[R]) stop(ts trace.Time, stack trace.Stack, ctx *traceContext) {
Dur: ts.Sub(gs.startRunningTime),
Resource: uint64(gs.executing),
Stack: stk,
EndStack: endStk,
})

// Flush completed ranges.
Expand Down
Loading

0 comments on commit 64f7854

Please sign in to comment.