Joel Sing [Thu, 28 Jan 2021 12:50:30 +0000 (23:50 +1100)]
runtime,syscall: convert syscall on openbsd/386 to libc
Convert the syscall package on openbsd/386 to use libc rather than performing
direct system calls.
Updates #36435
Change-Id: Ifcfbca0e6b933762596a564243caa850dac01442
Reviewed-on: https://go-review.googlesource.com/c/go/+/287654
Trust: Joel Sing <joel@sing.id.au>
Run-TryBot: Joel Sing <joel@sing.id.au> Reviewed-by: Cherry Zhang <cherryyz@google.com>
David Chase [Wed, 18 Nov 2020 00:54:31 +0000 (19:54 -0500)]
runtime: break up large calls to memclrNoHeapPointers to allow preemption
If something "huge" is allocated, and the zeroing is trivial (no pointers
involved) then zero it by chunks in a loop so that preemption can occur,
not all in a single non-preemptible call.
Benchmarking suggests that 256K is the best chunk size.
Updates #42642.
Change-Id: I94015e467eaa098c59870e479d6d83bc88efbfb4
Reviewed-on: https://go-review.googlesource.com/c/go/+/270943
Trust: David Chase <drchase@google.com>
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
Than McIntosh [Fri, 30 Apr 2021 15:15:44 +0000 (11:15 -0400)]
cmd/compile: fix abbrev selection for output params
In Cl 302071 we changed the compiler to use a different recipe for
selecting the DWARF frame offset for output parameters, to reflect the
fact that registerized output params don't have a stack memory
location on entry to the function. In the process, however, we
switched from using an abbrev pf DW_ABRV_PARAM to an abbrev of
DW_ABRV_AUTO, which means that Delve can't recognize them correctly.
To fix the problem, switch back to picking the correct abbrev entry,
while leaving the new offset recipe intact.
Updates #40724.
Updates #45720.
Change-Id: If721c9255bcd030177806576cde3450563f7a235
Reviewed-on: https://go-review.googlesource.com/c/go/+/315610
Trust: Than McIntosh <thanm@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
Than McIntosh [Thu, 29 Apr 2021 15:47:18 +0000 (11:47 -0400)]
cmd/compile: handle field padding for register-passed structs
When constructing multi-piece DWARF location expressions for
struct-typed parameters using the register ABI, make sure that the
location expressions generated properly reflect padding between
elements (this is required by debuggers). Example:
type small struct { x uint16 ; y uint8 ; z int32 }
func ABC(p1 int, p2 small, f1 float32) {
...
In the DWARF location expression for "p2" on entry to the routine, we
need pieces for each field, but for debuggers (such as GDB) to work
properly, we also need to describe the padding between elements. Thus
instead of
This patch adds a new helper routine in abiutils to compute the
correct padding amounts for a struct type, a unit test for the helper,
and updates the debug generation code to call the helper and insert
apadding "piece" ops in the right spots.
Updates #40724.
Updates #45720.
Change-Id: Ie208bee25776b9eb70642041869e65e4fa65a005
Reviewed-on: https://go-review.googlesource.com/c/go/+/315071
Trust: Than McIntosh <thanm@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
Than McIntosh [Tue, 27 Apr 2021 16:40:43 +0000 (12:40 -0400)]
cmd/compile: regabi support for DWARF location expressions
Revise the code that generates DWARF location expressions for input
parameters to get it to work properly with the new register ABI when
optimization is turned off.
The previously implementation assumed stack locations for all
input+output parameters when -N (disable optimization) was in effect.
In the new implementation, a register-resident input parameter is
given a 2-element location list, the first list element pointing to
the ABI register(s) containing the param, and the second element
pointing to the stack home once it has been spilled.
NB, this change fixes a bunch of the Delve pkg/proc unit tests (maybe
about half of the outstanding failures). Still a good number that need
to be investigated, however.
Updates #40724.
Updates #45720.
Change-Id: I743bbb9af187bcdebeb8e690fdd6db58094ca415
Reviewed-on: https://go-review.googlesource.com/c/go/+/314431
Trust: Than McIntosh <thanm@google.com>
Trust: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com> Reviewed-by: David Chase <drchase@google.com>
Joel Sing [Fri, 30 Apr 2021 18:47:00 +0000 (04:47 +1000)]
runtime: work around vet asmdecl checks for openbsd/386 mstart_stub
Include a NOP with the SP in order to disable/bypass vet asmdecl checks
for runtime.mstart_stub on openbsd/386. Without this we get:
runtime/sys_openbsd_386.s:33:1: [386] mstart_stub: use of 32(SP) points beyond argument frame
Change-Id: I834ae3dbceffcb5776481b076ec2afe3700671cf
Reviewed-on: https://go-review.googlesource.com/c/go/+/315789
Trust: Joel Sing <joel@sing.id.au> Reviewed-by: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Joel Sing <joel@sing.id.au>
Than McIntosh [Wed, 28 Apr 2021 22:26:54 +0000 (18:26 -0400)]
cmd/compile: revise block/func end sentinels in debug analysis
The SSA code for debug variable location analysis (for DWARF) has two
special 'sentinel' values that it uses to handshake with the
debugInfo.GetPC callback when capturing the PC values of debug
variable ranges after prog generatoin: "BlockStart" and "BlockEnd".
"BlockStart" has the expected semantics: it means "the PC value of the
first instruction of block B", but "BlockEnd" does not mean "PC value
of the last instruction of block B", but rather it is implemented as
"the PC value of the last instruction of the function". This causes
confusion when reading the code, and seems to to result in implementation
flaws in the past, leading to incorrect ranges in some cases.
To help with this, add a new sentinel "FuncEnd" (which has the "last
inst in the function" semantics) and change the implementation of
"BlockEnd" to actually mean what its name implies (last inst in
block).
Updates #45720.
Change-Id: Ic3497fb60413e898d2bfe27805c3db56483d12a2
Reviewed-on: https://go-review.googlesource.com/c/go/+/314930
Trust: Than McIntosh <thanm@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com> Reviewed-by: David Chase <drchase@google.com>
cmd/go: remove the special case for "unsafe" in importFromModules
The comment for this special case claims:
> There's no directory for import "C" or import "unsafe".
However, there clearly is a directory for "unsafe" in
GOROOT/src/unsafe, and all of our integration tests seem to pass
without this special case. As far as I can tell, it's just confusing.
Also note that the internal/goroot package explicitly considers
package "unsafe" to be in the standard library; see CL 137435.
For #36460
Change-Id: Ib857d18f731a7f3c911c1bd116a34e3a9b3d74a5
Reviewed-on: https://go-review.googlesource.com/c/go/+/315412
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org>
In order to prevent edit wars with previous cmd/go releases,
the new version annotations are only included if the main module
specifies 'go 1.17' or higher.
Fixes #36876
Change-Id: Iba15e47dd1ac2c16d754679a9b501db4069fa250
Reviewed-on: https://go-review.googlesource.com/c/go/+/315409
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org>
This change adds two possible upgrade paths for lazy loading:
1. Run 'go mod tidy -go=1.17'.
2. Starting in a module with no existing 'go' directive,
run any 'go' command that updates the go.mod file.
In the latter case, commands other than 'go mod tidy'
may leave the go.mod file *very* untidy if it had non-trivial
dependencies. (The 'go' invocation will promote all
implicit eager dependencies to explicit lazy ones,
which preserves the original module graph — most of which is
not actually relevant.)
'go mod tidy -go=1.17' can be used to enable lazy loading without
accidentally downgrading existing transitive dependencies.
'go mod tidy -go=1.16' can be used to disable lazy loading and clear
away redundant roots in a single step (if reducing the go version), or
to prune away dependencies of tests-of-external-tests (if increasing
the go version).
'go mod tidy -go=1.15' can be used to add dependencies of
tests-of-external-tests, although there isn't much point to that.
DO NOT MERGE
This change still needs an explicit test and a release note.
Fixes #45094
For #36460
Change-Id: I68f057e39489dfd6a667cd11dc1e320c1ee1aec1
Reviewed-on: https://go-review.googlesource.com/c/go/+/315210
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org>
This change activates the dormant “lazy loading” codepaths added in CL
265777 and its predecessors. Dependencies of modules that declare 'go
1.17' or higher are loaded lazily, and the dependencies in the go.mod
file maintain additional invariants to support more efficient lazy
loading for downstream dependent modules.
See https://golang.org/design/36460-lazy-module-loading for the
detailed design.
For #36460
Change-Id: Ic12ee7842aef9580357fcf8909d87654fcb2ad12
Reviewed-on: https://go-review.googlesource.com/c/go/+/314634
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org>
Ian Lance Taylor [Fri, 30 Apr 2021 04:10:05 +0000 (21:10 -0700)]
internal/buildcfg: enable regabi for Android
This will permit us to write ABIInternal assembler code for linux-amd64.
For #40724
Change-Id: I681866651554eda4229d6faa7f0c1ba42d07e57d
Reviewed-on: https://go-review.googlesource.com/c/go/+/315390
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
Robert Griesemer [Fri, 30 Apr 2021 17:20:38 +0000 (10:20 -0700)]
cmd/compile/internal/types2: list errors by default in TestManual
TestManual is used for debugging; in this case we usually want to
see error messages reported rather than checked against ERROR comments
in the provided files. Make this the default. Use the new -verify
flag to verify reported errors against ERROR comments.
With this change we cannot get an error list for the non-manual
tests, but that is usually not useful anyway because there are
usually many errors in those test files. Run those tests manually
instead.
Also, corrected -lang flag synopsys: it applies to all tests, not
just TestManual.
Change-Id: I56e0ea0583840fc3ea150d9ccfc330370b66191c
Reviewed-on: https://go-review.googlesource.com/c/go/+/315729
Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
Robert Griesemer [Fri, 30 Apr 2021 16:43:39 +0000 (09:43 -0700)]
cmd/compile/internal/types2: simplify use of TestManual
Running the TestManual test (for manual debugging) requires
user-provided files as input. Rather than using another flag
(-files) to provide these files, just use the (remaining)
command line arguments.
Change-Id: I9b20d9f1a6a7ce839bbd690c311ce3f0d0a10496
Reviewed-on: https://go-review.googlesource.com/c/go/+/315689
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
cmd/internal/objfile: emit better error for Go object of a different version
The Go object file format can change from version to version.
Tools like cmd/objdump and cmd/nm only onderstand the current
version of the object file. Currently, when it encounters an
object built with a different version of the toolchain, it emits
a generic error "unrecognized object file", which is not very
helpful for users. This CL makes it emit a clearer error. Now it
emits
objdump: open go116.o: go object of a different version: go116ld
Change-Id: I063c6078ed1da78f97cea65796779ae093a1a8cb
Reviewed-on: https://go-review.googlesource.com/c/go/+/315609
Trust: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
Change-Id: I897864984bd4b79f2e224ea1a7f323e0bd5e2ef0
GitHub-Last-Rev: b85415541d12128c7515af91b02c098617478a50
GitHub-Pull-Request: golang/go#45849
Reviewed-on: https://go-review.googlesource.com/c/go/+/314991 Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Ben Shi <powerman1st@163.com>
Trust: Matthew Dempsky <mdempsky@google.com>
Daniel Martí [Thu, 29 Apr 2021 21:54:26 +0000 (22:54 +0100)]
cmd/gofmt: always format non-directory arguments again
golang.org/cl/284138 introduced a regression: running "gofmt foo" would
silently ignore the file due to its lack of a ".go" extension, whereas
the tool is documented otherwise:
Given a file, it operates on that file; given a directory, it
operates on all .go files in that directory, recursively.
This wasn't caught as there were no tests for these edge cases. gofmt's
own tests are regular Go tests, so it's hard to test it properly without
adding an abstraction layer on top of func main.
Luckily, this kind of test is a great fit for cmd/go's own script tests,
and it just takes a few straightforward lines.
Finally, add the relevant logic back, with documentation to clarify its
intentional purpose.
Fixes #45859.
Change-Id: Ic5bf5937b8f95fcdad2b6933227c8b504ef38a82
Reviewed-on: https://go-review.googlesource.com/c/go/+/315270
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
Trust: Daniel Martí <mvdan@mvdan.cc>
Trust: Robert Griesemer <gri@golang.org>
Trust: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
eric fang [Thu, 29 Apr 2021 06:33:21 +0000 (06:33 +0000)]
cmd/internal/obj/arm64: fix the size of STP series instructions in optab
When the class of p.To is C_NAUTO4K, STP series instructions will be translated
into add/sub + stp instructions, the total size is 8. Currently this size
value in optab is 12, this CL fixes it.
Change-Id: Ife1b9e9f8a28edca9b59f62b45a80d83f38993b0
Reviewed-on: https://go-review.googlesource.com/c/go/+/314210 Reviewed-by: eric fang <eric.fang@arm.com> Reviewed-by: Cherry Zhang <cherryyz@google.com>
Trust: eric fang <eric.fang@arm.com>
Run-TryBot: eric fang <eric.fang@arm.com>
TryBot-Result: Go Bot <gobot@golang.org>
Dmitri Shuralyov [Thu, 29 Apr 2021 16:32:44 +0000 (12:32 -0400)]
api: update next.txt
There's no reason not to, and it'll help me test an upcoming fix
for #43956. The API additions look reasonable to me, and they'll
go through a more comprehensive API audit during the freeze.
Change-Id: I0daa6e978b199d69568f5100fdfc1b4bcfaeaef2
Reviewed-on: https://go-review.googlesource.com/c/go/+/315349
Trust: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Robert Griesemer [Thu, 29 Apr 2021 22:01:29 +0000 (15:01 -0700)]
math: increase precision of math.SmallestNonzeroFloat64
The original value was rounded too early, which lead to the
surprising behavior that float64(math.SmallestNonzeroFloat64 / 2)
wasn't 0. That is, the exact compile-time computation of
math.SmallestNonzeroFloat64 / 2 resulted in a value that was
rounded up when converting to float64. To address this, added 3
more digits to the mantissa, ending in a 0.
While at it, also slightly increased the precision of MaxFloat64
to end in a 0.
Computed exact values via https://play.golang.org/p/yt4KTpIx_wP.
Added a test to verify expected behavior.
In contrast to the other (irrational) constants, expanding these
extreme values to more digits is unlikely to be important as they
are not going to appear in numeric computations except for tests
verifying their correctness (as is the case here).
Re-enabled a disabled test in go/types and types2.
Updates #44057.
Fixes #44058.
Change-Id: I8f363155e02331354e929beabe993c8d8de75646
Reviewed-on: https://go-review.googlesource.com/c/go/+/315170
Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
cmd/compile, runtime: emit only GC data for stack objects
Currently, for stack objects, the compiler emits metadata that
includes the offset and type descriptor for each object. The type
descriptor symbol has many fields, and it references many other
symbols, e.g. field/element types, equality functions, names.
Observe that what we actually need at runtime is only the GC
metadata that are needed to scan the object, and the GC metadata
are "leaf" symbols (which doesn't reference other symbols). Emit
only the GC data instead. This avoids bringing live the type
descriptor as well as things referenced by it (if it is not
otherwise live).
Add missing version check. Even though this is a new types2 error
we separate between the compiler and the types2 error message: we
have the compiler error message to match the compiler style, and
we have a types2-specific error message to match the types2 style
for these kinds of errors (for now).
Eventually we need to decide which style we like better and clean
this up.
Follow-up on https://golang.org/cl/301650.
Updates #395.
Change-Id: I5b779f345994c66b1f4a4db466466f98b7d3c491
Reviewed-on: https://go-review.googlesource.com/c/go/+/315169
Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
This change adds four additional metrics to the runtime/metrics package
to fill in a few gaps with runtime.MemStats that were overlooked. The
biggest one is TotalAlloc, which is impossible to find with the
runtime/metrics package, but also add a few others for convenience and
clarity. For instance, the total number of objects allocated and freed
are technically available via allocs-by-size and frees-by-size, but it's
onerous to get them (one needs to sum the sample counts in the
histograms).
The four additional metrics are:
- /gc/heap/allocs:bytes -- total bytes allocated (TotalAlloc)
- /gc/heap/allocs:objects -- total objects allocated (Mallocs - [tiny])
- /gc/heap/frees:bytes -- total bytes frees (TotalAlloc-HeapAlloc)
- /gc/heap/frees:objects -- total objects freed (Frees - [tiny])
This change also updates the descriptions of allocs-by-size and
frees-by-size to be more precise.
Change-Id: Iec8c1797a584491e3484b198f2e7f325b68954a7
Reviewed-on: https://go-review.googlesource.com/c/go/+/312431 Reviewed-by: Michael Pratt <mpratt@google.com>
Trust: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Than McIntosh [Thu, 29 Apr 2021 18:52:24 +0000 (14:52 -0400)]
cmd/compile: minor doc enhancements
Add a little more detail to the ssa README relating to GOSSAFUNC.
Update the -d=ssa help section to give a little more detail on what
to expect with applying the /debug=X qualifier to a phase.
Change-Id: I7027735f1f2955dbb5b9be36d9a648e8dc655048
Reviewed-on: https://go-review.googlesource.com/c/go/+/315229
Trust: Than McIntosh <thanm@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
Roland Shoemaker [Thu, 29 Apr 2021 17:11:56 +0000 (10:11 -0700)]
crypto/elliptic: store P-256 precomputed basepoint table in source
Store the precomputed P-256 basepoint table in source rather than
computing it at runtime, saving ~88kB from the heap. The flip side
is that this increases binary sizes by ~77kB.
Fixes #44992
Change-Id: Ia5421eae87b41522b0d8cecba051cba1d2ed73db
Reviewed-on: https://go-review.googlesource.com/c/go/+/315189
Run-TryBot: Roland Shoemaker <roland@golang.org>
Trust: Roland Shoemaker <roland@golang.org>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Filippo Valsorda <filippo@golang.org>
Ian Lance Taylor [Mon, 19 Apr 2021 20:51:53 +0000 (13:51 -0700)]
archive/zip: only return directory once via io/fs.FS
While we're here fix the ModTime value for directories.
Fixes #43872
Fixes #45345
Change-Id: I155e6517713ef6a9482b9431f1167a44337c6ad2
Reviewed-on: https://go-review.googlesource.com/c/go/+/311530
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jeremy Faller <jeremy@golang.org>
Roger Peppe [Thu, 11 Feb 2021 13:54:45 +0000 (13:54 +0000)]
encoding/csv: add FieldPos method
This enables a consumer of a CSV to find out the position
of a CSV field without implementing an intermediate buffer.
This is useful to produce good higher level error messages when
the CSV syntax is OK but the field values don't match expectations.
This also changes the existing semantics of the `ParseError.Column`
field to bring it in line with precedent elsewhere in the Go
standard library (notably go/token.Position) - the column is
now 1-based and indicates a byte count rather than a rune count,
and the error position reporting at the end of a last line without
a newline is now fixed.
Change-Id: Id37c50fc396024eef406c5bad45380ecd414f5ea
Reviewed-on: https://go-review.googlesource.com/c/go/+/291290
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Paul Jolly <paul@myitcv.org.uk>
Keith Randall [Thu, 29 Apr 2021 06:07:38 +0000 (23:07 -0700)]
runtime: top align tinyallocs in race mode
Top align allocations in tinyalloc buckets when in race mode.
This will make checkptr checks more reliable, because any code
that modifies a pointer past the end of the object will trigger
a checkptr error.
No test, because we need -race for this to actually kick in. We could
add it to the race detector tests, but the race detector tests are all
geared towards race detector reports, not checkptr reports. Mucking
with parsing reports is more than a test is worth.
Fixes #38872
Change-Id: Ie56f0fbd1a9385539f6631fd1ac40c3de5600154
Reviewed-on: https://go-review.googlesource.com/c/go/+/315029
Trust: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Michael Anthony Knyszek [Mon, 16 Nov 2020 22:03:17 +0000 (22:03 +0000)]
runtime: use 4 MiB heap arenas on iOS
iOS arm64 is a 64-bit platform but with a strictly 32-bit address space
(technically 33 bits, but the bottom half is unavailable to the
application). Since address space is limited, use 4 MiB arenas instead
of 64 MiB arenas. No changes are needed to the arena index because it's
still relatively small; this change just brings iOS more in line with
32-bit platforms.
Rob Findley [Thu, 29 Apr 2021 15:42:35 +0000 (11:42 -0400)]
go/types: add additional test data from types2
Add some test data files that were not included in go/types.
- Issue 43125 only pertained to types2 because go/ast differentiates
StarExpr, UnaryExpr, and BinaryExpr, so typexpr.go was already
catching the invalid type expressions.
- Issues 42987 and 43190 are handled differently by go/parser.
- main.go2 was not added when ported to go/types, because this work
happened on the dev.regabi branch, which didn't support generics.
Test files are modified to adjust errors messages and positions, and to
update the copyright year.
Change-Id: Ia737eaab9afb2b59600b661ccf3eec3cbbb2d66c
Reviewed-on: https://go-review.googlesource.com/c/go/+/315070
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
cmd/link: support trampoline insertion for PLT calls on ARM64
When internal linking with C objects, some C object relocations
may be turned into a CALL via PLT. For very large programs, the
PLT stub may be laid too far.
PLT stubs are generated late in the linker, and laid out after
the end of the text section. So if the text section is big, the
PLT stubs are likely too far.
To avoid this situation, add trampolines for PLT calls in the
trampoline pass. Only do this when the program is known too large
(i.e. the second pass of the two-pass algorithm).
Compared to ARM32 or PPC64, ARM64 has larger range for direct jumps.
But for very large programs it can still go over the limit. Add
trampoline insertion for ARM64.
Ian Lance Taylor [Wed, 28 Apr 2021 20:06:55 +0000 (13:06 -0700)]
runtime: remove linux-amd64 walltime function
It's never called.
Change-Id: I8956743b21301816b5f37a9b34e3f50ef7b2e70a
Reviewed-on: https://go-review.googlesource.com/c/go/+/314771
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
Ian Lance Taylor [Wed, 28 Apr 2021 18:42:34 +0000 (11:42 -0700)]
runtime: rename walltime1 to walltime
Change-Id: Iec9de5ca56eb68d524bbaa0668515dbd09ad38a1
Reviewed-on: https://go-review.googlesource.com/c/go/+/314770
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
cmd/link: use a two-pass approach for trampoline insertion
Currently in the linker, for trampoline insertion it does a one-pass
approach, where it assigns addresses for each function and inserts
trampolines on the go. For this to work and not to emit too many
unnecessary trampolines, the functions need to be laid out in
dependency order, so a direct call's target is always as a known
address (or known to be not too far).
This mostly works, but there are a few exceptions:
- linkname can break dependency tree and cause cycles.
- in internal linking mode, on some platforms, some calls are turned
into calls via PLT, but the PLT stubs are inserted rather late.
Also, this is expensive in that it has to investigate all CALL
relocations.
This CL changes it to use a two-pass approach. The first pass is
just to assign addresses without inserting any trampolines, assuming
the program is not too big. If this succeeds, no extra work needs to
be done. If this fails, start over and insert trampolines for too-
far targets as well as targets with unknown addresses. This should
make it faster for small programs (most cases) and generate fewer
conservative trampolines.
Rob Findley [Wed, 28 Apr 2021 20:32:38 +0000 (16:32 -0400)]
go/types: improve error messages for unexpected ListExprs
This CL is a mix of CL 312149 and CL 314409, adding the
Checker.singleIndex method to provide better error messages when an
unexpected ListExpr is encountered.
Change-Id: I45d6de9b4dfc299dc2d356ca14d05c9191de818d
Reviewed-on: https://go-review.googlesource.com/c/go/+/314869
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
Rob Findley [Wed, 28 Apr 2021 19:49:17 +0000 (15:49 -0400)]
go/types: ensure that error code values do not change in 1.17
Over this cycle some error code values have changed due to codes being
added/removed. This is probably OK to do once more before we export
error codes in a later Go version, but for now let's keep them stable.
Move things around to correct the changes, and update comments in
errorcodes.go to make it clearer that new codes should be added at the
end.
Change-Id: Id32827ef1a72cfd876ccc039da11d0a1be7470e9
Reviewed-on: https://go-review.googlesource.com/c/go/+/314830
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
Rob Findley [Wed, 28 Apr 2021 18:40:53 +0000 (14:40 -0400)]
go/types: nest all test data under the testdata directory
Having multiple subdirectories of go/types containing test data is
slightly problematic:
- If ever we were to include a .go file in one of these directories,
we'd inadvertently create a visible package.
- It's difficult to add other content in testdata/, since TestTestdata
scans the entire directory.
Move everything down a level, into testdata/{fixedbugs,examples,check},
and update tests accordingly.
Change-Id: Idd074c94b7b261d678934330539e41a48c2a9dc9
Reviewed-on: https://go-review.googlesource.com/c/go/+/314829
Trust: Robert Findley <rfindley@google.com>
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
Robert Griesemer [Thu, 29 Apr 2021 01:00:16 +0000 (18:00 -0700)]
cmd/compile/internal/types2: match compiler error for invalid type alias decl
Fixes #45594.
Change-Id: I2fcc784e6908403dd96b009546e1ac2f53b9f0e8
Reviewed-on: https://go-review.googlesource.com/c/go/+/314776
Trust: Robert Griesemer <gri@golang.org>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Dan Scales <danscales@google.com>
Ian Lance Taylor [Wed, 28 Apr 2021 18:10:07 +0000 (11:10 -0700)]
runtime: remove walltime function
There was only one meaningful caller, which changes to call time_now.
This clearly separates systems that use walltime1 to be just those
that use the stub version of time_now. That is to say, those that do
not provide an assembler version of time_now.
Change-Id: I14c06cc402070bd705f953af6f9966785015e2a5
Reviewed-on: https://go-review.googlesource.com/c/go/+/314769
Trust: Ian Lance Taylor <iant@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
Change-Id: I96aa2e0206a6e9286bcbfc8be372e84608ed4e2f
Reviewed-on: https://go-review.googlesource.com/c/go/+/314277
Trust: Ian Lance Taylor <iant@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
Rob Findley [Wed, 28 Apr 2021 15:13:35 +0000 (11:13 -0400)]
go/types: respect IgnoreFuncBodies for function literals
This is a 1:1 port of CL 313650 to go/types.
Change-Id: Iec01ac2831f21162d9977a139549e081ee769f90
Reviewed-on: https://go-review.googlesource.com/c/go/+/314631
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
Rob Findley [Wed, 28 Apr 2021 14:35:53 +0000 (10:35 -0400)]
go/types: better errors for invalid short var decls
This is a port of CL 312170 to go/types, adjusted to use go/ast and to
add error codes. go/parser already emits errors for non-identifiers on
the LHS of a short var decl, so a TODO is added to reconsider this
redundancy.
A new error code is added for repeated identifiers in short var decls.
This is a bit specific, but I considered it to be a unique kind of
error.
The x/tools tests for this port turned up a bug: the new logic failed to
call recordDef for blank identifiers. Patchset #2 contains the fix for
this bug, both in go/types and cmd/compile/internal/types2.
Change-Id: Ibdc40b8b4ad0e0696111d431682e1f1056fd5eeb
Reviewed-on: https://go-review.googlesource.com/c/go/+/314629
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
Rob Findley [Wed, 28 Apr 2021 14:07:18 +0000 (10:07 -0400)]
go/types: fix type inference
This is a 1:1 port of CL 311651 to go/types.
Change-Id: I9d91b45cc5fa7ce686d6a91d4dde274d9f80e0d7
Reviewed-on: https://go-review.googlesource.com/c/go/+/314595
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
Ian Lance Taylor [Tue, 27 Apr 2021 23:22:25 +0000 (16:22 -0700)]
runtime: use a single definition of time_now for faketime
Build other definitions with the !faketime build tag.
This makes it easy for us to add new assembly implementations of time.now.
Change-Id: I4e48e41a4a04ab001030e6d1cdd9cebfa0161b0d
Reviewed-on: https://go-review.googlesource.com/c/go/+/314274
Trust: Ian Lance Taylor <iant@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
Ian Lance Taylor [Tue, 27 Apr 2021 23:04:56 +0000 (16:04 -0700)]
runtime: move Windows time.now implementations into separate files
This is a step toward separating whether time.now is implemented in
assembly from whether we are using faketime.
Change-Id: I8bf059b44a103b034835e3d3b799319cc05e9552
Reviewed-on: https://go-review.googlesource.com/c/go/+/314273
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
Rob Findley [Wed, 28 Apr 2021 14:02:16 +0000 (10:02 -0400)]
go/types: use a global atomic counter for type parameter ids
This is a 1:1 port of CL 309830 to go/types.
Change-Id: Ibf709f8194dd5e93a87145e5f9db674ce93af529
Reviewed-on: https://go-review.googlesource.com/c/go/+/314594
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
Rob Findley [Wed, 28 Apr 2021 13:54:56 +0000 (09:54 -0400)]
go/types: add example test for type inference
This is a port of CL 308973. The only change is to remove a TODO at
inference.go2:100 to improve the error position. The go/types error
position is fine.
Change-Id: Ibf61f3458adde91dec9c7531cbd892ca654a5497
Reviewed-on: https://go-review.googlesource.com/c/go/+/314593
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
Rob Findley [Wed, 28 Apr 2021 02:52:56 +0000 (22:52 -0400)]
go/types: use combined type and ordinary args for type inference
This is a port of CL 308372 to go/types. The only meaningful change was
to add TODOs to improve the positioning error messages.
Change-Id: I8314615d0851a59c2b5fd30eb897d581652eacc3
Reviewed-on: https://go-review.googlesource.com/c/go/+/314435
Trust: Robert Findley <rfindley@google.com>
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
Robert Griesemer [Wed, 28 Apr 2021 01:05:20 +0000 (18:05 -0700)]
spec: clarify conditions for switch expression type
1. The existing prose implied that a switch expression type must
be comparable because it is tested for equality against all case
expressions. But for an empty switch (no case expressions), it
was not clear if the switch expression needed to be comparable.
Require it to match the behavior of compiler and type checkers.
2. While making this change, remove redundant language explaining
what happens with untyped boolean switch expression values: the
default type of an untyped boolean value is bool, this is already
covered by the first part of the relevant sentence.
Fixes #43200.
Change-Id: Id8e0f29cfa8722b57cd2b7b58cba85b58c5f842b
Reviewed-on: https://go-review.googlesource.com/c/go/+/314411
Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Rob Pike <r@golang.org>
This is a modified port of the https://golang.org/cl/313909
change for go/types.
- add catch-all cases for unexpected expression lists
- add Checker.singleIndex function to check single indices
- better syntax error handling in parser for invalid type
instantiations that are missing a type argument
Change-Id: I6f0f396d637ad66b79f803d886fdc20ee55a98b3
Reviewed-on: https://go-review.googlesource.com/c/go/+/314409
Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
Jeff Widman [Wed, 28 Apr 2021 17:21:43 +0000 (17:21 +0000)]
cmd/go/internal/modfetch: fix comment that mentions no-longer returned error
In c9211577eb77df9c51f0565f1da7d20ff91d59df @bcmills removed the returned error from
`Lookup`. However, the function docstring still mentions that this can return an error.
So this corrects the docs.
Change-Id: Idca74a200dfdb024e3d7ff6c439c70632cfec11a
GitHub-Last-Rev: 62eaacf70c3886d8aba25b79212c61485a89fde0
GitHub-Pull-Request: golang/go#45822
Reviewed-on: https://go-review.googlesource.com/c/go/+/314572 Reviewed-by: Bryan C. Mills <bcmills@google.com> Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Daniel Martí [Fri, 15 Jan 2021 23:10:48 +0000 (23:10 +0000)]
cmd/gofmt: simplify arg handling
First, we can use flag.Args instead of flag.NArg and flag.Arg.
Second, just call filepath.WalkDir directly on each argument. We don't
need to check if each argument is a directory or not, since the function
will still work on regular files as expected.
To continue giving an error in the "gofmt does-not-exist.go" case, we
now need to return and handle errors from filepath.WalkDir, too.
Arguably, that should have always been the case.
While at it, I noticed that the printinf of the "diff" command did not
obey the "out" parameter. Fix that.
Finally, remove the code to ignore IsNotExist errors. It was added in CL
19301, though it didn't include tests and its reasoning is dubious.
Using gofmt on a directory treewhile another program is concurrently
editing or removing files is inherently racy. Hiding errors can hide
valid problems from the user, and such racy usages aren't supported.
Change-Id: I2e74cc04c53eeefb25231d804752b53562b97371
Reviewed-on: https://go-review.googlesource.com/c/go/+/284138
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
Trust: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Bryan C. Mills <bcmills@google.com> Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
cmd/go/internal/modload: in importFromModules, do not wrap module graph errors in ImportMissingError
If an error occurs in loading the module graph (such as a missing
checksum for a relevant go.mod file), that error should be terminal
and we should not look elsewhere to try to resolve the import. An
ImportMissingError instructs the caller to do exactly that, so don't
use that error type for this case.
(This behavior is tested incidentally in a later CL in this stack.)
For #36460
Change-Id: I963e39cc7fbc457c12a626c1402c0be29203d23b
Reviewed-on: https://go-review.googlesource.com/c/go/+/314633
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org>
Rob Findley [Tue, 27 Apr 2021 20:54:58 +0000 (16:54 -0400)]
go/types: split out function instantiation from index expr
This is a port of CL 308371 to go/types. The only meaningful change from
that CL is to use explicit return values in Checker.indexExpr, which I
felt was more readable. I made the same change in types2 to keep them in
sync
Change-Id: I3380c03fe49d3bf4167cadad305abe942785af19
Reviewed-on: https://go-review.googlesource.com/c/go/+/314432
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
cmd/compile: use desired register only if it satisfies register mask
In the register allocator, if possible, we allocate a value to its
desired register (the ideal register for its next use). In some
cases the desired register does not satisfies the value's output
register mask. We should not use the register in this case.
In the following example, v33 is going to be returned as a
function result, so it is allocated to its desired register AX.
However, its Op cannot use AX as output, causing miscompilation.
testing: add -shuffle=off|on|N to alter the execution order of tests and benchmarks
This CL adds a new flag to the testing package and the go test command
which randomizes the execution order for tests and benchmarks.
This can be useful for identifying unwanted dependencies
between test or benchmark functions.
The flag is off by default. If `-shuffle` is set to `on` then the system
clock will be used as the seed value. If `-shuffle` is set to an integer
N, then N will be used as the seed value. In both cases, the seed will
be reported for failed runs so that they can reproduced later on.
Fixes #28592
Change-Id: I62e7dfae5f63f97a0cbd7830ea844d9f7beac335
Reviewed-on: https://go-review.googlesource.com/c/go/+/310033
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Trust: Bryan C. Mills <bcmills@google.com>
Ian Lance Taylor [Tue, 27 Apr 2021 17:58:54 +0000 (10:58 -0700)]
runtime: consolidate Windows time constants into single copy
Change-Id: I1a583d3da9cca4ac51f3fec9b508b7638b452d60
Reviewed-on: https://go-review.googlesource.com/c/go/+/314270
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
Ian Lance Taylor [Wed, 28 Apr 2021 00:32:02 +0000 (17:32 -0700)]
cmd/go: include C/C++/Fortran compiler version in build ID
This will force a rebuild if the C/C++/Fortran compiler changes.
No test because a real test requires installing two different compilers.
Fixes #40042
Change-Id: I83cc88ade90d665a6fce06435068f39c811e43af
Reviewed-on: https://go-review.googlesource.com/c/go/+/314276
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
Ian Lance Taylor [Wed, 28 Apr 2021 04:56:46 +0000 (21:56 -0700)]
cmd/link: don't pass -Wl,--dynamic-linker if -static
As with -rdynamic, clang will pass -Wl,--dynamic-linker to the linker
even when linking statically. When using lld this will produce a statically
linked executable with a dynamic interpreter, which will crash at runtime.
This CL changes the linker to drop -Wl,--dynamic-linker when using -static,
as it already does with -rdynamic.
This has become more important since CL 310349, which changes the linker
to always pass a -Wl,--dynamic-linker option if the Go linker is invoked
with a -I option.
Change-Id: I68ed431064f02c70018bc0547585e5b0ebd20a41
Reviewed-on: https://go-review.googlesource.com/c/go/+/314412
Trust: Ian Lance Taylor <iant@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
cmd/link: use R12 as trampoline scratch register on ARM
The external linker uses R12. Do the same. We previously use R11,
the temp register in Go ABI. This does not really matter if the
caller is Go code, because all registers are clobbered at call.
But it the caller is C code, it may assume R11 live across a call.
Using R11 may clobber live value. On the callee side, R12 is not
an argument register in both Go and C calling convention.
Change-Id: I958c5dad52aa51bb282a7ad420f5423863e69c14
Reviewed-on: https://go-review.googlesource.com/c/go/+/314454
Trust: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
In external linking mode the external linker may insert
trampolines, which use R12 as a scratch register. So a call could
potentially clobber R12 if the target is laid out too far. Mark
R12 clobbered.
Also, we will use R12 for trampolines in the Go linker as well.
CL 310731 updated the generated rewrite files so imports are
grouped, but the generator was not updated to do so. Grouped
imports are nice. But as those are generated files, for
simplicity and my laziness, just regenerate with the current
generator (which makes imports not grouped).
Change-Id: Iddb741ff7314a291ade5fbffc7d315f555808409
Reviewed-on: https://go-review.googlesource.com/c/go/+/314453
Trust: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
Note how the " [test/main.test]" suffixes are missing. Because of that,
when one sees TOOLEXEC_IMPORTPATH="test/main", it is ambiguous whether
the regular "test/main" package is meant, or its test variant, otherwise
known as "test/main [test/main.test]" and including foo_test.go
To fix this, we need unambiguous strings to identify the packages
involved, just like one can do with "go list -test". "go list" already
has such a field, ImportPath, which is also used when printing output
from each build "action" as seen above.
That string is not really an import path - internally, it's
load.Package.Desc, and called a "description". However, it makes sense
to be consistent with "go list -json", because it's the source of truth
for practically all tools interacting with the Go toolchain.
To keep cmd/go more consistent, "go list -f {{.ImportPath}}" now calls
Package.Desc as well, instead of having its own copy of the string
concatenation for ForTest.
Fixes #44963.
Change-Id: Ibce7fbb5549209dac50526043c0c7daa0beebc08
Reviewed-on: https://go-review.googlesource.com/c/go/+/313770 Reviewed-by: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Daniel Martí <mvdan@mvdan.cc>
Joel Sing [Mon, 7 Dec 2020 17:30:22 +0000 (04:30 +1100)]
cmd/dist,runtime: support cgo on openbsd/mips64
Add support for cgo on openbsd/mips64.
Fixes #43005
Change-Id: I2386204f53fa984a01a9d89f0b6c96455768f326
Reviewed-on: https://go-review.googlesource.com/c/go/+/275896
Trust: Joel Sing <joel@sing.id.au>
Run-TryBot: Joel Sing <joel@sing.id.au> Reviewed-by: Cherry Zhang <cherryyz@google.com>
eric fang [Thu, 9 Jul 2020 11:27:03 +0000 (11:27 +0000)]
cmd/compile/ssa: optimize the derivable known branch of If block
When the control value of a If block is known for a particular inbound edge
because its value can be inferred from the control value of its predecessor,
then this inbound edge can be redirected to the known successor directly,
This CL optimizes this kind of cases to eliminate unnecessary comparision.
For example, the following piece of code comes from runtime.atoi,
if !neg && un > uint(maxInt) {
return 0, false
}
if neg && un > uint(maxInt)+1 {
return 0, false
}
Before this optimization, if the first "if" statement does not return, both
conditions of the second "if" statement will be checked. But obviously the
value of neg is known through the first "if" statement, and there is no need
to check neg repeatedly.
After this optimization, this redundancy check is eliminated, and the execution
logic becomes as follows.
if !neg {
if un > uint(maxInt) {
return 0, false
}
} else {
if un > uint(maxInt)+1 {
return 0, false
}
}
This CL does not bring significant performance changes, but it makes the code
structure look more reasonable.
Change-Id: I2831238b12e3af5aef2261f64f804bf0a8b43f86
Reviewed-on: https://go-review.googlesource.com/c/go/+/244737 Reviewed-by: eric fang <eric.fang@arm.com> Reviewed-by: Keith Randall <khr@golang.org>
Trust: eric fang <eric.fang@arm.com>
Run-TryBot: eric fang <eric.fang@arm.com>
TryBot-Result: Go Bot <gobot@golang.org>
eric fang [Wed, 21 Apr 2021 03:12:20 +0000 (03:12 +0000)]
cmd/asm: add check for register and shift/extension combination on arm64
The current code lacks a check on whether the register and shift/extension
combination is valid, for example the follow instructions also compiles.
ADD F1<<1, R1, R3
ADD V1<<1, R1, R3
MOVW (R9)(F8.SXTW<<2), R19
VST1 R4.D[1], (R0)
Actually only general registers can perform shift operations, and element
and arrangement extensions are only applicable to vector registers. This
CL adds a check for the register and shift/extension combination on arm64.
Change-Id: I93dd9343e92a66899cba8eaf4e0ac5430e94692b
Reviewed-on: https://go-review.googlesource.com/c/go/+/312571
Trust: eric fang <eric.fang@arm.com> Reviewed-by: eric fang <eric.fang@arm.com> Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: eric fang <eric.fang@arm.com>
TryBot-Result: Go Bot <gobot@golang.org>
eric fang [Tue, 27 Apr 2021 06:19:57 +0000 (06:19 +0000)]
cmd/internal/obj/arm64: fix the wrong error message of out-of-range checking
The error message of checking whether the offset value of load/store
instruction is out of range is wrong. The right range is [-256, 255], not
[-255, 254]. The CL fixes it.
Change-Id: Ia342957f1f6bcec65eceb45944221d3972641bed
Reviewed-on: https://go-review.googlesource.com/c/go/+/313891 Reviewed-by: eric fang <eric.fang@arm.com> Reviewed-by: Cherry Zhang <cherryyz@google.com>
Trust: eric fang <eric.fang@arm.com>
Run-TryBot: eric fang <eric.fang@arm.com>
cmd/compile: fix typechecking logical operators panic with non-boolean operand
In CL 255899, we added code to make clearer error when non-bool used
as operand to logical operators. The code is safe, because node type
is guaranteed to be non-nil.
In CL 279442, we refactored typechecking arith, including moving
typechecking logical operators to separate case. Now we have to
explicitly check if operand type is not nil, because calling Expr can
set operand type nil for non-bool operands.
Fixes #45804
Change-Id: Ie2b6e18f65c0614a803b343f60e78ee1d660bbeb
Reviewed-on: https://go-review.googlesource.com/c/go/+/314209
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>