1
0
mirror of https://github.com/golang/go synced 2024-09-25 05:20:13 -06:00
Commit Graph

965 Commits

Author SHA1 Message Date
Michael Hudson-Doyle
a60c5366f9 test: do not run external linking test on ppc64le
Change-Id: I9b8a6ac1ff6bef3b7f1e033bfd029f2a59e30297
Reviewed-on: https://go-review.googlesource.com/12623
Reviewed-by: Russ Cox <rsc@golang.org>
2015-07-27 16:22:12 +00:00
David Chase
731dcdae6d cmd/compile: prepend captured args to called-closure params
Old code appended, did not play well with a closure
with a ... param.

Fixes #11075.

Change-Id: Ib7c8590c5c4e576e798837e7499e00f3494efb4a
Reviewed-on: https://go-review.googlesource.com/12580
Reviewed-by: Russ Cox <rsc@golang.org>
Run-TryBot: David Chase <drchase@google.com>
2015-07-23 19:02:19 +00:00
David Chase
2584974d16 cmd/compile: adjust annotation of implicit operations.
Limit probe to ODOT/OIND/ODOTPTR for now; that works.

Fixes #11790

Change-Id: I411271e702c5fe6ceb880ca47c7dacc37ffcbb6a
Reviewed-on: https://go-review.googlesource.com/12532
Reviewed-by: Russ Cox <rsc@golang.org>
2015-07-23 14:19:07 +00:00
Ian Lance Taylor
e9fcd6ed2b cmd/link: if -B option was used, pass it to the external linker
Fixes #10607.

Change-Id: Ib294cf65b07103b60f62b86b21ff2d07b25136fe
Reviewed-on: https://go-review.googlesource.com/12242
Reviewed-by: Russ Cox <rsc@golang.org>
2015-07-21 03:57:55 +00:00
Ian Lance Taylor
dabb268170 cmd/compile: ignore carriage return in magic comments
Update #11771.

Change-Id: I3bb3262619765d3ca79652817e17e8f260f41907
Reviewed-on: https://go-review.googlesource.com/12379
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-07-18 17:33:53 +00:00
Russ Cox
19916e453e test/fixedbugs: disable issue11656.go on arm64
For #11656.

Change-Id: I8365d33a15419bd0e54f71182ad0994e41650264
Reviewed-on: https://go-review.googlesource.com/12248
Reviewed-by: Russ Cox <rsc@golang.org>
2015-07-16 02:16:20 +00:00
Ian Lance Taylor
2e4b659954 cmd/compile: recognize embedded field in inlined function
There was already special code to recognize "?" in hidden_structdcl,
which is used for inlined types and variables.  This recognizes "?" in
structdcl as well, a case that arises when a struct type appears
within an inlined function body.

Fixes #10219.

Change-Id: Ic5257ae54f817e0d4a189c2294dcd633c9f2101a
Reviewed-on: https://go-review.googlesource.com/12241
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2015-07-15 06:04:51 +00:00
Russ Cox
0bcdffeea6 runtime: fix x86 stack trace for call to heap memory
Fixes #11656.

Change-Id: Ib81d583e4b004e67dc9d2f898fd798112434e7a9
Reviewed-on: https://go-review.googlesource.com/12026
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
2015-07-13 19:42:35 +00:00
Brad Fitzpatrick
2ae77376f7 all: link to https instead of http
The one in misc/makerelease/makerelease.go is particularly bad and
probably warrants rotating our keys.

I didn't update old weekly notes, and reverted some changes involving
test code for now, since we're late in the Go 1.5 freeze. Otherwise,
the rest are all auto-generated changes, and all manually reviewed.

Change-Id: Ia2753576ab5d64826a167d259f48a2f50508792d
Reviewed-on: https://go-review.googlesource.com/12048
Reviewed-by: Rob Pike <r@golang.org>
2015-07-11 14:36:33 +00:00
Russ Cox
6f80e5edf4 cmd/link: reject data size > 2 GB
We can't address more than this on amd64 anyway.

Fixes #9862.

Change-Id: Ifb1abae558e2e1ee2dc953a76995f3f08c60b1df
Reviewed-on: https://go-review.googlesource.com/11715
Reviewed-by: Austin Clements <austin@google.com>
2015-06-30 19:40:39 +00:00
Russ Cox
1122836b5f cmd/compile: reject large floating point exponents without math/big
For #11326 (but not a fix).

Change-Id: Ic51814f5cd7357427c3fd990a5522775d05e7987
Reviewed-on: https://go-review.googlesource.com/11673
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-06-29 21:18:01 +00:00
Russ Cox
55203c7dd5 cmd/compile: allow unnamed constants to set line number
Fixes #8836.

Change-Id: Idda9f4a987e03b3bdf5e8fdb984fe56d6f84aa59
Reviewed-on: https://go-review.googlesource.com/11672
Reviewed-by: David Chase <drchase@google.com>
2015-06-29 17:35:55 +00:00
Austin Clements
840965f8d7 runtime: always clear stack barriers on G exit
Currently the runtime fails to clear a G's stack barriers in gfput if
the G's stack allocation is _FixedStack bytes. This causes the runtime
to panic if the following sequence of events happens:

1) The runtime installs stack barriers on a G.

2) The G exits by calling runtime.Goexit. Since this does not
   necessarily return through the stack barriers installed on the G,
   there may still be untriggered stack barriers left on the G's stack
   in recorded in g.stkbar.

3) The runtime calls gfput to add the exiting G to the free pool. If
   the G's stack allocation is _FixedStack bytes, we fail to clear
   g.stkbar.

4) A new G starts and allocates the G that was just added to the free
   pool.

5) The new G begins to execute and overwrites the stack slots that had
   stack barriers in them.

6) The garbage collector enters mark termination, attempts to remove
   stack barriers from the new G, and finds that they've been
   overwritten.

Fix this by clearing the stack barriers in gfput in the case where it
reuses the stack.

Fixes #11256.

Change-Id: I377c44258900e6bcc2d4b3451845814a8eeb2bcf
Reviewed-on: https://go-review.googlesource.com/11461
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Reviewed-by: Russ Cox <rsc@golang.org>
2015-06-29 15:02:30 +00:00
Dave Cheney
834fef80ae test: add test case for issue 8154
Updates #8154

Change-Id: Ie9c731a91b008277e51c723eef6871bb0919fa4c
Reviewed-on: https://go-review.googlesource.com/10831
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Russ Cox <rsc@golang.org>
2015-06-26 17:58:22 +00:00
Todd Neal
765c0f37ed cmd/compile: fix half multiply issue
In walkdiv, an OMUL node was created and passed to typecheck,
before the op was changed back to OHMUL.  In some instances,
the node that came back was an evaluated literal constant that
occurred with a full multiply.  The end result was a literal node
with a non-shifted value and an OHMUL op. This change causes code
to be generated for the OHMUL.

Fixes #11358
Fixes #11369

Change-Id: If42a98c6830d07fe065d5ca57717704fb8cfbd33
Reviewed-on: https://go-review.googlesource.com/11400
Reviewed-by: Russ Cox <rsc@golang.org>
2015-06-26 15:55:22 +00:00
Austin Clements
a8ae93fd26 runtime: fix heap bitmap repeating with large scalar tails
When heapBitsSetType repeats a source bitmap with a scalar tail
(typ.ptrdata < typ.size), it lays out the tail upon reaching the end
of the source bitmap by simply increasing the number of bits claimed
to be in the incoming bit buffer. This causes later iterations to read
the appropriate number of zeros out of the bit buffer before starting
on the next repeat of the source bitmap.

Currently, however, later iterations of the loop continue to read bits
from the source bitmap *regardless of the number of bits currently in
the bit buffer*. The bit buffer can only hold 32 or 64 bits, so if the
scalar tail is large and the padding bits exceed the size of the bit
buffer, the read from the source bitmap on the next iteration will
shift the incoming bits into oblivion when it attempts to put them in
the bit buffer. When the buffer does eventually shift down to where
these bits were supposed to be, it will contain zeros. As a result,
words that should be marked as pointers on later repetitions are
marked as scalars, so the garbage collector does not trace them. If
this is the only reference to an object, it will be incorrectly freed.

Fix this by adding logic to drain the bit buffer down if it is large
instead of reading more bits from the source bitmap.

Fixes #11286.

Change-Id: I964432c4b9f1cec334fc8c3da0ff16460203feb6
Reviewed-on: https://go-review.googlesource.com/11360
Reviewed-by: Russ Cox <rsc@golang.org>
2015-06-23 18:37:17 +00:00
Michael Matloob
32f2f72c47 cmd/compile: provide better error when method called without receiver
When a method is called using the Type.Method(receiver, args...) syntax
without the receiver, or enough arguments, provide the more helpful
error message "not enough arguments in call to method expression
Type.Method" instead of the old message "not enough arguments in call
to Type.Method".

Fixes #8385

Change-Id: Id5037eb1ee5fa93687d4a6557b4a8233b29e9df2
Reviewed-on: https://go-review.googlesource.com/2193
Reviewed-by: Russ Cox <rsc@golang.org>
2015-06-18 19:37:38 +00:00
David Chase
5be61b18d4 cmd/compile: run escape analysis after method wrapper generation
Also modified test/run.go to ignore messages prefixed <autogenerated>
because those cannot be described with "// ERROR ...", and backed out
patch from issue #9537 because it is no longer necessary.  The reasons
described in the 9537 discussion for why escape analysis cannot run
late no longer hold, happily.

Fixes #11053.

Change-Id: Icb14eccdf2e8cde3d0f8fb8a216b765400a96385
Reviewed-on: https://go-review.googlesource.com/11088
Reviewed-by: Russ Cox <rsc@golang.org>
Run-TryBot: David Chase <drchase@google.com>
2015-06-17 02:36:45 +00:00
Josh Bleecher Snyder
a44becef4a cmd/compile: use generated temps in bool codegen
Bool codegen was generating a temp for function calls
and other complex expressions, but was not using it.

This was a refactoring bug introduced by CL 7853.
The cmp code used to do (in short):

	l, r := &n1, &n2

It was changed to:

	l, r := nl, nr

But the requisite assignments:

	nl, nr = &n1, &n2

were only introduced on one of two code paths.

Fixes #10654.

Change-Id: Ie8de0b3a333842a048d4308e02911bb10c6915ce
Reviewed-on: https://go-review.googlesource.com/10844
Reviewed-by: Minux Ma <minux@golang.org>
Run-TryBot: Minux Ma <minux@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-06-09 17:38:26 +00:00
Josh Bleecher Snyder
494ff188f8 cmd/compile: early typecheck top level OAS2 nodes
Fixes #10977.

Change-Id: I706c953c16daad48595c7fae2d82124614dfc3ad
Reviewed-on: https://go-review.googlesource.com/10780
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
2015-06-09 00:25:02 +00:00
David Chase
596bb76248 cmd/compile: reject p-notation floats in Go source files
Use pkgimport == nil (or not) to distinguish between
parsing .go source files where "p" exponent specifier
is not allowed and parsing .a or .o export data where
it is.  Use that to control error when p-exponent is
seen.

Fixes #9036

Change-Id: I8924f09c91d4945ef3f20e80a6e544008a94a7e4
Reviewed-on: https://go-review.googlesource.com/10450
Reviewed-by: Russ Cox <rsc@golang.org>
2015-05-28 18:52:14 +00:00
David Chase
05d8f1d166 cmd/compile: propagate correct line numbers in treecopy
Added a lineno parameter to treecopy and listtreecopy
(ignored if = 0).  When nodes are copied the copy is
assigned the non-zero lineno (normally this would be
the destination).

Fixes #8183

Change-Id: Iffb767a745093fb89aa08bf8a7692c2f0122be98
Reviewed-on: https://go-review.googlesource.com/10334
Reviewed-by: Russ Cox <rsc@golang.org>
2015-05-27 17:29:15 +00:00
David Chase
b19ec6842d cmd/internal/gc: make indirect calls properly escape-y
Indirect function and method calls should leak everything,
but they didn't.

This fix had no particular effect on the cost of running the
compiler on html/template/*.go and added a single new "escape"
to the standard library:

    syscall/syscall_unix.go:85: &b[0] escapes to heap
in
	if errno := m.munmap(uintptr(unsafe.Pointer(&b[0])),
	                     uintptr(len(b))); errno != nil {

Added specific escape testing to escape_calls.go
(and verified that it fails without this patch)

I also did a little code cleanup around the changes in esc.c.

Fixes #10925

Change-Id: I9984b701621ad4c49caed35b01e359295c210033
Reviewed-on: https://go-review.googlesource.com/10295
Reviewed-by: Russ Cox <rsc@golang.org>
2015-05-22 01:36:11 +00:00
Russ Cox
cf932cd897 all: retire architecture letter in file names, public API
This CL removes the remaining visible uses of the "architecture letter" concept.
(They are no longer in tool names nor in source directory names.)

Because the architecture letter concept is now gone, delete GOCHAR
from "go env" output, and change go/build.ArchChar to return an
error always.

The architecture letter is still used in the compiler and linker sources
as a clumsy architecture enumeration, but that use is not visible to
Go users and can be cleaned up separately.

Change-Id: I4d97a38f372003fb610c9c5241bea440d9dbeb8d
Reviewed-on: https://go-review.googlesource.com/10289
Reviewed-by: Rob Pike <r@golang.org>
2015-05-21 17:32:17 +00:00
Russ Cox
0f4132c907 all: build and use go tool compile, go tool link
This CL fixes the build to use the newly created go tool compile
and go tool link in place of go tool 5g, go tool 5l, and so on.

See golang-dev thread titled "go tool compile, etc" for background.

Although it was not a primary motivation, this conversion does
reduce the wall clock time and cpu time required for make.bash
by about 10%.

Change-Id: I79cbbdb676cab029db8aeefb99a53178ff55f98d
Reviewed-on: https://go-review.googlesource.com/10288
Reviewed-by: Rob Pike <r@golang.org>
2015-05-21 17:32:03 +00:00
Russ Cox
c735064cde cmd/internal/gc: type of str[i] is byte, not uint8
Fixes #8745.

Change-Id: Id0641e3c0f259812b41ed871e83c68740feb2b19
Reviewed-on: https://go-review.googlesource.com/10261
Reviewed-by: Austin Clements <austin@google.com>
2015-05-19 19:20:25 +00:00
Robert Griesemer
99475dfb59 cmd/internal/gc: avoid spurious div-zero errors
Set overflowing integer constants to 1 rather than 0 to avoid
spurious div-zero errors in subsequent constant expressions.

Also: Exclude new test case from go/types test since it's
running too long (go/types doesn't have an upper constant
size limit at the moment).

Fixes #7746.

Change-Id: I3768488ad9909a3cf995247b81ee78a8eb5a1e41
Reviewed-on: https://go-review.googlesource.com/9165
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2015-05-13 17:38:13 +00:00
Russ Cox
3f209abb29 cmd/internal/gc: detect bad append(f()) during type check
Today's earlier fix can stay, but it's a band-aid over the real problem,
which is that bad code was slipping through the type checker
into the back end (and luckily causing a type error there).

I discovered this because my new append does not use the same
temporaries and failed the test as written.

Fixes #9521.

Change-Id: I7e33e2ea15743406e15c6f3fdf73e1edecda69bd
Reviewed-on: https://go-review.googlesource.com/9921
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-05-12 16:26:35 +00:00
Didier Spezia
7c0db1b7e2 cmd/gc: do not display ~b identifiers in error messages
Instead of errors like:

./blank2.go:15: cannot use ~b1 (type []int) as type int in assignment

we now have:

./blank2.go:15: cannot use _ (type []int) as type int in assignment

Less confusing for users.

Fixes #9521

Change-Id: Ieab9859040e8e0df95deeaee7eeb408d3be61c0f
Reviewed-on: https://go-review.googlesource.com/9902
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-05-11 17:44:31 +00:00
David Chase
d4bb72b485 cmd/internal/gc: improve "type *X has no field or method M" message
Try to provide hints for common areas, either *interface
were interface would have been better, and note incorrect
capitalization (but don't be more ambitious than that, at
least not today).

Added code and test for cases

  ptrInterface.ExistingMethod
  ptrInterface.unexportedMethod
  ptrInterface.MissingMethod
  ptrInterface.withwRongcASEdMethod
  interface.withwRongcASEdMethod
  ptrStruct.withwRongcASEdMethod
  struct.withwRongcASEdMethod

also included tests for related errors to check for
unintentional changes and consistent wording.

Somewhat simplified from previous versions to avoid second-
guessing user errors, yet also biased to point out most-likely
root cause.

Fixes #10700

Change-Id: I16693e93cc8d8ca195e7742a222d640c262105b4
Reviewed-on: https://go-review.googlesource.com/9731
Reviewed-by: Russ Cox <rsc@golang.org>
2015-05-07 16:21:57 +00:00
David Chase
7fbb1b36c3 cmd/internal/gc: improve flow of input params to output params
This includes the following information in the per-function summary:

outK = paramJ   encoded in outK bits for paramJ
outK = *paramJ  encoded in outK bits for paramJ
heap = paramJ   EscHeap
heap = *paramJ  EscContentEscapes

Note that (currently) if the address of a parameter is taken and
returned, necessarily a heap allocation occurred to contain that
reference, and the heap can never refer to stack, therefore the
parameter and everything downstream from it escapes to the heap.

The per-function summary information now has a tuneable number of bits
(2 is probably noticeably better than 1, 3 is likely overkill, but it
is now easy to check and the -m debugging output includes information
that allows you to figure out if more would be better.)

A new test was  added to check pointer flow through struct-typed and
*struct-typed parameters and returns; some of these are sensitive to
the number of summary bits, and ought to yield better results with a
more competent escape analysis algorithm.  Another new test checks
(some) correctness with array parameters, results, and operations.

The old analysis inferred a piece of plan9 runtime was non-escaping by
counteracting overconservative analysis with buggy analysis; with the
bug fixed, the result was too conservative (and it's not easy to fix
in this framework) so the source code was tweaked to get the desired
result.  A test was added against the discovered bug.

The escape analysis was further improved splitting the "level" into
3 parts, one tracking the conventional "level" and the other two
computing the highest-level-suffix-from-copy, which is used to
generally model the cancelling effect of indirection applied to
address-of.

With the improved escape analysis enabled, it was necessary to
modify one of the runtime tests because it now attempts to allocate
too much on the (small, fixed-size) G0 (system) stack and this
failed the test.

Compiling src/std after touching src/runtime/*.go with -m logging
turned on shows 420 fewer heap allocation sites (10538 vs 10968).

Profiling allocations in src/html/template with
for i in {1..5} ;
  do go tool 6g -memprofile=mastx.${i}.prof  -memprofilerate=1 *.go;
  go tool pprof -alloc_objects -text  mastx.${i}.prof ;
done

showed a 15% reduction in allocations performed by the compiler.

Update #3753
Update #4720
Fixes #10466

Change-Id: I0fd97d5f5ac527b45f49e2218d158a6e89951432
Reviewed-on: https://go-review.googlesource.com/8202
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2015-05-01 13:47:20 +00:00
Josh Bleecher Snyder
1fb948a029 test: set GOMAXPROCS=1 in fixedbugs/issue9110
With this fix,

GOMAXPROCS=8 ./all.bash

passes, at least on my machine.

Fixes #10216.

Change-Id: Ib5991950892a1399ec81aced0a52b435e6f83fdf
Reviewed-on: https://go-review.googlesource.com/9392
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-04-28 00:06:13 +00:00
Michael Hudson-Doyle
b92a0a8969 cmd/internal/gc, cmd/go: fix value of importpath symbol
In https://golang.org/cl/7797 I attempted to use myimportpath to set the value
of the go.importpath.$foo. symbol for the module being compiled, but I messed
it up and only set the name (which the linker rewrites anyway). This lead to
the importpath for the module being compiled being "". This was hard to notice,
because all modules that import another define the importpath for their
imported modules correctly -- but main is not imported, and this meant that the
reflect module saw all fields of all types defined in the main module as
exported.

The fix is to do what I meant to do the first time, add a test and change the
go tool to compile main packages with -p main and not -p
command-line-arguments.

Fixes #10332

Change-Id: I5fc6e9b1dc2b26f058641e382f9a56a526eca291
Reviewed-on: https://go-review.googlesource.com/8481
Reviewed-by: Russ Cox <rsc@golang.org>
2015-04-19 20:14:59 +00:00
Dmitry Vyukov
24f246c1b6 cmd/gc: fix crash during escape analysis
Fixes #10441

Compiler crashed as:

panic: runtime error: invalid memory address or nil pointer dereference
goroutine 1 [running]:
cmd/internal/gc.haspointers(0x0, 0xffffffffffffffff)
    src/cmd/internal/gc/reflect.go:623 +0x1f
cmd/internal/gc.escwalk(0x20c82dc00, 0xffffffffffffffff, 0x20c82dda0, 0x20c835520)
    src/cmd/internal/gc/esc.go:1291 +0x14aa
cmd/internal/gc.escwalk(0x20c82dc00, 0xffffffffffffffff, 0x20c82dda0, 0x20beac340)
    src/cmd/internal/gc/esc.go:1386 +0x836

while evaluating haspointers of the fake OADDR node here:

	leaks = level <= 0 && dst.Escloopdepth < src.Escloopdepth || level < 0 && dst == &e.funcParam && haspointers(src.Type)

Change-Id: I13c23fced52e8fcd0ae1df81b374df8632eb7790
Reviewed-on: https://go-review.googlesource.com/8932
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Dmitry Vyukov <dvyukov@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-04-14 15:45:26 +00:00
Ian Lance Taylor
607d5158c1 test: add gcc65755.go for http://gcc.gnu.org/PR65755
Change-Id: Ic35dff4c9a7fc6716ef9d5553a7b1769bed9be01
Reviewed-on: https://go-review.googlesource.com/8892
Reviewed-by: Minux Ma <minux@golang.org>
2015-04-13 23:24:30 +00:00
Shenghou Ma
399b3e3230 test: add gccgo test case for #10407
Change-Id: I8d17e2b0fbc529ca7958c75222964a5e419aa3db
Reviewed-on: https://go-review.googlesource.com/8717
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-10 22:51:46 +00:00
Dmitry Vyukov
878a86a129 cmd/gc: fix escape analysis of closures
Fixes #10353

See test/escape2.go:issue10353. Previously new(int) did not escape to heap,
and so heap-allcated closure was referencing a stack var. This breaks
the invariant that heap must not contain pointers to stack.

Look at the following program:

package main

func main() {
	foo(new(int))
	bar(new(int))
}

func foo(x *int) func() {
	return func() {
		println(*x)
	}
}

// Models what foo effectively does.
func bar(x *int) *C {
	return &C{x}
}

type C struct {
	x *int
}

Without this patch escape analysis works as follows:

$ go build -gcflags="-m -m -m -l" esc.go
escflood:1: dst ~r1 scope:foo[0]
escwalk: level:0 depth:0  func literal( l(9) f(1) esc(no) ld(1)) scope:foo[1]
/tmp/live2.go:9: func literal escapes to heap
escwalk: level:0 depth:1 	 x( l(8) class(PPARAM) f(1) esc(no) ld(1)) scope:foo[1]
/tmp/live2.go:8: leaking param: x to result ~r1

escflood:2: dst ~r1 scope:bar[0]
escwalk: level:0 depth:0  &C literal( l(15) esc(no) ld(1)) scope:bar[1]
/tmp/live2.go:15: &C literal escapes to heap
escwalk: level:-1 depth:1 	 &C literal( l(15)) scope:bar[0]
escwalk: level:-1 depth:2 		 x( l(14) class(PPARAM) f(1) esc(no) ld(1)) scope:bar[1]
/tmp/live2.go:14: leaking param: x

/tmp/live2.go:5: new(int) escapes to heap
/tmp/live2.go:4: main new(int) does not escape

new(int) does not escape while being captured by the closure.
With this patch escape analysis of foo and bar works similarly:

$ go build -gcflags="-m -m -m -l" esc.go
escflood:1: dst ~r1 scope:foo[0]
escwalk: level:0 depth:0  &(func literal)( l(9)) scope:foo[0]
escwalk: level:-1 depth:1 	 func literal( l(9) f(1) esc(no) ld(1)) scope:foo[1]
/tmp/live2.go:9: func literal escapes to heap
escwalk: level:-1 depth:2 		 x( l(8) class(PPARAM) f(1) esc(no) ld(1)) scope:foo[1]
/tmp/live2.go:8: leaking param: x

escflood:2: dst ~r1 scope:bar[0]
escwalk: level:0 depth:0  &C literal( l(15) esc(no) ld(1)) scope:bar[1]
/tmp/live2.go:15: &C literal escapes to heap
escwalk: level:-1 depth:1 	 &C literal( l(15)) scope:bar[0]
escwalk: level:-1 depth:2 		 x( l(14) class(PPARAM) f(1) esc(no) ld(1)) scope:bar[1]
/tmp/live2.go:14: leaking param: x

/tmp/live2.go:4: new(int) escapes to heap
/tmp/live2.go:5: new(int) escapes to heap

Change-Id: Ifd14b7ae3fc11820e3b5eb31eb07f35a22ed0932
Reviewed-on: https://go-review.googlesource.com/8408
Reviewed-by: Russ Cox <rsc@golang.org>
Run-TryBot: Dmitry Vyukov <dvyukov@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-04-09 09:56:27 +00:00
Matthew Dempsky
4f2a73011f cmd/internal/gc, cmd/yacc: restore remaining custom error messages
This CL extends cmd/yacc to expose a yyErrorVerbose variable that
changes the error messages from just "syntax error" to "syntax error:
unexpected ${tokname}".

It also moves the yyToknames table generation to after rules have been
processed so that entries can be generated for tokens that aren't
mentioned in the preamble (e.g., '.' in the case of go.y).

Lastly, it restores gc's old code for applying yytfix to yyToknames,
except that substituting "LLITERAL" with litbuf happens in Yyerror.

Fixes #9968.

Change-Id: Icec188d11fdabc1dae31b8a471c35b5c7f6deec7
Reviewed-on: https://go-review.googlesource.com/8432
Reviewed-by: Russ Cox <rsc@golang.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-04-03 23:40:40 +00:00
David Crawshaw
ca0adeddd5 cmd/7g: reserve registers R26 to R32
These registers are not available for programs to use. Prior to this
change, the compiler would crash attempting to use ZR as a general
purpose register. Other programs would compile but on execution would
overwrite the G register and cause havoc.

Fixes linux/arm64 build.
Fixes #10304
Fixes #10320

Change-Id: I5cf51d3b77cfe3db7dd6377324950cafb02f8d8b
Reviewed-on: https://go-review.googlesource.com/8456
Reviewed-by: Minux Ma <minux@golang.org>
2015-04-03 18:25:09 +00:00
Robert Griesemer
a51d5f27e8 cmd/internal/gc: use 512 bits (rather than 464) for multi-precision arithmetic
The original implementation used 16 int "words" but only 29 bits per word
for a total of 16*29 = 464 bits, with a space consumption of 16*64 = 1024
bits on a 64 bit machine. Switching to 512 bits increases precision while
still using (in the worst case) half the amount of memory per mp value on
a 64 bit machine.

Also: Decreased permitted number of least-significant mantissa bits which
may be incorrect when considering if a precise floating-point constant is
an integer from 29 to 16 bits.

Change-Id: Iee9287056f0e9aa4f06ceac0724ff4674f710c53
Reviewed-on: https://go-review.googlesource.com/8429
Reviewed-by: Russ Cox <rsc@golang.org>
2015-04-03 17:13:07 +00:00
Robert Griesemer
5bb89eb009 cmd/internal/gc: use big.Float to represent Mpflt bits
All multi-precision arithmetic is now based on math/big.

- passes all.bash
- added test cases for fixed bugs

Fixes #7740.
Fixes #6866.

Change-Id: I67268b91766970ced3b928260053ccdce8753d58
Reviewed-on: https://go-review.googlesource.com/7912
Reviewed-by: Russ Cox <rsc@golang.org>
2015-04-02 22:49:47 +00:00
Matthew Dempsky
398bf9d5a0 cmd/internal/gc, cmd/yacc: restore custom syntax error messages
This restores go.errors from before 3af0d79 along with a fixed up
version of the bisonerrors AWK script, translated to Go.

However, this means Yyerror needs access to the yacc parser's state,
which is currently private.  To workaround that, add a "state"
accessor method like the Lookahead method added in c7fa3c6.

Update issue #9968.

Change-Id: Ib868789e92fdb7d135442120a392457923e50121
Reviewed-on: https://go-review.googlesource.com/7270
Reviewed-by: Russ Cox <rsc@golang.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-04-02 21:56:24 +00:00
David Crawshaw
33448d963c cmd/7g: fix ACMP entry in progtable
On arm64, CMP $foo, R is encoded as from=$foo, reg=R, not as from=$foo,
to=R. The progtable entry for ACMP incorrectly described the latter
form. Because of this, the registerizer was not accounting the registers
used in CMP instructions and was incorrectly re-assigning those registers.

This was an old problem, but it only became apparent after b115c35
(cmd/internal/gc: move cgen, regalloc, et al to portable code). Previous
to this commit, the compiler used a slightly larger register set for the
temps than it used for register variables. Since it had plenty registers
dedicated to temps, the registers used in CMP instruction never clashed
with registers assigned to register variables.

Fixes #10253

Change-Id: Iedf4bd882bd59440dff310ac0f81e0f53d80d7ed
Reviewed-on: https://go-review.googlesource.com/8387
Reviewed-by: Aram Hăvărneanu <aram@mgk.ro>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Minux Ma <minux@golang.org>
2015-04-02 20:18:28 +00:00
Shenghou Ma
73c026e6fe test: add testcase for gccgo-specific issue 10284
Change-Id: I624b336a9eb27fbbc8ef13f141023b4f60966245
Reviewed-on: https://go-review.googlesource.com/8240
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-03-30 19:31:35 +00:00
Ian Lance Taylor
362f7bfa68 test: add test that gccgo failed to compile
Change-Id: I9ea6d4d8a9c1c63de36f2f3871dd5ac9201c0aac
Reviewed-on: https://go-review.googlesource.com/7523
Reviewed-by: Minux Ma <minux@golang.org>
2015-03-13 22:05:23 +00:00
Shenghou Ma
0d6a0d6c3f runtime: don't return a slice with nil ptr but non-zero len from growslice
Fixes #10135.

Change-Id: Ic4c5ab15bcb7b9c3fcc685a788d3b59c60c26e1e
Signed-off-by: Shenghou Ma <minux@golang.org>
Reviewed-on: https://go-review.googlesource.com/7400
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-03-12 00:08:38 +00:00
Chris Manghane
09b49bf18d test: add testcase for gccgo-specific issue 10047.
Change-Id: Ia5115b15a79e1b2b53036646f1ed4b08225b220f
Reviewed-on: https://go-review.googlesource.com/7051
Run-TryBot: Chris Manghane <cmang@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-03-06 22:29:08 +00:00
Shenghou Ma
f09887cdce cmd/internal/gc: do not show original expression for constants in export data
Fixes #10066.

Change-Id: I43c423793dd094989e921e163a06b12181a35719
Signed-off-by: Shenghou Ma <minux@golang.org>
Reviewed-on: https://go-review.googlesource.com/6750
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Chris Manghane <cmang@golang.org>
2015-03-05 03:40:42 +00:00
Chris Manghane
77d7771a82 cmd/internal/gc: omit non-explicit capacity in errors with map/chan make
Fixes #9083.

Change-Id: Ifbdebafb39a73a1dacf7e67171e8e88028d1f10b
Reviewed-on: https://go-review.googlesource.com/1219
Reviewed-by: Russ Cox <rsc@golang.org>
Run-TryBot: Chris Manghane <cmang@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-02-25 20:04:22 +00:00
Chris Manghane
c7e1453e3d cmd/internal/gc: do not show computed value in type error
Fixes #9076.

Change-Id: Ib41a452fa9aa9fecf19f65c36d13715923548041
Reviewed-on: https://go-review.googlesource.com/1250
Reviewed-by: Minux Ma <minux@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
Run-TryBot: Chris Manghane <cmang@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-02-25 19:49:49 +00:00
Chris Manghane
b59dd94f33 cmd/internal/gc: method selector should not auto-deref named pointer type
Fixes #9017.

Change-Id: I26cb1e7d6e137ff145773169cfe2d8bd4e1b339c
Reviewed-on: https://go-review.googlesource.com/1252
Reviewed-by: Russ Cox <rsc@golang.org>
Run-TryBot: Chris Manghane <cmang@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-02-25 19:27:30 +00:00
Russ Cox
5b94a47b7f [dev.cc] test: disable syntax error tests
These don't work with the new compiler, because the
new compiler doesn't have the custom syntax errors
that I built for the old compiler. It will, just not yet.
(Issue #9968.)

Change-Id: I658f7dab2c7f855340a501f9ae4479c097b28cd3
Reviewed-on: https://go-review.googlesource.com/5632
Reviewed-by: Rob Pike <r@golang.org>
2015-02-23 19:56:11 +00:00
Ian Lance Taylor
5aa448ff8c test: add test case for issue 4365
This is an update of http://golang.org/cl/151410043 by Tim Shen.

Change-Id: I43ab7fcedd785059c535f45a3c8cdb7b618c1499
Reviewed-on: https://go-review.googlesource.com/4873
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-02-14 16:02:10 +00:00
Dmitry Vyukov
c4ee44b7b9 cmd/gc: transform closure calls to function calls
Currently we always create context objects for closures that capture variables.
However, it is completely unnecessary for direct calls of closures
(whether it is func()(), defer func()() or go func()()).
This change transforms any OCALLFUNC(OCLOSURE) to normal function call.
Closed variables become function arguments.
This transformation is especially beneficial for go func(),
because we do not need to allocate context object on heap.
But it makes direct closure calls a bit faster as well (see BenchmarkClosureCall).

On implementation level it required to introduce yet another compiler pass.
However, the pass iterates only over xtop, so it should not be an issue.
Transformation consists of two parts: closure transformation and call site
transformation. We can't run these parts on different sides of escape analysis,
because tree state is inconsistent. We can do both parts during typecheck,
we don't know how to capture variables and don't have call site.
We can't do both parts during walk of OCALLFUNC, because we can walk
OCLOSURE body earlier.
So now capturevars pass only decides how to capture variables
(this info is required for escape analysis). New transformclosure
pass, that runs just before order/walk, does all transformations
of a closure. And later walk of OCALLFUNC(OCLOSURE) transforms call site.

benchmark                            old ns/op     new ns/op     delta
BenchmarkClosureCall                 4.89          3.09          -36.81%
BenchmarkCreateGoroutinesCapture     1634          1294          -20.81%

benchmark                            old allocs     new allocs     delta
BenchmarkCreateGoroutinesCapture     6              2              -66.67%

benchmark                            old bytes     new bytes     delta
BenchmarkCreateGoroutinesCapture     176           48            -72.73%

Change-Id: Ic85e1706e18c3235cc45b3c0c031a9c1cdb7a40e
Reviewed-on: https://go-review.googlesource.com/4050
Reviewed-by: Russ Cox <rsc@golang.org>
2015-02-13 12:12:18 +00:00
Josh Bleecher Snyder
77a2113925 cmd/gc: evaluate concrete == interface without allocating
Consider an interface value i of type I and concrete value c of type C.

Prior to this CL, i==c was evaluated as
	I(c) == i

Evaluating I(c) can allocate.

This CL changes the evaluation of i==c to
	x, ok := i.(C); ok && x == c

The new generated code is shorter and does not allocate directly.

If C is small, as it is in every instance in the stdlib,
the new code also uses less stack space
and makes one runtime call instead of two.

If C is very large, the original implementation is used.
The cutoff for "very large" is 1<<16,
following the stack vs heap cutoff used elsewhere.

This kind of comparison occurs in 38 places in the stdlib,
mostly in the net and os packages.

benchmark                     old ns/op     new ns/op     delta
BenchmarkEqEfaceConcrete      29.5          7.92          -73.15%
BenchmarkEqIfaceConcrete      32.1          7.90          -75.39%
BenchmarkNeEfaceConcrete      29.9          7.90          -73.58%
BenchmarkNeIfaceConcrete      35.9          7.90          -77.99%

Fixes #9370.

Change-Id: I7c4555950bcd6406ee5c613be1f2128da2c9a2b7
Reviewed-on: https://go-review.googlesource.com/2096
Reviewed-by: Russ Cox <rsc@golang.org>
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
2015-02-12 22:23:38 +00:00
Josh Bleecher Snyder
4ce06f4b5c cmd/gc: eliminate dead code in switch statements
Ordinary switch statements are rewritten
into a sequence of if statements.
Staticly dead cases were not being eliminated
because the rewrite introduced a temporary,
which hid the fact that the case was a constant.
Stop doing that.

This eliminates dead code in the standard library at:

runtime/cgocall.go:219
runtime/cgocall.go:269
debug/gosym/pclntab.go:175
debug/macho/file.go:208
math/big/nat.go:635
math/big/nat.go:850
math/big/nat.go:1058
cmd/pprof/internal/commands/commands.go:86
net/sock_bsd.go:19
cmd/go/build.go:2657
cmd/go/env.go:90

Fixes #9608.

Change-Id: Ic23a05dfbb1ad91d5f62a6506b35a13e51b33e38
Reviewed-on: https://go-review.googlesource.com/3980
Reviewed-by: Keith Randall <khr@golang.org>
2015-02-06 19:05:47 +00:00
Péter Surányi
9b6ccb1323 all: don't refer to code.google.com/p/go{,-wiki}/
Only documentation / comment changes. Update references to
point to golang.org permalinks or go.googlesource.com/go.
References in historical release notes under doc are left as is.

Change-Id: Icfc14e4998723e2c2d48f9877a91c5abef6794ea
Reviewed-on: https://go-review.googlesource.com/4060
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-02-06 14:41:47 +00:00
Rahul Chaudhry
d81cc374be test: chdir before running go tool, cleanup afterwards.
issue9355 generated a file a.[568] in test/ directory and left it there.
For tests like these, it is best to chdir to a test specific directory
before generating any temporary files, since the tests are running
in parallel and might otherwise race with each other for the same files.

Change-Id: I58d96256d4d8ee3fda70d81077f19006064a7425
Reviewed-on: https://go-review.googlesource.com/3813
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-02-06 05:16:34 +00:00
Dmitry Vyukov
8e2423a67d cmd/gc: typecheck type switch variables
Type switch variables was not typechecked.
Previously it lead only to a minor consequence:

switch unsafe.Sizeof = x.(type) {

generated an inconsistent error message.
But capturing by value functionality now requries typechecking of all ONAMEs.

Fixes #9731

Change-Id: If037883cba53d85028fb97b1328696091b3b7ddd
Reviewed-on: https://go-review.googlesource.com/3600
Reviewed-by: Russ Cox <rsc@golang.org>
2015-02-03 15:44:06 +00:00
Shenghou Ma
3bf005cea3 cmd/gc: always treat the output parameters as having been assigned in capturevars.
Fixes #9738.

Change-Id: Iab75de2d78335d4e31c3dce6a0e1826d8cddf5f3
Reviewed-on: https://go-review.googlesource.com/3690
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
2015-02-02 14:14:21 +00:00
Dmitry Vyukov
b581ca5956 cmd/gc: allow map index expressions in for range statements
Fixes #9691.

Change-Id: I22bfc82e05497e91a7b18a668913aed6c723365d
Reviewed-on: https://go-review.googlesource.com/3282
Reviewed-by: Russ Cox <rsc@golang.org>
2015-01-28 15:14:04 +00:00
Ian Lance Taylor
ec0ebc2281 cmd/gc: treat non-local vars inlined into wrapper as escaping
The compiler has a phase ordering problem.  Escape analysis runs
before wrapper generation.  When a generated wrapper calls a method
defined in a different package, if that call is inlined, there will be
no escape information for the variables defined in the inlined call.
Those variables will be placed on the stack, which fails if they
actually do escape.

There are probably various complex ways to fix this.  This is a simple
way to avoid it: when a generated wrapper calls a method defined in a
different package, treat all local variables as escaping.

Fixes #9537.

Change-Id: I530f39346de16ad173371c6c3f69cc189351a4e9
Reviewed-on: https://go-review.googlesource.com/3092
Reviewed-by: Russ Cox <rsc@golang.org>
2015-01-22 03:25:12 +00:00
Chris Manghane
f5b8813e93 cmd/gc: don't unpack struct arguments to append
Fixes #9634.

Change-Id: I7b18f26c2fb812978fc7adc5bfd39ebfffe48701
Reviewed-on: https://go-review.googlesource.com/3080
Reviewed-by: Minux Ma <minux@golang.org>
2015-01-20 22:55:56 +00:00
Keith Randall
c3b459d328 test: generate tests for arithmetic on narrow types
Fixes #9607
Related to #9604
Inadvertently found #9609

Change-Id: I8a8ddf84ac72d3e18986fd8e9288734459f3f174
Reviewed-on: https://go-review.googlesource.com/2962
Reviewed-by: Minux Ma <minux@golang.org>
2015-01-17 21:00:15 +00:00
Keith Randall
daa64ddfe6 cmd/5g: make sure we normalize after unary ops on small types
We were failing ^uint16(0xffff) == 0, as we computed 0xffff0000 instead.

I could only trigger a failure for the above case, the other two tests
^uint16(0xfffe) == 1 and -uint16(0xffff) == 1 didn't seem to fail
previously.  Somehow they get MOVHUs inserted for other reasons (used
by CMP instead of TST?).  I fixed OMINUS anyway, better safe than
sorry.

Fixes #9604

Change-Id: I4c2d5bdc667742873ac029fdbe3db0cf12893c27
Reviewed-on: https://go-review.googlesource.com/2940
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Minux Ma <minux@golang.org>
2015-01-15 23:50:01 +00:00
Shenghou Ma
fcff3ba740 cmd/gc: don't recurse infinitely when a recursive type references itself more than once
Fixes #9432

Change-Id: I08c92481afa7c7fac890aa780efc1cb2fabad528
Reviewed-on: https://go-review.googlesource.com/2115
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Russ Cox <rsc@golang.org>
2015-01-12 02:09:50 +00:00
Josh Bleecher Snyder
f03c9202c4 cmd/gc: optimize memclr of slices and arrays
Recognize loops of the form

for i := range a {
	a[i] = zero
}

in which the evaluation of a is free from side effects.
Replace these loops with calls to memclr.
This occurs in the stdlib in 18 places.

The motivating example is clearing a byte slice:

benchmark                old ns/op     new ns/op     delta
BenchmarkGoMemclr5       3.31          3.26          -1.51%
BenchmarkGoMemclr16      13.7          3.28          -76.06%
BenchmarkGoMemclr64      50.8          4.14          -91.85%
BenchmarkGoMemclr256     157           6.02          -96.17%

Update #5373.

Change-Id: I99d3e6f5f268e8c6499b7e661df46403e5eb83e4
Reviewed-on: https://go-review.googlesource.com/2520
Reviewed-by: Keith Randall <khr@golang.org>
2015-01-09 22:35:25 +00:00
Keith Randall
fcfbeb3adf test: shorten test runtime
This test was taking a long time, reduce its zealousness.

Change-Id: Ib824247b84b0039a9ec690f72336bef3738d4c44
Reviewed-on: https://go-review.googlesource.com/2502
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Minux Ma <minux@golang.org>
2015-01-08 04:49:43 +00:00
Matthew Dempsky
537ddc9456 runtime: fix slicecopy return value for zero-width elements
Fixes #8620

Change-Id: Idb49e586919d21d07e94a39ed9ebb0562f403460
Reviewed-on: https://go-review.googlesource.com/2221
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-01-04 01:59:59 +00:00
Shenghou Ma
cb1897a58c cmd/gc: give an error if only one argument is given to complex()
Fixes #8501

Change-Id: I0dbbdded7f7924351c3d1841d60cb5c934b295b7
Reviewed-on: https://go-review.googlesource.com/2143
Reviewed-by: Chris Manghane <cmang@golang.org>
2015-01-02 02:52:56 +00:00
Chris Manghane
5cc29ab95e cmd/gc: logical operators should produce untyped bool for untyped
operands

Fixes #6671 for cmd/gc.

Change-Id: I4907655b6e243960f2ceb544c63ea16513c7bd68
Reviewed-on: https://go-review.googlesource.com/1251
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-29 23:36:30 +00:00
Chris Manghane
edf7258416 test: add fixed GoSmith bugs reported on the gcc Bugzilla
Change-Id: I36b57f3e299a4f96b8b5aa55c9c224d888229684
Reviewed-on: https://go-review.googlesource.com/1790
Reviewed-by: Minux Ma <minux@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2014-12-29 23:21:10 +00:00
Shenghou Ma
958e0792b5 test/fixedbugs/issue9355: fix build on arm and power64
Change-Id: I1ef770184ad1d42bcb58714d559f2cc866a919ab
Signed-off-by: Shenghou Ma <minux@golang.org>
Reviewed-on: https://go-review.googlesource.com/1880
Reviewed-by: Keith Randall <khr@golang.org>
2014-12-24 00:07:46 +00:00
David du Colombier
fbdf59a7c4 test: disable bug248 and bug345 tests on Plan 9
These tests were enabled as part of change 1774.
They depend on the errchk tool, which is a Perl
script. However, Perl is not available on Plan 9.

Change-Id: I82707aae16013acc9a3800d39b0084588b852b53
Reviewed-on: https://go-review.googlesource.com/2031
Reviewed-by: Minux Ma <minux@golang.org>
2014-12-23 10:28:39 +00:00
Josh Bleecher Snyder
209dd4cdc1 test: fix windows build
Broken by e7173dfdfd

Fix by simply disabling the relevant tests.

* bug248 and bug345 require errchk, but we can't
  rely on perl being available.
* bug369 is disabled anyway.

Change-Id: Idf73ebccb066943e3fe17c2f662b37238ec74dfe
Reviewed-on: https://go-review.googlesource.com/2052
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2014-12-23 01:12:30 +00:00
Ian Lance Taylor
02f56bfb5c test: add test case that gccgo failed to link
Gccgo creates a struct to hold the arguments for the deferred
function.  In this example the struct holds a type defined in a
different package.  The bug was that gccgo tried to create an equality
function for this struct, and it implemented that function by calling
the equality function for the type defined in the other package.
Since that type is not exported, the reference to the equality
function failed at link time.  Normally it is impossible for a struct
to directly contain a member that is an unexported type from another
package, but in this specific case it was possible.  Fixed in gccgo
with https://codereview.appspot.com/183500043 .

Change-Id: I8ec3a33631225b9ac2a4ac060cb4d10b4635e60b
Reviewed-on: https://go-review.googlesource.com/1690
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Minux Ma <minux@golang.org>
2014-12-22 23:07:10 +00:00
Josh Bleecher Snyder
e7173dfdfd test: migrate remaining tests to run.go
* bug248, bug345, bug369, and bug429 were ported from bash commands to run scripts. bug369 remains disabled.
* bug395 is a test for issue 1909, which is still open. It is marked as skip now and will be usable with compile with run.go when issue 1909 is fixed.

Fixes #4139

Updates #1909

Change-Id: Ibb5fbfb5cf72ddc285829245318eeacd3fb5a636
Reviewed-on: https://go-review.googlesource.com/1774
Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-22 22:41:34 +00:00
Shenghou Ma
c5089a7a81 test/fixedbugs/issue9355: fix build on windows and skip on nacl
Change-Id: If367cc1e8c2d744569513bc71da6e6c454c74e9a
Signed-off-by: Shenghou Ma <minux@golang.org>
Reviewed-on: https://go-review.googlesource.com/1802
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2014-12-19 01:06:33 +00:00
Keith Randall
2fc29a83ae cmd/gc: resolve static addresses of the form &x.f at link time
When we do y = &x for global variables x and y, y gets initialized
at link time.  Do the same for y = &x.f if x is a struct and y=&x[5]
if x is an array.

fixes #9217
fixes #9355

Change-Id: Iea3c0ce2ce1b309e2b760e345608fd95460b5713
Reviewed-on: https://go-review.googlesource.com/1691
Reviewed-by: Minux Ma <minux@golang.org>
2014-12-18 21:53:03 +00:00
Ian Lance Taylor
6cd4d59db6 test: add bug494: test case miscompiled by gccgo
Gccgo incorrectly executed functions multiple times when they appeared
in a composite literal that required a conversion between different
interface types.

Change-Id: I7b40e76ed23fa8440ffa03b262041265c109adf7
Reviewed-on: https://go-review.googlesource.com/1710
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Minux Ma <minux@golang.org>
2014-12-18 02:45:00 +00:00
Ian Lance Taylor
60ea2c594b test: add test that gccgo failed to compile
Gccgo failed to create the type descriptor for the type used to
allocate the nil value passed to append as the second argument when
append is called with only one argument.  Calling append with only one
argument is unusual but obviously should not cause a compiler crash.

Change-Id: I530821847dfd68f0302de6ca6a84dfbc79653935
Reviewed-on: https://go-review.googlesource.com/1692
Reviewed-by: Minux Ma <minux@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2014-12-17 02:22:57 +00:00
Keith Randall
50bc3d5bbc runtime: fix deadlock in runtime.Stack
It shouldn't semacquire() inside an acquirem(), the runtime
thinks that means deadlock.  It actually isn't a deadlock, but it
looks like it because acquirem() does m.locks++.

Candidate for inclusion in 1.4.1.  runtime.Stack with all=true
is pretty unuseable in GOMAXPROCS>1 environment.

fixes #9321

Change-Id: Iac6b664217d24763b9878c20e49229a1ecffc805
Reviewed-on: https://go-review.googlesource.com/1600
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
2014-12-16 17:04:45 +00:00
Shenghou Ma
e8f13700b7 test/fixedbugs/bug302: fix test on windows.
Change-Id: I74c2578d1620b37a6486eca00a774b9a736a8899
Reviewed-on: https://go-review.googlesource.com/1222
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2014-12-09 05:23:35 +00:00
Ian Lance Taylor
c5de72b213 test: write Go wrapper code so that bug302 can be run by run.go
Issue #4139.

Change-Id: I50d85a65b22c0cfb4d2a078cee45cf7adb23ba77
Reviewed-on: https://go-review.googlesource.com/1210
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2014-12-09 01:07:27 +00:00
Russ Cox
b3932baba4 runtime: fix sudog leak
The SudoG used to sit on the stack, so it was cheap to allocated
and didn't need to be cleaned up when finished.

For the conversion to Go, we had to move sudog off the stack
for a few reasons, so we added a cache of recently used sudogs
to keep allocation cheap. But we didn't add any of the necessary
cleanup before adding a SudoG to the new cache, and so the cached
SudoGs had stale pointers inside them that have caused all sorts
of awful, hard to debug problems.

CL 155760043 made sure SudoG.elem is cleaned up.
CL 150520043 made sure SudoG.selectdone is cleaned up.

This CL makes sure SudoG.next, SudoG.prev, and SudoG.waitlink
are cleaned up. I should have done this when I did the other two
fields; instead I wasted a week tracking down a leak they caused.

A dangling SudoG.waitlink can point into a sudogcache list that
has been "forgotten" in order to let the GC collect it, but that
dangling .waitlink keeps the list from being collected.
And then the list holding the SudoG with the dangling waitlink
can find itself in the same situation, and so on. We end up
with lists of lists of unusable SudoGs that are still linked into
the object graph and never collected (given the right mix of
non-trivial selects and non-channel synchronization).

More details in golang.org/issue/9110.

Fixes #9110.

LGTM=r
R=r
CC=dvyukov, golang-codereviews, iant, khr
https://golang.org/cl/177870043
2014-11-16 16:44:45 -05:00
Russ Cox
a22c11b995 runtime: fix line number in first stack frame in printed stack trace
Originally traceback was only used for printing the stack
when an unexpected signal came in. In that case, the
initial PC is taken from the signal and should be used
unaltered. For the callers, the PC is the return address,
which might be on the line after the call; we subtract 1
to get to the CALL instruction.

Traceback is now used for a variety of things, and for
almost all of those the initial PC is a return address,
whether from getcallerpc, or gp->sched.pc, or gp->syscallpc.
In those cases, we need to subtract 1 from this initial PC,
but the traceback code had a hard rule "never subtract 1
from the initial PC", left over from the signal handling days.

Change gentraceback to take a flag that specifies whether
we are tracing a trap.

Change traceback to default to "starting with a return PC",
which is the overwhelmingly common case.

Add tracebacktrap, like traceback but starting with a trap PC.

Use tracebacktrap in signal handlers.

Fixes #7690.

LGTM=iant, r
R=r, iant
CC=golang-codereviews
https://golang.org/cl/167810044
2014-10-29 15:14:24 -04:00
Russ Cox
6b54cc93d0 cmd/gc: fix internal compiler error in struct compare
Fixes #9006.

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/167800043
2014-10-28 23:22:46 -04:00
Russ Cox
5225854b74 cmd/gc: synthesize zeroed value for non-assignment context
CL 157910047 introduced code to turn a node representing
a zeroed composite literal into N, the nil Node* pointer
(which represents any zero, not the Go literal nil).

That's great for assignments like x = T{}, but it doesn't work
when T{} is used in a value context like T{}.v or x == T{}.
Fix those.

Should have no effect on performance; confirmed.
The deltas below are noise (compare ns/op):

benchmark                          old ns/op      new ns/op      delta
BenchmarkBinaryTree17              2902919192     2915228424     +0.42%
BenchmarkFannkuch11                2597417605     2630363685     +1.27%
BenchmarkFmtFprintfEmpty           73.7           74.8           +1.49%
BenchmarkFmtFprintfString          196            199            +1.53%
BenchmarkFmtFprintfInt             213            217            +1.88%
BenchmarkFmtFprintfIntInt          336            356            +5.95%
BenchmarkFmtFprintfPrefixedInt     289            294            +1.73%
BenchmarkFmtFprintfFloat           415            416            +0.24%
BenchmarkFmtManyArgs               1281           1271           -0.78%
BenchmarkGobDecode                 10271734       10307978       +0.35%
BenchmarkGobEncode                 8985021        9079442        +1.05%
BenchmarkGzip                      410233227      412266944      +0.50%
BenchmarkGunzip                    102114554      103272443      +1.13%
BenchmarkHTTPClientServer          45297          44993          -0.67%
BenchmarkJSONEncode                19499741       19498489       -0.01%
BenchmarkJSONDecode                76436733       74247497       -2.86%
BenchmarkMandelbrot200             4273814        4307292        +0.78%
BenchmarkGoParse                   4024594        4028937        +0.11%
BenchmarkRegexpMatchEasy0_32       131            135            +3.05%
BenchmarkRegexpMatchEasy0_1K       328            333            +1.52%
BenchmarkRegexpMatchEasy1_32       115            117            +1.74%
BenchmarkRegexpMatchEasy1_1K       931            948            +1.83%
BenchmarkRegexpMatchMedium_32      216            217            +0.46%
BenchmarkRegexpMatchMedium_1K      72669          72857          +0.26%
BenchmarkRegexpMatchHard_32        3818           3809           -0.24%
BenchmarkRegexpMatchHard_1K        121398         121945         +0.45%
BenchmarkRevcomp                   613996550      615145436      +0.19%
BenchmarkTemplate                  93678525       93267391       -0.44%
BenchmarkTimeParse                 414            411            -0.72%
BenchmarkTimeFormat                396            399            +0.76%

Fixes #8947.

LGTM=r
R=r, dave
CC=golang-codereviews
https://golang.org/cl/162130043
2014-10-24 10:27:39 -04:00
Russ Cox
93fcb92257 cmd/gc: disallow call of *T method using **T variable
This brings cmd/gc in line with the spec on this question.
It might break existing code, but that code was not conformant
with the spec.

Credit to Rémy for finding the broken code.

Fixes #6366.

LGTM=r
R=golang-codereviews, r
CC=adonovan, golang-codereviews, gri
https://golang.org/cl/129550043
2014-10-20 22:04:12 -04:00
Daniel Morsing
0edafefc36 cmd/gc: emit code for extern = <N>
https://golang.org/cl/152700045/ made it possible for struct literals assigned to globals to use <N> as the RHS. Normally, this is to zero out variables on first use. Because globals are already zero (or their linker initialized value), we just ignored this.

Now that <N> can occur from non-initialization code, we need to emit this code. We don't use <N> for initialization of globals any more, so this shouldn't cause any excessive zeroing.

Fixes #8961.

LGTM=rsc
R=golang-codereviews, rsc
CC=bradfitz, golang-codereviews
https://golang.org/cl/154540044
2014-10-20 15:59:10 +01:00
Chris Manghane
fe8f799ef7 cmd/gc: check for initialization cycles in method values
Fixes #7960.

LGTM=rsc
R=rsc
CC=golang-codereviews, gri
https://golang.org/cl/159800045
2014-10-14 19:12:10 -07:00
Chris Manghane
d83e43ccc6 test: add test for gccgo-specific issue 8079
LGTM=gri
R=gri
CC=golang-codereviews, iant
https://golang.org/cl/159850044
2014-10-13 12:33:45 -07:00
Russ Cox
454d1b0e8b cmd/gc: fix call order in array literal of slice literal of make chan
Fixes #8761.

LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews, r
https://golang.org/cl/144530045
2014-09-30 12:48:47 -04:00
Russ Cox
870f4e190c cmd/gc: emit error for out-of-bounds slice of constant string
Fixes #7200.

LGTM=gri, iant
R=golang-codereviews, gri, iant
CC=golang-codereviews, r
https://golang.org/cl/150020044
2014-09-25 13:24:43 -04:00
Russ Cox
52e9bcafe1 cmd/gc: print x++ (not x += 1) in errors about x++
Fixes #8311.

LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews, r
https://golang.org/cl/146270043
2014-09-25 13:13:02 -04:00
Russ Cox
53c66543e0 cmd/gc: avoid infinite recursion on invalid recursive type
Fixes #8507.

LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews, r
https://golang.org/cl/144560043
2014-09-25 13:08:37 -04:00
Russ Cox
43c4287b25 cmd/gc: fix import of package with var func returning _
Fixes #8280.

LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews, r
https://golang.org/cl/146240043
2014-09-24 16:53:34 -04:00
Russ Cox
8d61334dd5 cmd/gc: say 'non-constant array bound' instead of 'invalid array bound'
Fixes #8196.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/141510044
2014-09-16 10:21:54 -04:00
Rémy Oudompheng
e024ed5ca4 cmd/gc: don't walk static nodes generated by anylit.
During anylit run, nodes such as SLICEARR(statictmp, [:])
may be generated and are expected to be found unchanged by
gen_as_init.

In some walks (in particular walkselect), the statement
may be walked again and lowered to its usual form, leading to a
crash.

Fixes #8017.
Fixes #8024.
Fixes #8058.

LGTM=rsc
R=golang-codereviews, dvyukov, gobot, rsc
CC=golang-codereviews
https://golang.org/cl/112080043
2014-09-15 18:31:47 +02:00
Rémy Oudompheng
8d47b08255 cmd/gc: generate type alg after calling dowidth.
Previously it might happen before calling dowidth and
result in a compiler crash.

Fixes #8060.

LGTM=dvyukov, rsc
R=golang-codereviews, dvyukov, gobot, rsc
CC=golang-codereviews
https://golang.org/cl/110980044
2014-09-15 18:24:16 +02:00