Skip to content

Commit f98f640

Browse files
committed
Merge branch 'release-branch.go1.24' of https://go.googlesource.com/go
2 parents 6d2c4a8 + f3a3023 commit f98f640

40 files changed

+855
-117
lines changed

src/cmd/compile/internal/inline/inl.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import (
4242
"cmd/compile/internal/types"
4343
"cmd/internal/obj"
4444
"cmd/internal/pgo"
45+
"cmd/internal/src"
4546
)
4647

4748
// Inlining budget parameters, gathered in one place
@@ -974,6 +975,16 @@ func inlineCostOK(n *ir.CallExpr, caller, callee *ir.Func, bigCaller, closureCal
974975
return true, 0, metric, hot
975976
}
976977

978+
// parsePos returns all the inlining positions and the innermost position.
979+
func parsePos(pos src.XPos, posTmp []src.Pos) ([]src.Pos, src.Pos) {
980+
ctxt := base.Ctxt
981+
ctxt.AllPos(pos, func(p src.Pos) {
982+
posTmp = append(posTmp, p)
983+
})
984+
l := len(posTmp) - 1
985+
return posTmp[:l], posTmp[l]
986+
}
987+
977988
// canInlineCallExpr returns true if the call n from caller to callee
978989
// can be inlined, plus the score computed for the call expr in question,
979990
// and whether the callee is hot according to PGO.
@@ -1001,6 +1012,17 @@ func canInlineCallExpr(callerfn *ir.Func, n *ir.CallExpr, callee *ir.Func, bigCa
10011012
return false, 0, false
10021013
}
10031014

1015+
callees, calleeInner := parsePos(n.Pos(), make([]src.Pos, 0, 10))
1016+
1017+
for _, p := range callees {
1018+
if p.Line() == calleeInner.Line() && p.Col() == calleeInner.Col() && p.AbsFilename() == calleeInner.AbsFilename() {
1019+
if log && logopt.Enabled() {
1020+
logopt.LogOpt(n.Pos(), "cannotInlineCall", "inline", fmt.Sprintf("recursive call to %s", ir.FuncName(callerfn)))
1021+
}
1022+
return false, 0, false
1023+
}
1024+
}
1025+
10041026
if callee == callerfn {
10051027
// Can't recursively inline a function into itself.
10061028
if log && logopt.Enabled() {
@@ -1040,6 +1062,28 @@ func canInlineCallExpr(callerfn *ir.Func, n *ir.CallExpr, callee *ir.Func, bigCa
10401062
return false, 0, false
10411063
}
10421064
}
1065+
do := func(fn *ir.Func) bool {
1066+
// Can't recursively inline a function if the function body contains
1067+
// a call to a function f, which the function f is one of the call arguments.
1068+
return ir.Any(fn, func(node ir.Node) bool {
1069+
if call, ok := node.(*ir.CallExpr); ok {
1070+
for _, arg := range call.Args {
1071+
if call.Fun == arg {
1072+
return true
1073+
}
1074+
}
1075+
}
1076+
return false
1077+
})
1078+
}
1079+
for _, fn := range []*ir.Func{callerfn, callee} {
1080+
if do(fn) {
1081+
if log && logopt.Enabled() {
1082+
logopt.LogOpt(n.Pos(), "cannotInlineCall", "inline", fmt.Sprintf("recursive call to function: %s", ir.FuncName(fn)))
1083+
}
1084+
return false, 0, false
1085+
}
1086+
}
10431087

10441088
if base.Flag.Cfg.Instrumenting && types.IsNoInstrumentPkg(callee.Sym().Pkg) {
10451089
// Runtime package must not be instrumented.

src/cmd/compile/internal/inline/interleaved/interleaved.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ func (s *inlClosureState) mark(n ir.Node) ir.Node {
253253

254254
if isTestingBLoop(n) {
255255
// No inlining nor devirtualization performed on b.Loop body
256-
if base.Flag.LowerM > 1 {
256+
if base.Flag.LowerM > 0 {
257257
fmt.Printf("%v: skip inlining within testing.B.loop for %v\n", ir.Line(n), n)
258258
}
259259
// We still want to explore inlining opportunities in other parts of ForStmt.

src/cmd/compile/internal/test/inl_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ func TestIntendedInlining(t *testing.T) {
230230
"(*Pointer[go.shape.int]).Store",
231231
"(*Pointer[go.shape.int]).Swap",
232232
},
233+
"testing": {
234+
"(*B).Loop",
235+
},
233236
}
234237

235238
if !goexperiment.SwissMap {

src/cmd/compile/internal/types2/assignments.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ func (check *Checker) lhsVar(lhs syntax.Expr) Type {
204204
// dot-imported variables.
205205
if w, _ := obj.(*Var); w != nil && w.pkg == check.pkg {
206206
v = w
207-
v_used = v.used
207+
v_used = check.usedVars[v]
208208
}
209209
}
210210
}
@@ -213,7 +213,7 @@ func (check *Checker) lhsVar(lhs syntax.Expr) Type {
213213
check.expr(nil, &x, lhs)
214214

215215
if v != nil {
216-
v.used = v_used // restore v.used
216+
check.usedVars[v] = v_used // restore v.used
217217
}
218218

219219
if x.mode == invalid || !isValid(x.typ) {

src/cmd/compile/internal/types2/call.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ func (check *Checker) selector(x *operand, e *syntax.SelectorExpr, def *TypeName
687687
if pname, _ := obj.(*PkgName); pname != nil {
688688
assert(pname.pkg == check.pkg)
689689
check.recordUse(ident, pname)
690-
pname.used = true
690+
check.usedPkgNames[pname] = true
691691
pkg := pname.imported
692692

693693
var exp Object
@@ -972,13 +972,13 @@ func (check *Checker) use1(e syntax.Expr, lhs bool) bool {
972972
// dot-imported variables.
973973
if w, _ := obj.(*Var); w != nil && w.pkg == check.pkg {
974974
v = w
975-
v_used = v.used
975+
v_used = check.usedVars[v]
976976
}
977977
}
978978
}
979979
check.exprOrType(&x, n, true)
980980
if v != nil {
981-
v.used = v_used // restore v.used
981+
check.usedVars[v] = v_used // restore v.used
982982
}
983983
case *syntax.ListExpr:
984984
return check.useN(n.ElemList, lhs)

src/cmd/compile/internal/types2/check.go

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ type Checker struct {
162162
dotImportMap map[dotImportKey]*PkgName // maps dot-imported objects to the package they were dot-imported through
163163
brokenAliases map[*TypeName]bool // set of aliases with broken (not yet determined) types
164164
unionTypeSets map[*Union]*_TypeSet // computed type sets for union types
165+
usedVars map[*Var]bool // set of used variables
166+
usedPkgNames map[*PkgName]bool // set of used package names
165167
mono monoGraph // graph for detecting non-monomorphizable instantiation loops
166168

167169
firstErr error // first error encountered
@@ -285,19 +287,23 @@ func NewChecker(conf *Config, pkg *Package, info *Info) *Checker {
285287
// (previously, pkg.goVersion was mutated here: go.dev/issue/61212)
286288

287289
return &Checker{
288-
conf: conf,
289-
ctxt: conf.Context,
290-
pkg: pkg,
291-
Info: info,
292-
objMap: make(map[Object]*declInfo),
293-
impMap: make(map[importKey]*Package),
290+
conf: conf,
291+
ctxt: conf.Context,
292+
pkg: pkg,
293+
Info: info,
294+
objMap: make(map[Object]*declInfo),
295+
impMap: make(map[importKey]*Package),
296+
usedVars: make(map[*Var]bool),
297+
usedPkgNames: make(map[*PkgName]bool),
294298
}
295299
}
296300

297301
// initFiles initializes the files-specific portion of checker.
298302
// The provided files must all belong to the same package.
299303
func (check *Checker) initFiles(files []*syntax.File) {
300304
// start with a clean slate (check.Files may be called multiple times)
305+
// TODO(gri): what determines which fields are zeroed out here, vs at the end
306+
// of checkFiles?
301307
check.files = nil
302308
check.imports = nil
303309
check.dotImportMap = nil
@@ -309,6 +315,13 @@ func (check *Checker) initFiles(files []*syntax.File) {
309315
check.objPath = nil
310316
check.cleaners = nil
311317

318+
// We must initialize usedVars and usedPkgNames both here and in NewChecker,
319+
// because initFiles is not called in the CheckExpr or Eval codepaths, yet we
320+
// want to free this memory at the end of Files ('used' predicates are
321+
// only needed in the context of a given file).
322+
check.usedVars = make(map[*Var]bool)
323+
check.usedPkgNames = make(map[*PkgName]bool)
324+
312325
// determine package name and collect valid files
313326
pkg := check.pkg
314327
for _, file := range files {
@@ -482,8 +495,11 @@ func (check *Checker) checkFiles(files []*syntax.File) {
482495
check.seenPkgMap = nil
483496
check.brokenAliases = nil
484497
check.unionTypeSets = nil
498+
check.usedVars = nil
499+
check.usedPkgNames = nil
485500
check.ctxt = nil
486501

502+
// TODO(gri): shouldn't the cleanup above occur after the bailout?
487503
// TODO(gri) There's more memory we should release at this point.
488504
}
489505

src/cmd/compile/internal/types2/object.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,12 @@ func (a *object) cmp(b *object) int {
242242
type PkgName struct {
243243
object
244244
imported *Package
245-
used bool // set if the package was used
246245
}
247246

248247
// NewPkgName returns a new PkgName object representing an imported package.
249248
// The remaining arguments set the attributes found with all Objects.
250249
func NewPkgName(pos syntax.Pos, pkg *Package, name string, imported *Package) *PkgName {
251-
return &PkgName{object{nil, pos, pkg, name, Typ[Invalid], 0, black, nopos}, imported, false}
250+
return &PkgName{object{nil, pos, pkg, name, Typ[Invalid], 0, black, nopos}, imported}
252251
}
253252

254253
// Imported returns the package that was imported.
@@ -331,10 +330,10 @@ func (obj *TypeName) IsAlias() bool {
331330
// A Variable represents a declared variable (including function parameters and results, and struct fields).
332331
type Var struct {
333332
object
333+
origin *Var // if non-nil, the Var from which this one was instantiated
334334
embedded bool // if set, the variable is an embedded struct field, and name is the type name
335335
isField bool // var is struct field
336-
used bool // set if the variable was used
337-
origin *Var // if non-nil, the Var from which this one was instantiated
336+
isParam bool // var is a param, for backport of 'used' check to go1.24 (go.dev/issue/72826)
338337
}
339338

340339
// NewVar returns a new variable.
@@ -345,7 +344,7 @@ func NewVar(pos syntax.Pos, pkg *Package, name string, typ Type) *Var {
345344

346345
// NewParam returns a new variable representing a function parameter.
347346
func NewParam(pos syntax.Pos, pkg *Package, name string, typ Type) *Var {
348-
return &Var{object: object{nil, pos, pkg, name, typ, 0, colorFor(typ), nopos}, used: true} // parameters are always 'used'
347+
return &Var{object: object{nil, pos, pkg, name, typ, 0, colorFor(typ), nopos}, isParam: true}
349348
}
350349

351350
// NewField returns a new variable representing a struct field.

src/cmd/compile/internal/types2/resolver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ func (check *Checker) collectObjects() {
295295

296296
if imp.fake {
297297
// match 1.17 cmd/compile (not prescribed by spec)
298-
pkgName.used = true
298+
check.usedPkgNames[pkgName] = true
299299
}
300300

301301
// add import to file scope
@@ -715,7 +715,7 @@ func (check *Checker) unusedImports() {
715715
// (initialization), use the blank identifier as explicit package name."
716716

717717
for _, obj := range check.imports {
718-
if !obj.used && obj.name != "_" {
718+
if obj.name != "_" && !check.usedPkgNames[obj] {
719719
check.errorUnusedPkg(obj)
720720
}
721721
}

src/cmd/compile/internal/types2/sizeof_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestSizeof(t *testing.T) {
3636
{term{}, 12, 24},
3737

3838
// Objects
39-
{PkgName{}, 64, 104},
39+
{PkgName{}, 60, 96},
4040
{Const{}, 64, 104},
4141
{TypeName{}, 56, 88},
4242
{Var{}, 64, 104},

src/cmd/compile/internal/types2/stmt.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (check *Checker) usage(scope *Scope) {
5858
var unused []*Var
5959
for name, elem := range scope.elems {
6060
elem = resolve(name, elem)
61-
if v, _ := elem.(*Var); v != nil && !v.used {
61+
if v, _ := elem.(*Var); v != nil && !v.isParam && !check.usedVars[v] {
6262
unused = append(unused, v)
6363
}
6464
}
@@ -824,10 +824,10 @@ func (check *Checker) typeSwitchStmt(inner stmtContext, s *syntax.SwitchStmt, gu
824824
if lhs != nil {
825825
var used bool
826826
for _, v := range lhsVars {
827-
if v.used {
827+
if check.usedVars[v] {
828828
used = true
829829
}
830-
v.used = true // avoid usage error when checking entire function
830+
check.usedVars[v] = true // avoid usage error when checking entire function
831831
}
832832
if !used {
833833
check.softErrorf(lhs, UnusedVar, "%s declared and not used", lhs.Value)
@@ -934,7 +934,7 @@ func (check *Checker) rangeStmt(inner stmtContext, s *syntax.ForStmt, rclause *s
934934
if typ == nil || typ == Typ[Invalid] {
935935
// typ == Typ[Invalid] can happen if allowVersion fails.
936936
obj.typ = Typ[Invalid]
937-
obj.used = true // don't complain about unused variable
937+
check.usedVars[obj] = true // don't complain about unused variable
938938
continue
939939
}
940940

src/cmd/compile/internal/types2/typexpr.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (check *Checker) ident(x *operand, e *syntax.Name, def *TypeName, wantType
5555
// avoid "declared but not used" errors
5656
// (don't use Checker.use - we don't want to evaluate too much)
5757
if v, _ := obj.(*Var); v != nil && v.pkg == check.pkg /* see Checker.use1 */ {
58-
v.used = true
58+
check.usedVars[v] = true
5959
}
6060
return
6161
}
@@ -83,7 +83,7 @@ func (check *Checker) ident(x *operand, e *syntax.Name, def *TypeName, wantType
8383
// (This code is only needed for dot-imports. Without them,
8484
// we only have to mark variables, see *Var case below).
8585
if pkgName := check.dotImportMap[dotImportKey{scope, obj.Name()}]; pkgName != nil {
86-
pkgName.used = true
86+
check.usedPkgNames[pkgName] = true
8787
}
8888

8989
switch obj := obj.(type) {
@@ -120,7 +120,7 @@ func (check *Checker) ident(x *operand, e *syntax.Name, def *TypeName, wantType
120120
// from other packages to avoid potential race conditions with
121121
// dot-imported variables.
122122
if obj.pkg == check.pkg {
123-
obj.used = true
123+
check.usedVars[obj] = true
124124
}
125125
check.addDeclDep(obj)
126126
if !isValid(typ) {

src/cmd/internal/objabi/pkgspecial.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ type PkgSpecial struct {
4343
}
4444

4545
var runtimePkgs = []string{
46+
// TODO(panjf2000): consider syncing the list inside the
47+
// isAsyncSafePoint in preempt.go based on this list?
48+
4649
"runtime",
4750

4851
"internal/runtime/atomic",

src/crypto/tls/defaults.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ var defaultCipherSuitesTLS13NoAES = []uint16{
9292
}
9393

9494
// The FIPS-only policies below match BoringSSL's
95-
// ssl_compliance_policy_fips_202205, which is based on NIST SP 800-52r2.
95+
// ssl_compliance_policy_fips_202205, which is based on NIST SP 800-52r2, with
96+
// minor changes per https://go.dev/issue/71757.
9697
// https://cs.opensource.google/boringssl/boringssl/+/master:ssl/ssl_lib.cc;l=3289;drc=ea7a88fa
9798

9899
var defaultSupportedVersionsFIPS = []uint16{
@@ -102,7 +103,7 @@ var defaultSupportedVersionsFIPS = []uint16{
102103

103104
// defaultCurvePreferencesFIPS are the FIPS-allowed curves,
104105
// in preference order (most preferable first).
105-
var defaultCurvePreferencesFIPS = []CurveID{CurveP256, CurveP384}
106+
var defaultCurvePreferencesFIPS = []CurveID{CurveP256, CurveP384, CurveP521}
106107

107108
// defaultSupportedSignatureAlgorithmsFIPS currently are a subset of
108109
// defaultSupportedSignatureAlgorithms without Ed25519 and SHA-1.
@@ -115,6 +116,7 @@ var defaultSupportedSignatureAlgorithmsFIPS = []SignatureScheme{
115116
PKCS1WithSHA384,
116117
ECDSAWithP384AndSHA384,
117118
PKCS1WithSHA512,
119+
ECDSAWithP521AndSHA512,
118120
}
119121

120122
// defaultCipherSuitesFIPS are the FIPS-allowed cipher suites.

src/crypto/tls/fips_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func isFIPSCipherSuite(id uint16) bool {
106106

107107
func isFIPSCurve(id CurveID) bool {
108108
switch id {
109-
case CurveP256, CurveP384:
109+
case CurveP256, CurveP384, CurveP521:
110110
return true
111111
}
112112
return false
@@ -130,6 +130,7 @@ func isFIPSSignatureScheme(alg SignatureScheme) bool {
130130
PKCS1WithSHA384,
131131
ECDSAWithP384AndSHA384,
132132
PKCS1WithSHA512,
133+
ECDSAWithP521AndSHA512,
133134
PSSWithSHA256,
134135
PSSWithSHA384,
135136
PSSWithSHA512:

src/go/types/assignments.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)