Skip to content

Commit dc9cfd9

Browse files
committed
Merge tag 'go1.22.12' into go1.22.6-msspi
2 parents 49934b6 + 5817e65 commit dc9cfd9

46 files changed

Lines changed: 794 additions & 316 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

VERSION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
go1.22.6
2-
time 2024-07-31T19:43:06Z
1+
go1.22.12
2+
time 2025-01-31T18:38:03Z

src/cmd/cgo/gcc.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2579,6 +2579,11 @@ func (c *typeConv) loadType(dtype dwarf.Type, pos token.Pos, parent string) *Typ
25792579
if dt.BitSize > 0 {
25802580
fatalf("%s: unexpected: %d-bit int type - %s", lineno(pos), dt.BitSize, dtype)
25812581
}
2582+
2583+
if t.Align = t.Size; t.Align >= c.ptrSize {
2584+
t.Align = c.ptrSize
2585+
}
2586+
25822587
switch t.Size {
25832588
default:
25842589
fatalf("%s: unexpected: %d-byte int type - %s", lineno(pos), t.Size, dtype)
@@ -2595,9 +2600,8 @@ func (c *typeConv) loadType(dtype dwarf.Type, pos token.Pos, parent string) *Typ
25952600
Len: c.intExpr(t.Size),
25962601
Elt: c.uint8,
25972602
}
2598-
}
2599-
if t.Align = t.Size; t.Align >= c.ptrSize {
2600-
t.Align = c.ptrSize
2603+
// t.Align is the alignment of the Go type.
2604+
t.Align = 1
26012605
}
26022606

26032607
case *dwarf.PtrType:
@@ -2826,6 +2830,11 @@ func (c *typeConv) loadType(dtype dwarf.Type, pos token.Pos, parent string) *Typ
28262830
if dt.BitSize > 0 {
28272831
fatalf("%s: unexpected: %d-bit uint type - %s", lineno(pos), dt.BitSize, dtype)
28282832
}
2833+
2834+
if t.Align = t.Size; t.Align >= c.ptrSize {
2835+
t.Align = c.ptrSize
2836+
}
2837+
28292838
switch t.Size {
28302839
default:
28312840
fatalf("%s: unexpected: %d-byte uint type - %s", lineno(pos), t.Size, dtype)
@@ -2842,9 +2851,8 @@ func (c *typeConv) loadType(dtype dwarf.Type, pos token.Pos, parent string) *Typ
28422851
Len: c.intExpr(t.Size),
28432852
Elt: c.uint8,
28442853
}
2845-
}
2846-
if t.Align = t.Size; t.Align >= c.ptrSize {
2847-
t.Align = c.ptrSize
2854+
// t.Align is the alignment of the Go type.
2855+
t.Align = 1
28482856
}
28492857

28502858
case *dwarf.VoidType:
@@ -3110,10 +3118,11 @@ func (c *typeConv) Struct(dt *dwarf.StructType, pos token.Pos) (expr *ast.Struct
31103118
}
31113119

31123120
// Round off up to talign, assumed to be a power of 2.
3121+
origOff := off
31133122
off = (off + talign - 1) &^ (talign - 1)
31143123

31153124
if f.ByteOffset > off {
3116-
fld, sizes = c.pad(fld, sizes, f.ByteOffset-off)
3125+
fld, sizes = c.pad(fld, sizes, f.ByteOffset-origOff)
31173126
off = f.ByteOffset
31183127
}
31193128
if f.ByteOffset < off {

src/cmd/cgo/internal/test/cgo_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ func Test31891(t *testing.T) { test31891(t) }
7070
func Test42018(t *testing.T) { test42018(t) }
7171
func Test45451(t *testing.T) { test45451(t) }
7272
func Test49633(t *testing.T) { test49633(t) }
73+
func Test69086(t *testing.T) { test69086(t) }
7374
func TestAlign(t *testing.T) { testAlign(t) }
7475
func TestAtol(t *testing.T) { testAtol(t) }
7576
func TestBlocking(t *testing.T) { testBlocking(t) }

src/cmd/cgo/internal/test/test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,19 @@ typedef struct issue45451Undefined issue45451;
933933
extern void GoFunc49633(void*);
934934
void cfunc49633(void *context) { GoFunc49633(context); }
935935
936+
// Issue 69086.
937+
// GCC added the __int128 type in GCC 4.6, released in 2011.
938+
typedef struct {
939+
int a;
940+
#ifdef __SIZEOF_INT128__
941+
unsigned __int128 b;
942+
#else
943+
uint64_t b;
944+
#endif
945+
unsigned char c;
946+
} issue69086struct;
947+
static int issue690861(issue69086struct* p) { p->b = 1234; return p->c; }
948+
static int issue690862(unsigned long ul1, unsigned long ul2, unsigned int u, issue69086struct s) { return (int)(s.b); }
936949
*/
937950
import "C"
938951

@@ -2321,3 +2334,24 @@ func test45451(t *testing.T) {
23212334
func func52542[T ~[]C.int]() {}
23222335

23232336
type type52542[T ~*C.float] struct{}
2337+
2338+
// Issue 69086.
2339+
func test69086(t *testing.T) {
2340+
var s C.issue69086struct
2341+
2342+
typ := reflect.TypeOf(s)
2343+
for i := 0; i < typ.NumField(); i++ {
2344+
f := typ.Field(i)
2345+
t.Logf("field %d: name %s size %d align %d offset %d", i, f.Name, f.Type.Size(), f.Type.Align(), f.Offset)
2346+
}
2347+
2348+
s.c = 1
2349+
got := C.issue690861(&s)
2350+
if got != 1 {
2351+
t.Errorf("field: got %d, want 1", got)
2352+
}
2353+
got = C.issue690862(1, 2, 3, s)
2354+
if got != 1234 {
2355+
t.Errorf("call: got %d, want 1234", got)
2356+
}
2357+
}

src/cmd/cgo/internal/testcarchive/carchive_test.go

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,22 +1224,14 @@ func TestManyCalls(t *testing.T) {
12241224
}
12251225

12261226
argv := cmdToRun("./testp7")
1227-
cmd = exec.Command(argv[0], argv[1:]...)
1227+
cmd = testenv.Command(t, argv[0], argv[1:]...)
12281228
sb := new(strings.Builder)
12291229
cmd.Stdout = sb
12301230
cmd.Stderr = sb
12311231
if err := cmd.Start(); err != nil {
12321232
t.Fatal(err)
12331233
}
12341234

1235-
timer := time.AfterFunc(time.Minute,
1236-
func() {
1237-
t.Error("test program timed out")
1238-
cmd.Process.Kill()
1239-
},
1240-
)
1241-
defer timer.Stop()
1242-
12431235
err = cmd.Wait()
12441236
t.Logf("%v\n%s", cmd.Args, sb)
12451237
if err != nil {
@@ -1284,22 +1276,14 @@ func TestPreemption(t *testing.T) {
12841276
}
12851277

12861278
argv := cmdToRun("./testp8")
1287-
cmd = exec.Command(argv[0], argv[1:]...)
1279+
cmd = testenv.Command(t, argv[0], argv[1:]...)
12881280
sb := new(strings.Builder)
12891281
cmd.Stdout = sb
12901282
cmd.Stderr = sb
12911283
if err := cmd.Start(); err != nil {
12921284
t.Fatal(err)
12931285
}
12941286

1295-
timer := time.AfterFunc(time.Minute,
1296-
func() {
1297-
t.Error("test program timed out")
1298-
cmd.Process.Kill()
1299-
},
1300-
)
1301-
defer timer.Stop()
1302-
13031287
err = cmd.Wait()
13041288
t.Logf("%v\n%s", cmd.Args, sb)
13051289
if err != nil {

src/cmd/compile/internal/ssa/writebarrier.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ func writebarrier(f *Func) {
252252
var start, end int
253253
var nonPtrStores int
254254
values := b.Values
255+
hasMove := false
255256
FindSeq:
256257
for i := len(values) - 1; i >= 0; i-- {
257258
w := values[i]
@@ -263,6 +264,9 @@ func writebarrier(f *Func) {
263264
end = i + 1
264265
}
265266
nonPtrStores = 0
267+
if w.Op == OpMoveWB {
268+
hasMove = true
269+
}
266270
case OpVarDef, OpVarLive:
267271
continue
268272
case OpStore:
@@ -273,6 +277,17 @@ func writebarrier(f *Func) {
273277
if nonPtrStores > 2 {
274278
break FindSeq
275279
}
280+
if hasMove {
281+
// We need to ensure that this store happens
282+
// before we issue a wbMove, as the wbMove might
283+
// use the result of this store as its source.
284+
// Even though this store is not write-barrier
285+
// eligible, it might nevertheless be the store
286+
// of a pointer to the stack, which is then the
287+
// source of the move.
288+
// See issue 71228.
289+
break FindSeq
290+
}
276291
default:
277292
if last == nil {
278293
continue

src/cmd/fix/buildtag.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ package main
66

77
import (
88
"go/ast"
9+
"go/version"
910
"strings"
1011
)
1112

1213
func init() {
1314
register(buildtagFix)
1415
}
1516

16-
const buildtagGoVersionCutoff = 1_18
17+
const buildtagGoVersionCutoff = "go1.18"
1718

1819
var buildtagFix = fix{
1920
name: "buildtag",
@@ -23,7 +24,7 @@ var buildtagFix = fix{
2324
}
2425

2526
func buildtag(f *ast.File) bool {
26-
if goVersion < buildtagGoVersionCutoff {
27+
if version.Compare(*goVersion, buildtagGoVersionCutoff) < 0 {
2728
return false
2829
}
2930

src/cmd/fix/buildtag_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ func init() {
1111
var buildtagTests = []testCase{
1212
{
1313
Name: "buildtag.oldGo",
14-
Version: 1_10,
14+
Version: "go1.10",
1515
In: `//go:build yes
1616
// +build yes
1717
@@ -20,7 +20,7 @@ package main
2020
},
2121
{
2222
Name: "buildtag.new",
23-
Version: 1_99,
23+
Version: "go1.99",
2424
In: `//go:build yes
2525
// +build yes
2626

src/cmd/fix/main.go

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ import (
1313
"go/parser"
1414
"go/scanner"
1515
"go/token"
16+
"go/version"
1617
"internal/diff"
1718
"io"
1819
"io/fs"
1920
"os"
2021
"path/filepath"
2122
"sort"
22-
"strconv"
2323
"strings"
2424
)
2525

@@ -37,10 +37,8 @@ var forceRewrites = flag.String("force", "",
3737
var allowed, force map[string]bool
3838

3939
var (
40-
doDiff = flag.Bool("diff", false, "display diffs instead of rewriting files")
41-
goVersionStr = flag.String("go", "", "go language version for files")
42-
43-
goVersion int // 115 for go1.15
40+
doDiff = flag.Bool("diff", false, "display diffs instead of rewriting files")
41+
goVersion = flag.String("go", "", "go language version for files")
4442
)
4543

4644
// enable for debugging fix failures
@@ -68,24 +66,9 @@ func main() {
6866
flag.Usage = usage
6967
flag.Parse()
7068

71-
if *goVersionStr != "" {
72-
if !strings.HasPrefix(*goVersionStr, "go") {
73-
report(fmt.Errorf("invalid -go=%s", *goVersionStr))
74-
os.Exit(exitCode)
75-
}
76-
majorStr := (*goVersionStr)[len("go"):]
77-
minorStr := "0"
78-
if before, after, found := strings.Cut(majorStr, "."); found {
79-
majorStr, minorStr = before, after
80-
}
81-
major, err1 := strconv.Atoi(majorStr)
82-
minor, err2 := strconv.Atoi(minorStr)
83-
if err1 != nil || err2 != nil || major < 0 || major >= 100 || minor < 0 || minor >= 100 {
84-
report(fmt.Errorf("invalid -go=%s", *goVersionStr))
85-
os.Exit(exitCode)
86-
}
87-
88-
goVersion = major*100 + minor
69+
if !version.IsValid(*goVersion) {
70+
report(fmt.Errorf("invalid -go=%s", *goVersion))
71+
os.Exit(exitCode)
8972
}
9073

9174
sort.Sort(byDate(fixes))

src/cmd/fix/main_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
type testCase struct {
1818
Name string
1919
Fn func(*ast.File) bool
20-
Version int
20+
Version string
2121
In string
2222
Out string
2323
}
@@ -96,7 +96,7 @@ func TestRewrite(t *testing.T) {
9696
for _, tt := range testCases {
9797
tt := tt
9898
t.Run(tt.Name, func(t *testing.T) {
99-
if tt.Version == 0 {
99+
if tt.Version == "" {
100100
if testing.Verbose() {
101101
// Don't run in parallel: cmd/fix sometimes writes directly to stderr,
102102
// and since -v prints which test is currently running we want that
@@ -105,10 +105,10 @@ func TestRewrite(t *testing.T) {
105105
t.Parallel()
106106
}
107107
} else {
108-
old := goVersion
109-
goVersion = tt.Version
108+
old := *goVersion
109+
*goVersion = tt.Version
110110
defer func() {
111-
goVersion = old
111+
*goVersion = old
112112
}()
113113
}
114114

0 commit comments

Comments
 (0)