Skip to content

Commit

Permalink
Merge pull request #97 from tailscale/update-go1.23.1
Browse files Browse the repository at this point in the history
Update go1.23.1
  • Loading branch information
patrickod authored Sep 6, 2024
2 parents 32389dd + e31cc2c commit 0a7392b
Show file tree
Hide file tree
Showing 56 changed files with 879 additions and 246 deletions.
4 changes: 2 additions & 2 deletions VERSION
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
go1.23.0
time 2024-08-07T19:21:44Z
go1.23.1
time 2024-08-29T20:56:24Z
23 changes: 16 additions & 7 deletions src/cmd/cgo/gcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2579,6 +2579,11 @@ func (c *typeConv) loadType(dtype dwarf.Type, pos token.Pos, parent string) *Typ
if dt.BitSize > 0 {
fatalf("%s: unexpected: %d-bit int type - %s", lineno(pos), dt.BitSize, dtype)
}

if t.Align = t.Size; t.Align >= c.ptrSize {
t.Align = c.ptrSize
}

switch t.Size {
default:
fatalf("%s: unexpected: %d-byte int type - %s", lineno(pos), t.Size, dtype)
Expand All @@ -2595,9 +2600,8 @@ func (c *typeConv) loadType(dtype dwarf.Type, pos token.Pos, parent string) *Typ
Len: c.intExpr(t.Size),
Elt: c.uint8,
}
}
if t.Align = t.Size; t.Align >= c.ptrSize {
t.Align = c.ptrSize
// t.Align is the alignment of the Go type.
t.Align = 1
}

case *dwarf.PtrType:
Expand Down Expand Up @@ -2826,6 +2830,11 @@ func (c *typeConv) loadType(dtype dwarf.Type, pos token.Pos, parent string) *Typ
if dt.BitSize > 0 {
fatalf("%s: unexpected: %d-bit uint type - %s", lineno(pos), dt.BitSize, dtype)
}

if t.Align = t.Size; t.Align >= c.ptrSize {
t.Align = c.ptrSize
}

switch t.Size {
default:
fatalf("%s: unexpected: %d-byte uint type - %s", lineno(pos), t.Size, dtype)
Expand All @@ -2842,9 +2851,8 @@ func (c *typeConv) loadType(dtype dwarf.Type, pos token.Pos, parent string) *Typ
Len: c.intExpr(t.Size),
Elt: c.uint8,
}
}
if t.Align = t.Size; t.Align >= c.ptrSize {
t.Align = c.ptrSize
// t.Align is the alignment of the Go type.
t.Align = 1
}

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

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

if f.ByteOffset > off {
fld, sizes = c.pad(fld, sizes, f.ByteOffset-off)
fld, sizes = c.pad(fld, sizes, f.ByteOffset-origOff)
off = f.ByteOffset
}
if f.ByteOffset < off {
Expand Down
1 change: 1 addition & 0 deletions src/cmd/cgo/internal/test/cgo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func Test31891(t *testing.T) { test31891(t) }
func Test42018(t *testing.T) { test42018(t) }
func Test45451(t *testing.T) { test45451(t) }
func Test49633(t *testing.T) { test49633(t) }
func Test69086(t *testing.T) { test69086(t) }
func TestAlign(t *testing.T) { testAlign(t) }
func TestAtol(t *testing.T) { testAtol(t) }
func TestBlocking(t *testing.T) { testBlocking(t) }
Expand Down
34 changes: 34 additions & 0 deletions src/cmd/cgo/internal/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,19 @@ typedef struct {
} issue67517struct;
static void issue67517(issue67517struct* p) {}
// Issue 69086.
// GCC added the __int128 type in GCC 4.6, released in 2011.
typedef struct {
int a;
#ifdef __SIZEOF_INT128__
unsigned __int128 b;
#else
uint64_t b;
#endif
unsigned char c;
} issue69086struct;
static int issue690861(issue69086struct* p) { p->b = 1234; return p->c; }
static int issue690862(unsigned long ul1, unsigned long ul2, unsigned int u, issue69086struct s) { return (int)(s.b); }
*/
import "C"

Expand Down Expand Up @@ -2349,3 +2362,24 @@ func issue67517() {
b: nil,
})
}

// Issue 69086.
func test69086(t *testing.T) {
var s C.issue69086struct

typ := reflect.TypeOf(s)
for i := 0; i < typ.NumField(); i++ {
f := typ.Field(i)
t.Logf("field %d: name %s size %d align %d offset %d", i, f.Name, f.Type.Size(), f.Type.Align(), f.Offset)
}

s.c = 1
got := C.issue690861(&s)
if got != 1 {
t.Errorf("field: got %d, want 1", got)
}
got = C.issue690862(1, 2, 3, s)
if got != 1234 {
t.Errorf("call: got %d, want 1234", got)
}
}
50 changes: 38 additions & 12 deletions src/cmd/compile/internal/types2/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2898,22 +2898,48 @@ func TestFileVersions(t *testing.T) {
fileVersion string
wantVersion string
}{
{"", "", ""}, // no versions specified
{"go1.19", "", "go1.19"}, // module version specified
{"", "go1.20", ""}, // file upgrade ignored
{"go1.19", "go1.20", "go1.20"}, // file upgrade permitted
{"go1.20", "go1.19", "go1.20"}, // file downgrade not permitted
{"go1.21", "go1.19", "go1.19"}, // file downgrade permitted (module version is >= go1.21)
{"", "", ""}, // no versions specified
{"go1.19", "", "go1.19"}, // module version specified
{"", "go1.20", "go1.21"}, // file version specified below minimum of 1.21
{"go1", "", "go1"}, // no file version specified
{"go1", "goo1.22", "go1"}, // invalid file version specified
{"go1", "go1.19", "go1.21"}, // file version specified below minimum of 1.21
{"go1", "go1.20", "go1.21"}, // file version specified below minimum of 1.21
{"go1", "go1.21", "go1.21"}, // file version specified at 1.21
{"go1", "go1.22", "go1.22"}, // file version specified above 1.21
{"go1.19", "", "go1.19"}, // no file version specified
{"go1.19", "goo1.22", "go1.19"}, // invalid file version specified
{"go1.19", "go1.20", "go1.21"}, // file version specified below minimum of 1.21
{"go1.19", "go1.21", "go1.21"}, // file version specified at 1.21
{"go1.19", "go1.22", "go1.22"}, // file version specified above 1.21
{"go1.20", "", "go1.20"}, // no file version specified
{"go1.20", "goo1.22", "go1.20"}, // invalid file version specified
{"go1.20", "go1.19", "go1.21"}, // file version specified below minimum of 1.21
{"go1.20", "go1.20", "go1.21"}, // file version specified below minimum of 1.21
{"go1.20", "go1.21", "go1.21"}, // file version specified at 1.21
{"go1.20", "go1.22", "go1.22"}, // file version specified above 1.21
{"go1.21", "", "go1.21"}, // no file version specified
{"go1.21", "goo1.22", "go1.21"}, // invalid file version specified
{"go1.21", "go1.19", "go1.21"}, // file version specified below minimum of 1.21
{"go1.21", "go1.20", "go1.21"}, // file version specified below minimum of 1.21
{"go1.21", "go1.21", "go1.21"}, // file version specified at 1.21
{"go1.21", "go1.22", "go1.22"}, // file version specified above 1.21
{"go1.22", "", "go1.22"}, // no file version specified
{"go1.22", "goo1.22", "go1.22"}, // invalid file version specified
{"go1.22", "go1.19", "go1.21"}, // file version specified below minimum of 1.21
{"go1.22", "go1.20", "go1.21"}, // file version specified below minimum of 1.21
{"go1.22", "go1.21", "go1.21"}, // file version specified at 1.21
{"go1.22", "go1.22", "go1.22"}, // file version specified above 1.21

// versions containing release numbers
// (file versions containing release numbers are considered invalid)
{"go1.19.0", "", "go1.19.0"}, // no file version specified
{"go1.20", "go1.20.1", "go1.20"}, // file upgrade ignored
{"go1.20.1", "go1.20", "go1.20.1"}, // file upgrade ignored
{"go1.20.1", "go1.21", "go1.21"}, // file upgrade permitted
{"go1.20.1", "go1.19", "go1.20.1"}, // file downgrade not permitted
{"go1.21.1", "go1.19.1", "go1.21.1"}, // file downgrade not permitted (invalid file version)
{"go1.21.1", "go1.19", "go1.19"}, // file downgrade permitted (module version is >= go1.21)
{"go1.20.1", "go1.19.1", "go1.20.1"}, // invalid file version
{"go1.20.1", "go1.21.1", "go1.20.1"}, // invalid file version
{"go1.21.1", "go1.19.1", "go1.21.1"}, // invalid file version
{"go1.21.1", "go1.21.1", "go1.21.1"}, // invalid file version
{"go1.22.1", "go1.19.1", "go1.22.1"}, // invalid file version
{"go1.22.1", "go1.21.1", "go1.22.1"}, // invalid file version
} {
var src string
if test.fileVersion != "" {
Expand Down
47 changes: 19 additions & 28 deletions src/cmd/compile/internal/types2/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,6 @@ func (check *Checker) initFiles(files []*syntax.File) {
check.errorf(files[0], TooNew, "package requires newer Go version %v (application built with %v)",
check.version, go_current)
}
downgradeOk := check.version.cmp(go1_21) >= 0

// determine Go version for each file
for _, file := range check.files {
Expand All @@ -336,33 +335,18 @@ func (check *Checker) initFiles(files []*syntax.File) {
// unlike file versions which are Go language versions only, if valid.)
v := check.conf.GoVersion

fileVersion := asGoVersion(file.GoVersion)
if fileVersion.isValid() {
// use the file version, if applicable
// (file versions are either the empty string or of the form go1.dd)
if pkgVersionOk {
cmp := fileVersion.cmp(check.version)
// Go 1.21 introduced the feature of setting the go.mod
// go line to an early version of Go and allowing //go:build lines
// to “upgrade” (cmp > 0) the Go version in a given file.
// We can do that backwards compatibly.
//
// Go 1.21 also introduced the feature of allowing //go:build lines
// to “downgrade” (cmp < 0) the Go version in a given file.
// That can't be done compatibly in general, since before the
// build lines were ignored and code got the module's Go version.
// To work around this, downgrades are only allowed when the
// module's Go version is Go 1.21 or later.
//
// If there is no valid check.version, then we don't really know what
// Go version to apply.
// Legacy tools may do this, and they historically have accepted everything.
// Preserve that behavior by ignoring //go:build constraints entirely in that
// case (!pkgVersionOk).
if cmp > 0 || cmp < 0 && downgradeOk {
v = file.GoVersion
}
}
// If the file specifies a version, use max(fileVersion, go1.21).
if fileVersion := asGoVersion(file.GoVersion); fileVersion.isValid() {
// Go 1.21 introduced the feature of allowing //go:build lines
// to sometimes set the Go version in a given file. Versions Go 1.21 and later
// can be set backwards compatibly as that was the first version
// files with go1.21 or later build tags could be built with.
//
// Set the version to max(fileVersion, go1.21): That will allow a
// downgrade to a version before go1.22, where the for loop semantics
// change was made, while being backwards compatible with versions of
// go before the new //go:build semantics were introduced.
v = string(versionMax(fileVersion, go1_21))

// Report a specific error for each tagged file that's too new.
// (Normally the build system will have filtered files by version,
Expand All @@ -377,6 +361,13 @@ func (check *Checker) initFiles(files []*syntax.File) {
}
}

func versionMax(a, b goVersion) goVersion {
if a.cmp(b) > 0 {
return a
}
return b
}

// A bailout panic is used for early termination.
type bailout struct{}

Expand Down
20 changes: 20 additions & 0 deletions src/cmd/compile/internal/types2/issues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1121,3 +1121,23 @@ func f(x int) {
t.Errorf("got: %s want: %s", got, want)
}
}

func TestIssue68877(t *testing.T) {
const src = `
package p
type (
S struct{}
A = S
T A
)`

conf := Config{EnableAlias: true}
pkg := mustTypecheck(src, &conf, nil)
T := pkg.Scope().Lookup("T").(*TypeName)
got := T.String() // this must not panic (was issue)
const want = "type p.T struct{}"
if got != want {
t.Errorf("got %s, want %s", got, want)
}
}
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/types2/named.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ func (t *Named) cleanup() {
if t.TypeArgs().Len() == 0 {
panic("nil underlying")
}
case *Named:
case *Named, *Alias:
t.under() // t.under may add entries to check.cleaners
}
t.check = nil
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/compile/internal/types2/typeset.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ func (s *_TypeSet) underIs(f func(Type) bool) bool {
}
for _, t := range s.terms {
assert(t.typ != nil)
// x == under(x) for ~x terms
u := t.typ
// Unalias(x) == under(x) for ~x terms
u := Unalias(t.typ)
if !t.tilde {
u = under(u)
}
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
golang.org/x/mod v0.19.0
golang.org/x/sync v0.7.0
golang.org/x/sys v0.22.0
golang.org/x/telemetry v0.0.0-20240717194752-0b706e19b701
golang.org/x/telemetry v0.0.0-20240828213427-40b6b7fe7147
golang.org/x/term v0.20.0
golang.org/x/tools v0.22.1-0.20240618181713-f2d2ebe43e72
)
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/telemetry v0.0.0-20240717194752-0b706e19b701 h1:+bltxAtk8YFEQ61B/lcYQM8e+7XjLwSDbpspVaVYkz8=
golang.org/x/telemetry v0.0.0-20240717194752-0b706e19b701/go.mod h1:amNmu/SBSm2GAF3X+9U2C0epLocdh+r5Z+7oMYO5cLM=
golang.org/x/telemetry v0.0.0-20240828213427-40b6b7fe7147 h1:Lj8KbuZmoFUbI6pQ28G3Diz/5bRYD2UY5vfAmhrLZWo=
golang.org/x/telemetry v0.0.0-20240828213427-40b6b7fe7147/go.mod h1:amNmu/SBSm2GAF3X+9U2C0epLocdh+r5Z+7oMYO5cLM=
golang.org/x/term v0.20.0 h1:VnkxpohqXaOBYJtBmEppKUG6mXpi+4O6purfc2+sMhw=
golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 18 additions & 3 deletions src/cmd/vendor/golang.org/x/telemetry/internal/upload/run.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0a7392b

Please sign in to comment.