mirror of
https://github.com/golang/go.git
synced 2026-04-04 02:10:08 +09:00
Merge List: + 2025-11-248dd5b13abccmd/compile: relax stmtline_test on amd64 + 2025-11-23feae743bdbcmd/compile: use 32x32->64 multiplies on loong64 + 2025-11-23e88be8a128runtime: fix stale comment for mheap/malloc + 2025-11-23a318843a2acmd/internal/obj/loong64: optimize duplicate optab entries + 2025-11-23a18294bb6acmd/internal/obj/arm64, image/gif, runtime, sort: use math/bits to calculate log2 + 2025-11-23437323ef7bslices: fix incorrect comment in slices.Insert function documentation + 2025-11-231993dca400doc/next: pre-announce end of support for macOS 12 in Go 1.27 + 2025-11-22337f7b1f5dcmd/go: update default go directive in mod or work init + 2025-11-213c26aef8fbcmd/internal/obj/riscv: improve large branch/call/jump tests + 2025-11-2131aa9f800bcrypto/tls: use inner hello for earlyData when using QUIC and ECH + 2025-11-21d68aec8db1runtime: replace trace seqlock with write flag + 2025-11-218d9906cd34runtime/trace: add Log benchmark + 2025-11-216aeacdff38cmd/go: support sha1 repos when git default is sha256 + 2025-11-219570036ca5crypto/sha3: make the zero value of SHAKE useable + 2025-11-21155efbbeebcrypto/sha3: make the zero value of SHA3 useable + 2025-11-216f16669e34database/sql: don't ignore ColumnConverter for unknown input count + 2025-11-21121bc3e464runtime/pprof: remove hard-coded sleep in CPU profile reader + 2025-11-21b604148c4eruntime: fix double wakeup in CPU profile buffer + 2025-11-2122f24f90b5cmd/compile: change testing.B.Loop keep alive semantic + 2025-11-21cfb9d2eb73net: remove unused linknames + 2025-11-2165ef314f89net/http: remove unused linknames + 2025-11-210f32fbc631net/http: populate Response.Request when using NewFileTransport + 2025-11-213e0a8e7867net/http: preserve original path encoding in redirects + 2025-11-21831af61120net/http: use HTTP 307 redirects in ServeMux + 2025-11-2187269224cbnet/http: update Response.Request.URL after redirects on GOOS=js + 2025-11-217aa9ca729fnet/http/cookiejar: treat localhost as secure origin + 2025-11-21f870a1d398net/url: warn that JoinPath arguments should be escaped + 2025-11-219962d95fedcrypto/internal/fips140/mldsa: unroll NTT and inverseNTT + 2025-11-21f821fc46c5crypto/internal/fisp140test: update acvptool, test data + 2025-11-21b59efc38a0crypto/internal/fips140/mldsa: new package + 2025-11-2162741480b8runtime: remove linkname for gopanic + 2025-11-217db2f0bb9acrypto/internal/hpke: separate KEM and PublicKey/PrivateKey interfaces + 2025-11-21e15800c0eccrypto/internal/hpke: add ML-KEM and hybrid KEMs, and SHAKE KDFs + 2025-11-217c985a2df4crypto/internal/hpke: modularize API and support more ciphersuites + 2025-11-21e7d47ac33dcmd/compile: simplify negative on multiplication + 2025-11-2135d2712b32net/http: fix typo in Transport docs + 2025-11-2190c970cd0fnet: remove unnecessary loop variable copies in tests + 2025-11-219772d3a690cmd/cgo: strip top-level const qualifier from argument frame struct + 2025-11-211903782adeerrors: add examples for custom Is/As matching + 2025-11-21ec92bc6d63cmd/compile: rewrite Rsh to RshU if arguments are proved positive + 2025-11-213820f94c1dcmd/compile: propagate unsigned relations for Rsh if arguments are positive + 2025-11-21d474f1fd21cmd/compile: make dse track multiple shadowed ranges + 2025-11-21d0d0a72980cmd/compile/internal/ssa: correct type of ARM64 conditional instructions + 2025-11-21a9704f89eainternal/runtime/gc/scan: add AVX512 impl of filterNil. + 2025-11-21ccd389036acmd/internal/objabi: remove -V=goexperiment internal special case + 2025-11-21e7787b9ecaruntime: go fmt + 2025-11-2117b3b98796internal/strconv: go fmt + 2025-11-21c851827c68internal/trace: go fmt + 2025-11-21f87aaec53dcmd/compile: fix integer overflow in prove pass + 2025-11-21dbd2ab9992cmd/compile/internal: fix typos + 2025-11-21b9d86baae3cmd/compile/internal/devirtualize: fix typos + 2025-11-204b0e3cc1d6cmd/link: support loading R_LARCH_PCREL20_S2 and R_LARCH_CALL36 relocs + 2025-11-20cdba82c7d6cmd/internal/obj/loong64: add {,X}VSLT.{B/H/W/V}{,U} instructions support + 2025-11-20bd2b117c2ccrypto/tls: add QUICErrorEvent + 2025-11-203ad2e113fcnet/http/httputil: wrap ReverseProxy's outbound request body so Close is a noop + 2025-11-20d58b733646runtime: track goroutine location until actual STW + 2025-11-201bc54868d4cmd/vendor: update to x/tools@68724af + 2025-11-208c3195973bruntime: disable stack allocation tests on sanitizers + 2025-11-20ff654ea100net/url: permit colons in the host of postgresql:// URLs + 2025-11-20a662badab9encoding/json: remove linknames + 2025-11-205afe237d65mime: add missing path for mime types in godoc + 2025-11-20c1b7112af8os/signal: make NotifyContext cancel the context with a cause Change-Id: Ib93ef643be610dfbdd83ff45095a7b1ca2537b8b
// Copyright 2018 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.
The codegen directory contains code generation tests for the gc
compiler.
- Introduction
The test harness compiles Go code inside files in this directory and
matches the generated assembly (the output of `go tool compile -S`)
against a set of regexps to be specified in comments that follow a
special syntax (described below). The test driver is implemented as
an action within the GOROOT/test test suite, called "asmcheck".
The codegen harness is part of the all.bash test suite, but for
performance reasons only the codegen tests for the host machine's
GOARCH are enabled by default, and only on GOOS=linux.
To perform comprehensive tests for all the supported architectures
(even on a non-Linux system), one can run the following command:
$ ../../bin/go test cmd/internal/testdir -run='Test/codegen' -all_codegen -v
This is recommended after any change that affect the compiler's code.
The test harness compiles the tests with the same go toolchain that is
used to run the test. After writing tests for a newly added codegen
transformation, it can be useful to first run the test harness with a
toolchain from a released Go version (and verify that the new tests
fail), and then re-running the tests using the devel toolchain.
- Regexps comments syntax
Instructions to match are specified inside plain comments that start
with an architecture tag, followed by a colon and a quoted Go-style
regexp to be matched. For example, the following test:
func Sqrt(x float64) float64 {
// amd64:"SQRTSD"
// arm64:"FSQRTD"
return math.Sqrt(x)
}
verifies that math.Sqrt calls are intrinsified to a SQRTSD instruction
on amd64, and to a FSQRTD instruction on arm64.
It is possible to put multiple architectures checks into the same
line, as:
// amd64:"SQRTSD" arm64:"FSQRTD"
although this form should be avoided when doing so would make the
regexps line excessively long and difficult to read.
Comments that are on their own line will be matched against the first
subsequent non-comment line. Inline comments are also supported; the
regexp will be matched against the code found on the same line:
func Sqrt(x float64) float64 {
return math.Sqrt(x) // arm:"SQRTD"
}
It's possible to specify a comma-separated list of regexps to be
matched. For example, the following test:
func TZ8(n uint8) int {
// amd64:"BSFQ","ORQ\t\\$256"
return bits.TrailingZeros8(n)
}
verifies that the code generated for a bits.TrailingZeros8 call on
amd64 contains both a "BSFQ" instruction and an "ORQ $256".
Note how the ORQ regex includes a tab char (\t). In the Go assembly
syntax, operands are separated from opcodes by a tabulation.
Regexps can be quoted using either " or `. Special characters must be
escaped accordingly. Both of these are accepted, and equivalent:
// amd64:"ADDQ\t\\$3"
// amd64:`ADDQ\t\$3`
and they'll match this assembly line:
ADDQ $3
Negative matches can be specified using a - before the quoted regexp.
For example:
func MoveSmall() {
x := [...]byte{1, 2, 3, 4, 5, 6, 7}
copy(x[1:], x[:]) // arm64:-".*memmove"
}
verifies that NO memmove call is present in the assembly generated for
the copy() line.
The expected number of matches for the regexp can be specified using a
positive number:
func fb(a [4]int) (r [4]int) {
// amd64:2`MOVUPS[^,]+, X0$`,2`MOVUPS\sX0,[^\n]+$`
return a
}
- Architecture specifiers
There are three different ways to specify on which architecture a test
should be run:
* Specify only the architecture (eg: "amd64"). This indicates that the
check should be run on all the supported architecture variants. For
instance, arm checks will be run against all supported GOARM
variations (5,6,7).
* Specify both the architecture and a variant, separated by a slash
(eg: "arm/7"). This means that the check will be run only on that
specific variant.
* Specify the operating system, the architecture and the variant,
separated by slashes (eg: "plan9/386/sse2", "plan9/amd64/"). This is
needed in the rare case that you need to do a codegen test affected
by a specific operating system; by default, tests are compiled only
targeting linux.
- Remarks, and Caveats
-- Write small test functions
As a general guideline, test functions should be small, to avoid
possible interactions between unrelated lines of code that may be
introduced, for example, by the compiler's optimization passes.
Any given line of Go code could get assigned more instructions than it
may appear from reading the source. In particular, matching all MOV
instructions should be avoided; the compiler may add them for
unrelated reasons and this may render the test ineffective.
-- Line matching logic
Regexps are always matched from the start of the instructions line.
This means, for example, that the "MULQ" regexp is equivalent to
"^MULQ" (^ representing the start of the line), and it will NOT match
the following assembly line:
IMULQ $99, AX
To force a match at any point of the line, ".*MULQ" should be used.
For the same reason, a negative regexp like -"memmove" is not enough
to make sure that no memmove call is included in the assembly. A
memmove call looks like this:
CALL runtime.memmove(SB)
To make sure that the "memmove" symbol does not appear anywhere in the
assembly, the negative regexp to be used is -".*memmove".