Update to go1.23.4

This commit is contained in:
Vorapol Rinsatitnon
2024-12-24 19:40:24 +07:00
parent 289b9e3aad
commit f9b11597fa
32 changed files with 771 additions and 248 deletions

View File

@@ -33,7 +33,7 @@ import (
"unicode"
)
var globalSkip = func(t *testing.T) {}
var globalSkip = func(t testing.TB) {}
// Program to run.
var bin []string
@@ -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()
}
}
@@ -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)
@@ -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)

View File

@@ -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() {}

View File

@@ -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));
}

View File

@@ -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;
}

View File

@@ -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]);
}
int main() {
GoF(); // call GoF without using much stack
callGoFWithDeepStack(); // call GoF with a deep stack
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() {
callGoWithVariousStack(0);
callGoWithVariousStackAndGoFrame(0); // normal execution
callGoWithVariousStackAndGoFrame(1); // panic and recover
}

View File

@@ -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
}

View File

@@ -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 {

View File

@@ -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

View File

@@ -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)),

View File

@@ -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
@@ -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].
@@ -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
}

View File

@@ -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},
}

View File

@@ -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)
}
}

View File

@@ -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")
@@ -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.