1
0
mirror of https://github.com/golang/go synced 2024-11-06 13:46:16 -07:00
Commit Graph

32732 Commits

Author SHA1 Message Date
Michael Munday
42a82ce1a7 math/bits: optimize Reverse32 and Reverse64
Use ReverseBytes32 and ReverseBytes64 to speed up these functions.
The byte reversal functions are intrinsics on most platforms and
generally compile to a single instruction.

name       old time/op  new time/op  delta
Reverse32  2.41ns ± 1%  1.94ns ± 3%  -19.60%  (p=0.000 n=20+19)
Reverse64  3.85ns ± 1%  2.56ns ± 1%  -33.32%  (p=0.000 n=17+19)

Change-Id: I160bf59a0c7bd5db94114803ec5a59fae448f096
Reviewed-on: https://go-review.googlesource.com/c/159358
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2019-02-26 17:52:08 +00:00
Iskander Sharipov
b65ab889ab net/rpc: fix args order in strings.Contains call
The old code looks suspicious and is fragile.
It would fail if error messages were not totally the same.
Swapped the arguments order to fix that.

Change-Id: Id5df7242fb9224d0090245286ef8986ebb15e921
Reviewed-on: https://go-review.googlesource.com/c/161157
Run-TryBot: Iskander Sharipov <quasilyte@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
2019-02-26 17:51:35 +00:00
Daniel Martí
856525ce5c text/template: improve nil errors in evalField
If we're accessing a field on a nil struct pointer, and that field is
present in the type, we should print a "nil pointer evaluating X.Y" error
instead of the broader "can't evaluate field Y in X". The latter error
should still be used for the cases where the field is simply missing.

While at it, remove the isNil checks in the struct and map cases. The
indirect func will only return a true isNil when returning a pointer or
interface reflect.Value, so it's impossible for either of these checks
to be useful.

Finally, extend the test suite to test a handful of these edge cases,
including the one shown in the original issue.

Fixes #29137.

Change-Id: I53408ced8a7b53807a0a8461b6baef1cd01d25ae
Reviewed-on: https://go-review.googlesource.com/c/153341
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2019-02-26 17:50:11 +00:00
Daniel Martí
be9c534cde cmd/compile: don't crash on -d=ssa/
I forgot how to pull up the ssa debug options help, so instead of
writing -d=ssa/help, I just wrote -d=ssa/. Much to my amusement, the
compiler just crashed, as shown below. Fix that.

	panic: runtime error: index out of range

	goroutine 1 [running]:
	cmd/compile/internal/ssa.PhaseOption(0x7ffc375d2b70, 0x0, 0xdbff91, 0x5, 0x1, 0x0, 0x0, 0x1, 0x1)
	    /home/mvdan/tip/src/cmd/compile/internal/ssa/compile.go:327 +0x1876
	cmd/compile/internal/gc.Main(0xde7bd8)
	    /home/mvdan/tip/src/cmd/compile/internal/gc/main.go:411 +0x41d0
	main.main()
	    /home/mvdan/tip/src/cmd/compile/main.go:51 +0xab

Change-Id: Ia2ad394382ddf8f4498b16b5cfb49be0317fc1aa
Reviewed-on: https://go-review.googlesource.com/c/154421
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2019-02-26 17:50:01 +00:00
Alberto Donizetti
c0101b1961 time: parse 1us in Nanoseconds example
The example for Nanoseconds() currently reads:

  ns, _ := time.ParseDuration("1000ns")
  fmt.Printf("one microsecond has %d nanoseconds.", ns.Nanoseconds())

which is not terribly interesting: it seems obvious that parsing
"1000ns" and then calling Nanoseconds() will print 1000. The mention
of microseconds in the text suggests that the author's intention was,
instead, to write something like this:

  u, _ := time.ParseDuration("1us")

i.e. build a time value by parsing 1 microsecond, and then print the
value in nanoseconds. Change the example to do this.

Change-Id: I4ddb123f0935a12cda3b5d6f1ca919bfcd6383d6
Reviewed-on: https://go-review.googlesource.com/c/163622
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-02-26 17:22:58 +00:00
Russ Cox
3cf56e78d8 text/template: accept new number syntax
This CL updates text/template's scanner to accept the
new number syntaxes:

 - Hexadecimal floating-point values.
 - Digit-separating underscores.
 - Leading 0b and 0o prefixes.

See golang.org/design/19308-number-literals for background.

For #12711.
For #19308.
For #28493.
For #29008.

Change-Id: I68c16ea35c3f506701063781388de72bafee6b8d
Reviewed-on: https://go-review.googlesource.com/c/160248
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2019-02-26 05:18:38 +00:00
Russ Cox
f601d412ce fmt: scan new number syntax
This CL updates fmt's scanner to accept the new number syntaxes:

 - Hexadecimal floating-point values.
 - Digit-separating underscores.
 - Leading 0b and 0o prefixes.

See golang.org/design/19308-number-literals for background.

For #12711.
For #19308.
For #28493.
For #29008.

Change-Id: I5582af5c94059c781e6cf4e862441d3df3006adf
Reviewed-on: https://go-review.googlesource.com/c/160247
Reviewed-by: Robert Griesemer <gri@golang.org>
2019-02-26 05:18:24 +00:00
Russ Cox
ac51237aff fmt: format 0b, 0o prefixes in %#b and %O
This CL modifies fmt's printer to implement %#b and %O
to emit leading 0b and 0o prefixes on binary and octal.
(%#o is already taken and emits "0377"; %O emits "0o377".)

See golang.org/design/19308-number-literals for background.

For #19308.
For #12711.
Vet update is #29986.

Change-Id: I7c38a4484c48a03abe9f6d45c7d981c7c314f583
Reviewed-on: https://go-review.googlesource.com/c/160246
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2019-02-26 05:16:56 +00:00
Russ Cox
e1a6d1fc08 fmt: format hex floats and complexes
This CL modifies fmt's printer to implement %x and %X
for formatting floating-point data (floats and complexes)
in standard hexadecimal notation.

See golang.org/design/19308-number-literals for background.

For #29008.
Vet update is #29986.

Change-Id: If2842a11631bc393a1ebcf6914ed07658652af5a
Reviewed-on: https://go-review.googlesource.com/c/160245
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2019-02-26 05:16:49 +00:00
Bryan C. Mills
50bb2b6b0f cmd/go: allow "stdout" and "stderr" as inputs to script_test "cp" command
Updates #30241

Change-Id: I543d8914faf810835d3327baa3c84b3dff124156
Reviewed-on: https://go-review.googlesource.com/c/163519
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-02-26 02:45:57 +00:00
Bryan C. Mills
dd4e7f9722 misc/cgo/testso{,var}: fix tests in module mode
Add _test.go files in the individal directories to invoke 'go build'
with appropriate arguments.

Move the test driver out of cmd/dist so that it's easier to invoke the
test separately (using 'go test .').

Updates #30228
Updates #28387

Change-Id: Ibc4a024a52c12a274058298b41cc90709f7f56c8
Reviewed-on: https://go-review.googlesource.com/c/163420
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-02-26 02:43:55 +00:00
Lynn Boger
2d3474043c cmd/compile: call ginsnop, not ginsnop2 on ppc64le for mid-stack inlining tracebacks
A recent change to fix stacktraces for inlined functions
introduced a regression on ppc64le when compiling position
independent code. That happened because ginsnop2 was called for
the purpose of inserting a NOP to identify the location of
the inlined function, when ginsnop should have been used.
ginsnop2 is intended to be used before deferreturn to ensure
r2 is properly restored when compiling position independent code.
In some cases the location where r2 is loaded from might not be
initialized. If that happens and r2 is used to generate an address,
the result is likely a SEGV.

This fixes that problem.

Fixes #30283

Change-Id: If70ef27fc65ef31969712422306ac3a57adbd5b6
Reviewed-on: https://go-review.googlesource.com/c/163337
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Carlos Eduardo Seo <cseo@linux.vnet.ibm.com>
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Andrew Bonventre <andybons@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-02-25 18:08:46 +00:00
Elias Naur
f5aecc1d1d Revert "androidtest.bash: wait for device to be ready before using it"
This reverts commit 27b9571de8.

Reason for revert: broke the multi-device Android builder. And the wait logic is moving to the exec wrapper anyway.

Change-Id: I3e429106bbe70b3a12286f8f229a2b558279eec4
Reviewed-on: https://go-review.googlesource.com/c/163620
Run-TryBot: Elias Naur <mail@eliasnaur.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-02-24 21:54:04 +00:00
Bryan C. Mills
01f34cbf52 misc/cgo/life: fix tests in module mode
Updates #30228

Change-Id: Ie972694254d2195ca9760ea7ffb6073e01c52488
Reviewed-on: https://go-review.googlesource.com/c/163422
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
2019-02-24 00:41:11 +00:00
Bryan C. Mills
c6611b2f7e misc/cgo/stdio: fix tests in module mode
Updates #30228

Change-Id: I4d213c6fe68c47ccb877f13b55128e035f76a26b
Reviewed-on: https://go-review.googlesource.com/c/163421
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-02-24 00:40:20 +00:00
Bryan C. Mills
eb2d1cdd1b misc/cgo/testplugin: convert test.bash to Go and fix in module mode
Updates #30228
Updates #28387

Change-Id: Iad7d960b70221f90ccc2372bb1d4d41cec3926e4
Reviewed-on: https://go-review.googlesource.com/c/163214
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-02-24 00:36:13 +00:00
Bryan C. Mills
3726d91d68 cmd/go/internal/imports: use the full path to resolve symlinks
info.Name returns a name relative to the directory, so we need to
prefix that directory in the Stat call.

(This was missed in CL 141097 due to the fact that the test only
happened to check symlinks in the current directory.)

This allows the misc/ tests to work in module mode on platforms that
support symlinks.

Updates #30228
Updates #28107

Change-Id: Ie31836382df0cbd7d203b7a8b637c4743d68b6f3
Reviewed-on: https://go-review.googlesource.com/c/163517
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
2019-02-23 22:02:23 +00:00
Bryan C. Mills
a00611f58d misc/cgo/testcshared: fix tests in module mode
Updates #30228

Change-Id: Ie9dca7c64be8dff729be98cb6190236287afd23e
Reviewed-on: https://go-review.googlesource.com/c/163213
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Jay Conrod <jayconrod@google.com>
2019-02-22 21:57:35 +00:00
Bryan C. Mills
13d9a29060 misc/cgo/testcarchive: fix tests in module mode
Updates #30228

Change-Id: I830e3c83416b2e5744f30d1a903a74c50462716b
Reviewed-on: https://go-review.googlesource.com/c/163210
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
2019-02-22 21:56:56 +00:00
Elias Naur
27b9571de8 androidtest.bash: wait for device to be ready before using it
Updates #23824

Change-Id: I265e3f40192a0a4bf54f608d9408ba0cfef2b69c
Reviewed-on: https://go-review.googlesource.com/c/163457
Run-TryBot: Elias Naur <mail@eliasnaur.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-02-22 19:30:43 +00:00
Filippo Valsorda
b35dacaac5 crypto/rc4: remove false guarantees from Reset docs and deprecate it
Nothing in Go can truly guarantee a key will be gone from memory (see
#21865), so remove that claim. That makes Reset useless, because
unlike most Reset methods it doesn't restore the original value state,
so deprecate it.

Change-Id: I6bb0f7f94c7e6dd4c5ac19761bc8e5df1f9ec618
Reviewed-on: https://go-review.googlesource.com/c/162297
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-02-22 17:05:17 +00:00
fanzha02
2ef8abb41f cmd/internal/obj/arm64: fix the bug assembling TSTW
Current assembler reports error when it assembles
"TSTW $1689262177517664, R3", but go1.11 was building
fine.

Fixes #30334

Change-Id: I9c16d36717cd05df2134e8eb5b17edc385aff0a9
Reviewed-on: https://go-review.googlesource.com/c/163259
Run-TryBot: Ben Shi <powerman1st@163.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ben Shi <powerman1st@163.com>
2019-02-22 09:29:27 +00:00
Cherry Zhang
0349f29a55 cmd/compile: flow interface data to heap if CONVIFACE of a non-direct interface escapes
Consider the following code:

func f(x []*T) interface{} {
	return x
}

It returns an interface that holds a heap copy of x (by calling
convT2I or friend), therefore x escape to heap. The current
escape analysis only recognizes that x flows to the result. This
is not sufficient, since if the result does not escape, x's
content may be stack allocated and this will result a
heap-to-stack pointer, which is bad.

Fix this by realizing that if a CONVIFACE escapes and we're
converting from a non-direct interface type, the data needs to
escape to heap.

Running "toolstash -cmp" on std & cmd, the generated machine code
are identical for all packages. However, the export data (escape
tags) differ in the following packages. It looks to me that all
are similar to the "f" above, where the parameter should escape
to heap.

io/ioutil/ioutil.go:118
	old: leaking param: r to result ~r1 level=0
	new: leaking param: r

image/image.go:943
	old: leaking param: p to result ~r0 level=1
	new: leaking param content: p

net/url/url.go:200
	old: leaking param: s to result ~r2 level=0
	new: leaking param: s

(as a consequence)
net/url/url.go:183
	old: leaking param: s to result ~r1 level=0
	new: leaking param: s

net/url/url.go:194
	old: leaking param: s to result ~r1 level=0
	new: leaking param: s

net/url/url.go:699
	old: leaking param: u to result ~r0 level=1
	new: leaking param: u

net/url/url.go:775
	old: (*URL).String u does not escape
	new: leaking param content: u

net/url/url.go:1038
	old: leaking param: u to result ~r0 level=1
	new: leaking param: u

net/url/url.go:1099
	old: (*URL).MarshalBinary u does not escape
	new: leaking param content: u

flag/flag.go:235
	old: leaking param: s to result ~r0 level=1
	new: leaking param content: s

go/scanner/errors.go:105
	old: leaking param: p to result ~r0 level=0
	new: leaking param: p

database/sql/sql.go:204
	old: leaking param: ns to result ~r0 level=0
	new: leaking param: ns

go/constant/value.go:303
	old: leaking param: re to result ~r2 level=0, leaking param: im to result ~r2 level=0
	new: leaking param: re, leaking param: im

go/constant/value.go:846
	old: leaking param: x to result ~r1 level=0
	new: leaking param: x

encoding/xml/xml.go:518
	old: leaking param: d to result ~r1 level=2
	new: leaking param content: d

encoding/xml/xml.go:122
	old: leaking param: leaking param: t to result ~r1 level=0
	new: leaking param: t

crypto/x509/verify.go:506
	old: leaking param: c to result ~r8 level=0
	new: leaking param: c

crypto/x509/verify.go:563
	old: leaking param: c to result ~r3 level=0, leaking param content: c
	new: leaking param: c

crypto/x509/verify.go:615
	old: (nothing)
	new: leaking closure reference c

crypto/x509/verify.go:996
	old: leaking param: c to result ~r1 level=0, leaking param content: c
	new: leaking param: c

net/http/filetransport.go:30
	old: leaking param: fs to result ~r1 level=0
	new: leaking param: fs

net/http/h2_bundle.go:2684
	old: leaking param: mh to result ~r0 level=2
	new: leaking param content: mh

net/http/h2_bundle.go:7352
	old: http2checkConnHeaders req does not escape
	new: leaking param content: req

net/http/pprof/pprof.go:221
	old: leaking param: name to result ~r1 level=0
	new: leaking param: name

cmd/internal/bio/must.go:21
	old: leaking param: w to result ~r1 level=0
	new: leaking param: w

Fixes #29353.

Change-Id: I7e7798ae773728028b0dcae5bccb3ada51189c68
Reviewed-on: https://go-review.googlesource.com/c/162829
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: David Chase <drchase@google.com>
2019-02-21 15:14:45 +00:00
Herbie Ong
889aa5eb98 go/build: add go1.13 release tag
Adding this early in the cycle to start regression testing in the master
toolchain.

Change-Id: Ia151429c4f94efbac0aa41ab6bc16e7462b0e303
Reviewed-on: https://go-review.googlesource.com/c/163082
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-02-20 21:44:53 +00:00
Robert Griesemer
34fb5855eb text/scanner: don't liberally consume (invalid) floats or underbars
This is a follow-up on https://golang.org/cl/161199 which introduced
the new Go 2 number literals to text/scanner.

That change introduced a bug by allowing decimal and hexadecimal floats
to be consumed even if the scanner was not configured to accept floats.

This CL changes the code to not consume a radix dot '.' or exponent
unless the scanner is configured to accept floats.

This CL also introduces a new mode "AllowNumberbars" which controls
whether underbars '_' are permitted as digit separators in numbers
or not.

There is a possibility that we may need to refine text/scanner
further (e.g., the Float mode now includes hexadecimal floats
which it didn't recognize before). We're very early in the cycle,
so let's see how it goes.

RELNOTE=yes

Updates #12711.
Updates #19308.
Updates #28493.
Updates #29008.

Fixes #30320.

Change-Id: I6481d314f0384e09ef6803ffad38dc529b1e89a3
Reviewed-on: https://go-review.googlesource.com/c/163079
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-02-20 20:23:28 +00:00
Ian Lance Taylor
153c0da89b path/filepath: revert "fix Windows-specific Clean bug"
Revert CL 137055, which changed Clean("\\somepath\dir\") to return
"\\somepath\dir" on Windows. It's not entirely clear this is correct,
as this path is really "\\server\share\", and as such the trailing
slash may be the path on that share, much like "C:\". In any case, the
change broke existing code, so roll it back for now and rethink for 1.13.

Updates #27791
Fixes #30307

Change-Id: I69200b1efe38bdb6d452b744582a2bfbb3acbcec
Reviewed-on: https://go-review.googlesource.com/c/163077
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2019-02-20 18:32:07 +00:00
Bryan C. Mills
dace6544b3 cmd/vet: make vet_test module-agnostic
vet_test currently uses a custom GOPATH for each test, but it turns
out not to be necessary.

Updates #30228

Change-Id: Id7a7bf6d759bd94adccf44e197be1728c2f23575
Reviewed-on: https://go-review.googlesource.com/c/163038
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
2019-02-20 15:46:42 +00:00
Bryan C. Mills
1e4a88fa0a cmd/link/internal/ld: make dwarf_test and associated testdata module-agnostic
Updates #30228

Change-Id: I31aac4cb113c0c88a54329181ad27aee3d8acc71
Reviewed-on: https://go-review.googlesource.com/c/162835
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
2019-02-20 15:46:11 +00:00
Bryan C. Mills
b88462ef8b cmd/cover: fix TestHtmlUnformatted in module mode
Updates #30228

Change-Id: Id9dffa6c805ac630945bac8febe342ce633626c6
Reviewed-on: https://go-review.googlesource.com/c/162830
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
2019-02-20 15:45:22 +00:00
Bryan C. Mills
583975b934 cmd/link: fix TestUnresolved in module mode
Updates #30228

Change-Id: I9f0e7e59922bd56b17889f72124b7d14b2433218
Reviewed-on: https://go-review.googlesource.com/c/162833
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
2019-02-19 23:10:00 +00:00
Bryan C. Mills
34291f5f3e cmd/internal/goobj: make the buildGoobj test helper work in module mode
Updates #30228

Change-Id: I8dd4a1f94dfd3be324a4f213941a20fa1b8b1215
Reviewed-on: https://go-review.googlesource.com/c/162832
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
2019-02-19 22:53:59 +00:00
Robert Griesemer
4ad5537bfa cmd/compile: accept 'i' suffix orthogonally on all numbers
This change accepts the 'i' suffix on binary and octal integer
literals as well as hexadecimal floats. The suffix was already
accepted on decimal integers and floats.

Note that 0123i == 123i for backward-compatibility (and 09i is
valid).

See also the respective language in the spec change:
https://golang.org/cl/161098

Change-Id: I9d2d755cba36a3fa7b9e24308c73754d4568daaf
Reviewed-on: https://go-review.googlesource.com/c/162878
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-02-19 22:45:09 +00:00
Robert Griesemer
c3b49186a6 go/scanner: accept 'i' suffix orthogonally on all numbers
This change accepts the 'i' suffix on binary and octal integer
literals as well as hexadecimal floats. The suffix was already
accepted on decimal integers and floats.

See also the respective language in the spec change:
https://golang.org/cl/161098

Change-Id: I0c182bdf58f8fd1f70090e581b3ccb2f5e2e4e79
Reviewed-on: https://go-review.googlesource.com/c/162880
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-02-19 22:44:43 +00:00
Robert Griesemer
041d31b882 cmd/compile: don't mix internal float/complex constants of different precision
There are several places where a new (internal) complex constant is allocated
via new(Mpcplx) rather than newMpcmplx(). The problem with using new() is that
the Mpcplx data structure's Real and Imag components don't get initialized with
an Mpflt of the correct precision (they have precision 0, which may be adjusted
later).

In all cases but one, the components of those complex constants are set using
a Set operation which "inherits" the correct precision from the value that is
being set.

But when creating a complex value for an imaginary literal, the imaginary
component is set via SetString which assumes 64bits of precision by default.
As a result, the internal representation of 0.01i and complex(0, 0.01) was
not correct.

Replaced all used of new(Mpcplx) with newMpcmplx() and added a new test.

Fixes #30243.

Change-Id: Ife7fd6ccd42bf887a55c6ce91727754657e6cb2d
Reviewed-on: https://go-review.googlesource.com/c/163000
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2019-02-19 21:05:17 +00:00
Bryan C. Mills
165a8d93cd cmd/vet: do not write test vet binary to GOROOT
Updates #28387

Change-Id: Ie5a5f1f798eb5900f9c7bdef165abcca02dd0dde
Reviewed-on: https://go-review.googlesource.com/c/163037
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-02-19 20:54:12 +00:00
Bryan C. Mills
8827147932 cmd/nm: fix testGoLib helper to be module-agnostic
Updates #30228

Change-Id: I3c7864e6725312df5ec978cdc130ccfe8fc2e738
Reviewed-on: https://go-review.googlesource.com/c/162836
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-02-19 20:53:59 +00:00
Bryan C. Mills
d7d3887e3e cmd/internal/obj/x86: fix issue19518_test in module mode
Updates #30228

Change-Id: I6a38269f322d906702921b3879ff48c8a96ab511
Reviewed-on: https://go-review.googlesource.com/c/162831
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-02-19 20:53:10 +00:00
Robert Griesemer
fae44a2be3 src, misc: apply gofmt
This applies the new gofmt literal normalizations to the library.

Change-Id: I8c1e8ef62eb556fc568872c9f77a31ef236348e7
Reviewed-on: https://go-review.googlesource.com/c/162539
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-02-19 20:38:28 +00:00
Robert Griesemer
f8abdd6c8a cmd/gofmt: normalize integer imaginary literals starting with 0
An 'i' suffix on an integer literal marks the integer literal as
a decimal integer imaginary value, even if the literal without the
suffix starts with a 0 and thus looks like an octal value:

	0123i == 123i // != 0123 * 1i

This is at best confusing, and at worst a potential source of bugs.
It is always safe to rewrite such literals into the equivalent
literal without the leading 0.

This CL implements this normalization.

Change-Id: Ib77ad535f98b5be912ecbdec20ca1b472c1b4973
Reviewed-on: https://go-review.googlesource.com/c/162538
Run-TryBot: Robert Griesemer <gri@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-02-19 20:38:06 +00:00
Bryan C. Mills
613f0a3144 cmd/go: set GO111MODULE=off explicitly in tests that assume GOPATH mode
We will soon switch GO111MODULE to 'on' by default, and when that
happens these tests will otherwise break.

Updates #30228

Change-Id: I1016d429b1dfb889d1aae8bc86fb2567cf0fc56f
Reviewed-on: https://go-review.googlesource.com/c/162697
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
2019-02-19 19:57:03 +00:00
Bryan C. Mills
cf155b00d1 runtime: make tests that invoke 'go build' module-agnostic
In module mode, building the current directory requires a go.mod file
(in order to determine the import path of the package).

Change the tests to pass explicit file arguments instead, since those
can be built in module mode without defining a module.

Updates #30228

Change-Id: I680c658d1f79645f73ad4d1e88189ea50a4852e9
Reviewed-on: https://go-review.googlesource.com/c/162837
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2019-02-19 19:56:43 +00:00
Robert Griesemer
5aac0f0d1e go/types: include test/fixedbugs/bug073.go again in test
This test was excluded from the go/types std lib test
because it tested old behavior (shift count must be
an unsigned int). With the compiler changes made and
the test adjusted accordingly, we can include it again.

Updates #19113.

Change-Id: If9b6b83505d2bd2b426fcefa225986d73658a229
Reviewed-on: https://go-review.googlesource.com/c/159319
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2019-02-17 04:39:22 +00:00
Cherry Zhang
dca707b2a0 cmd/compile: guard against loads with negative offset from readonly constants
CL 154057 adds guards agaist out-of-bound reads from readonly
constants. It turns out that in dead code, the offset can also
be negative. Guard against negative offset as well.

Fixes #30257.

Change-Id: I47c2a2e434dd466c08ae6f50f213999a358c796e
Reviewed-on: https://go-review.googlesource.com/c/162819
Reviewed-by: Keith Randall <khr@golang.org>
2019-02-16 02:02:31 +00:00
Keith Randall
585c9e8412 cmd/compile: implement shifts by signed amounts
Allow shifts by signed amounts. Panic if the shift amount is negative.

TODO: We end up doing two compares per shift, see Ian's comment
https://github.com/golang/go/issues/19113#issuecomment-443241799 that
we could do it with a single comparison in the normal case.

The prove pass mostly handles this code well. For instance, it removes the
<0 check for cases like this:
    if s >= 0 { _ = x << s }
    _ = x << len(a)

This case isn't handled well yet:
    _ = x << (y & 0xf)
I'll do followon CLs for unhandled cases as needed.

Update #19113

R=go1.13

Change-Id: I839a5933d94b54ab04deb9dd5149f32c51c90fa1
Reviewed-on: https://go-review.googlesource.com/c/158719
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2019-02-15 23:13:09 +00:00
Ian Lance Taylor
e1acd854f7 cmd/go: add newline after module-requires-version message
Fixes #30263

Change-Id: Iefb3d8baf815c19eaf915a59048e1da799ca0cdf
Reviewed-on: https://go-review.googlesource.com/c/162957
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2019-02-15 21:33:31 +00:00
Brad Fitzpatrick
5fcc24074f syscall: skip TestSyscallNoError when temp dir is mounted nosuid
Fixes #30258

Change-Id: I73b63eb9d3aca00f562fdc3af010e96269bb6b9c
Reviewed-on: https://go-review.googlesource.com/c/162891
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Katie Hockman <katie@golang.org>
2019-02-15 19:24:37 +00:00
Bryan C. Mills
65c2069a9f cmd/go: only generate a go.mod file during 'go mod init'
In the general case, we do not know the correct module path for a new
module unless we have checked its VCS tags for a major version. If we
do not know the correct path, then we should not synthesize a go.mod
file automatically from it.

On the other hand, we don't want to run VCS commands in the working
directory without an explicit request by the user to do so: 'go mod
init' can reasonably invoke a VCS command, but 'go build' should not.

Therefore, we should only create a go.mod file during 'go mod init'.

This change removes the previous behavior of synthesizing a file
automatically, and instead suggests a command that the user can opt to
run explicitly.

Updates #29433
Updates #27009
Updates #30228

Change-Id: I8c4554969db17156e97428df220b129a4d361040
Reviewed-on: https://go-review.googlesource.com/c/162699
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
2019-02-15 17:32:07 +00:00
Zhou Peng
4c89a10fb9 database/sql/driver: fix typo
Change-Id: I6e7035db4b3e2a09e5655eb7646eea9d99fb7118
Reviewed-on: https://go-review.googlesource.com/c/162917
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-02-15 17:23:55 +00:00
Brad Fitzpatrick
48bb611667 crypto/tls, runtime: document GODEBUG TLS 1.3 option
Change-Id: I6801676335924414ce50249df2b7bea08886b203
Reviewed-on: https://go-review.googlesource.com/c/162360
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2019-02-13 19:34:40 +00:00
Emmanuel T Odeke
b690d7e513 net/http/httputil: make TestDumpRequest idempotent
TestDumpRequest was failing with -count=2 or more
because for test cases that involved mustReadRequest,
the body was created as a *bufio.Reader. DumpRequest
and DumpRequestOut would then read the body until EOF
and would close it after use.
However, on re-runs of the test, the body would
be terminally exhausted and result in an unexpected
error "http: invalid Read on closed Body".

The update to the test cases adds an extra field "GetReq"
which allows us to construct requests per run of the tests
and hence make the test indefinitely re-runnable/idempotent.
"Req" or "GetReq" are mutually exclusive: either one of them
can be set or nil, but not both.

Fixes #26858

Change-Id: Ice3083dac1aa3249da4afc7075cd984eb159530d
Reviewed-on: https://go-review.googlesource.com/c/153377
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-02-13 16:58:53 +00:00