Skip to content

Commit 7653824

Browse files
Merge branch 'golang:master' into master
2 parents dfc76be + 6c3b5a2 commit 7653824

File tree

50 files changed

+465
-344
lines changed

Some content is hidden

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

50 files changed

+465
-344
lines changed

src/cmd/cgo/internal/testsanitizers/asan_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package sanitizers_test
88

99
import (
1010
"bytes"
11+
"crypto/fips140"
1112
"fmt"
1213
"internal/platform"
1314
"internal/testenv"
@@ -157,6 +158,10 @@ func mustHaveASAN(t *testing.T) *config {
157158
t.Skipf("skipping on %s/%s; -asan option is not supported.", goos, goarch)
158159
}
159160

161+
if fips140.Enabled() {
162+
t.Skipf("skipping with FIPS 140 mode; -asan option is not supported.")
163+
}
164+
160165
// The current implementation is only compatible with the ASan library from version
161166
// v7 to v9 (See the description in src/runtime/asan/asan.go). Therefore, using the
162167
// -asan option must use a compatible version of ASan library, which requires that

src/cmd/compile/internal/base/debug.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type DebugFlags struct {
4040
InlFuncsWithClosures int `help:"allow functions with closures to be inlined" concurrent:"ok"`
4141
InlStaticInit int `help:"allow static initialization of inlined calls" concurrent:"ok"`
4242
Libfuzzer int `help:"enable coverage instrumentation for libfuzzer"`
43+
LiteralAllocHash string `help:"hash value for use in debugging literal allocation optimizations" concurrent:"ok"`
4344
LoopVar int `help:"shared (0, default), 1 (private loop variables), 2, private + log"`
4445
LoopVarHash string `help:"for debugging changes in loop behavior. Overrides experiment and loopvar flag."`
4546
LocationLists int `help:"print information about DWARF location list creation"`

src/cmd/compile/internal/base/flag.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,10 @@ func ParseFlags() {
268268
if Debug.PGOHash != "" {
269269
PGOHash = NewHashDebug("pgohash", Debug.PGOHash, nil)
270270
}
271+
if Debug.LiteralAllocHash != "" {
272+
LiteralAllocHash = NewHashDebug("literalalloc", Debug.LiteralAllocHash, nil)
273+
}
274+
271275
if Debug.MergeLocalsHash != "" {
272276
MergeLocalsHash = NewHashDebug("mergelocals", Debug.MergeLocalsHash, nil)
273277
}

src/cmd/compile/internal/base/hashdebug.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ var hashDebug *HashDebug
5656
var FmaHash *HashDebug // for debugging fused-multiply-add floating point changes
5757
var LoopVarHash *HashDebug // for debugging shared/private loop variable changes
5858
var PGOHash *HashDebug // for debugging PGO optimization decisions
59+
var LiteralAllocHash *HashDebug // for debugging literal allocation optimizations
5960
var MergeLocalsHash *HashDebug // for debugging local stack slot merging changes
6061
var VariableMakeHash *HashDebug // for debugging variable-sized make optimizations
6162

src/cmd/compile/internal/escape/escape.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -534,10 +534,6 @@ func (b *batch) rewriteWithLiterals(n ir.Node, fn *ir.Func) {
534534
if n.Op() != ir.OMAKESLICE && n.Op() != ir.OCONVIFACE {
535535
return
536536
}
537-
if base.Flag.Cfg.CoverageInfo != nil {
538-
// Avoid altering coverage results.
539-
return
540-
}
541537

542538
// Look up a cached ReassignOracle for the function, lazily computing one if needed.
543539
ro := b.reassignOracle(fn)
@@ -571,6 +567,10 @@ func (b *batch) rewriteWithLiterals(n ir.Node, fn *ir.Func) {
571567
base.Fatalf("unexpected BasicLit Kind")
572568
}
573569
if constant.Compare(lit.Val(), token.GEQ, constant.MakeInt64(0)) {
570+
if !base.LiteralAllocHash.MatchPos(n.Pos(), nil) {
571+
// De-selected by literal alloc optimizations debug hash.
572+
return
573+
}
574574
// Preserve any side effects of the original expression, then replace it.
575575
assignTemp(*r, n.PtrInit())
576576
*r = lit
@@ -584,6 +584,10 @@ func (b *batch) rewriteWithLiterals(n ir.Node, fn *ir.Func) {
584584
if conv.X.Op() != ir.OLITERAL && !conv.X.Type().IsInterface() {
585585
v := ro.StaticValue(conv.X)
586586
if v != nil && v.Op() == ir.OLITERAL && ir.ValidTypeForConst(conv.X.Type(), v.Val()) {
587+
if !base.LiteralAllocHash.MatchPos(n.Pos(), nil) {
588+
// De-selected by literal alloc optimizations debug hash.
589+
return
590+
}
587591
if base.Debug.EscapeDebug >= 3 {
588592
base.WarnfAt(n.Pos(), "rewriting OCONVIFACE value from %v (%v) to %v (%v)", conv.X, conv.X.Type(), v, v.Type())
589593
}

src/cmd/compile/internal/walk/order.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,14 +246,18 @@ func (o *orderState) addrTemp(n ir.Node) ir.Node {
246246
if v == nil {
247247
v = n
248248
}
249+
optEnabled := func(n ir.Node) bool {
250+
// Do this optimization only when enabled for this node.
251+
return base.LiteralAllocHash.MatchPos(n.Pos(), nil)
252+
}
249253
if (v.Op() == ir.OSTRUCTLIT || v.Op() == ir.OARRAYLIT) && !base.Ctxt.IsFIPS() {
250-
if ir.IsZero(v) && 0 < v.Type().Size() && v.Type().Size() <= abi.ZeroValSize {
254+
if ir.IsZero(v) && 0 < v.Type().Size() && v.Type().Size() <= abi.ZeroValSize && optEnabled(n) {
251255
// This zero value can be represented by the read-only zeroVal.
252256
zeroVal := ir.NewLinksymExpr(v.Pos(), ir.Syms.ZeroVal, n.Type())
253257
vstat := typecheck.Expr(zeroVal).(*ir.LinksymOffsetExpr)
254258
return vstat
255259
}
256-
if isStaticCompositeLiteral(v) {
260+
if isStaticCompositeLiteral(v) && optEnabled(n) {
257261
// v can be directly represented in the read-only data section.
258262
lit := v.(*ir.CompLitExpr)
259263
vstat := readonlystaticname(n.Type())

src/cmd/go/alldocs.go

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

src/cmd/go/internal/doc/doc.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ different cases. If this occurs, documentation for all matches is printed.
7575
Examples:
7676
go doc
7777
Show documentation for current package.
78+
go doc -http
79+
Serve HTML documentation over HTTP for the current package.
7880
go doc Foo
7981
Show documentation for Foo in the current package.
8082
(Foo starts with a capital letter so it cannot match
@@ -116,6 +118,8 @@ Flags:
116118
Treat a command (package main) like a regular package.
117119
Otherwise package main's exported symbols are hidden
118120
when showing the package's top-level documentation.
121+
-http
122+
Serve HTML docs over HTTP.
119123
-short
120124
One-line representation for each symbol.
121125
-src

src/cmd/go/internal/modindex/build_read.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"go/ast"
1616
"go/build"
1717
"go/parser"
18+
"go/scanner"
1819
"go/token"
1920
"io"
2021
"strconv"
@@ -463,6 +464,13 @@ func readGoInfo(f io.Reader, info *fileInfo) error {
463464
if err != nil {
464465
return fmt.Errorf("parser returned invalid quoted string: <%s>", quoted)
465466
}
467+
if !isValidImport(path) {
468+
// The parser used to return a parse error for invalid import paths, but
469+
// no longer does, so check for and create the error here instead.
470+
info.parseErr = scanner.Error{Pos: info.fset.Position(spec.Pos()), Msg: "invalid import path: " + path}
471+
info.imports = nil
472+
return nil
473+
}
466474
if path == "embed" {
467475
hasEmbed = true
468476
}
@@ -520,6 +528,20 @@ func readGoInfo(f io.Reader, info *fileInfo) error {
520528
return nil
521529
}
522530

531+
// isValidImport checks if the import is a valid import using the more strict
532+
// checks allowed by the implementation restriction in https://go.dev/ref/spec#Import_declarations.
533+
// It was ported from the function of the same name that was removed from the
534+
// parser in CL 424855, when the parser stopped doing these checks.
535+
func isValidImport(s string) bool {
536+
const illegalChars = `!"#$%&'()*,:;<=>?[\]^{|}` + "`\uFFFD"
537+
for _, r := range s {
538+
if !unicode.IsGraphic(r) || unicode.IsSpace(r) || strings.ContainsRune(illegalChars, r) {
539+
return false
540+
}
541+
}
542+
return s != ""
543+
}
544+
523545
// parseGoEmbed parses the text following "//go:embed" to extract the glob patterns.
524546
// It accepts unquoted space-separated patterns as well as double-quoted and back-quoted Go strings.
525547
// This is based on a similar function in cmd/compile/internal/gc/noder.go;

src/cmd/internal/doc/main.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,16 @@ func doPkgsite(urlPath string) error {
227227
fields := strings.Fields(vars)
228228
if err == nil && len(fields) == 2 {
229229
goproxy, gomodcache := fields[0], fields[1]
230-
goproxy = "file://" + filepath.Join(gomodcache, "cache", "download") + "," + goproxy
231-
env = append(env, "GOPROXY="+goproxy)
230+
gomodcache = filepath.Join(gomodcache, "cache", "download")
231+
// Convert absolute path to file URL. pkgsite will not accept
232+
// Windows absolute paths because they look like a host:path remote.
233+
// TODO(golang.org/issue/32456): use url.FromFilePath when implemented.
234+
if strings.HasPrefix(gomodcache, "/") {
235+
gomodcache = "file://" + gomodcache
236+
} else {
237+
gomodcache = "file:///" + filepath.ToSlash(gomodcache)
238+
}
239+
env = append(env, "GOPROXY="+gomodcache+","+goproxy)
232240
}
233241

234242
const version = "v0.0.0-20250608123103-82c52f1754cd"

0 commit comments

Comments
 (0)