1
0
mirror of https://github.com/golang/go synced 2024-10-03 13:31:21 -06:00
Commit Graph

1454 Commits

Author SHA1 Message Date
Daniel Morsing
c956dcdc54 cmd/gc: Reject parenthesised .(type) expressions.
Fixes #4470.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6949073
2012-12-22 17:36:10 +01:00
Russ Cox
e431398e09 undo CL 6938073 / 1542912cf09d
remove zerostack compiler experiment; will do at link time instead

««« original CL description
cmd/gc: add GOEXPERIMENT=zerostack to clear stack on function entry

This is expensive but it might be useful in cases where
people are suffering from false positives during garbage
collection and are willing to trade the CPU time for getting
rid of the false positives.

On the other hand it only eliminates false positives caused
by other function calls, not false positives caused by dead
temporaries stored in the current function call.

The 5g/6g/8g changes were pulled out of the history, from
the last time we needed to do this (to work around a goto bug).
The code in go.h, lex.c, pgen.c is new but tiny.

R=ken2
CC=golang-dev
https://golang.org/cl/6938073
»»»

R=ken2
CC=golang-dev
https://golang.org/cl/7002051
2012-12-22 11:18:04 -05:00
Russ Cox
407d0c5ab7 cmd/gc: fix error line in switch expr eval
Fixes #4562.

R=ken2
CC=golang-dev
https://golang.org/cl/7008044
2012-12-22 10:01:15 -05:00
Rémy Oudompheng
64eb7749bc cmd/gc: mapassign2 doesn't exist anymore.
R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/6997043
2012-12-21 20:39:30 +01:00
Rémy Oudompheng
1dcf658f6d cmd/gc: remove an incorrect assertion in escape analysis.
A fatal error used to happen when escassign-ing a multiple
function return to a single node. However, the situation
naturally appears when using "go f(g())" or "defer f(g())",
because g() is escassign-ed to sink.

Fixes #4529.

R=golang-dev, lvd, minux.ma, rsc
CC=golang-dev
https://golang.org/cl/6920060
2012-12-20 23:27:28 +01:00
Russ Cox
b7603cfc2c cmd/gc: add GOEXPERIMENT=zerostack to clear stack on function entry
This is expensive but it might be useful in cases where
people are suffering from false positives during garbage
collection and are willing to trade the CPU time for getting
rid of the false positives.

On the other hand it only eliminates false positives caused
by other function calls, not false positives caused by dead
temporaries stored in the current function call.

The 5g/6g/8g changes were pulled out of the history, from
the last time we needed to do this (to work around a goto bug).
The code in go.h, lex.c, pgen.c is new but tiny.

R=ken2
CC=golang-dev
https://golang.org/cl/6938073
2012-12-17 14:32:26 -05:00
Dmitriy Vyukov
ca4b868e9a cmd/gc: racewalk: fix compiler crash
The code:
func main() {
        v := make([]int64, 10)
        i := 1
        _ = v[(i*4)/3]
}
crashes compiler with:

Program received signal SIGSEGV, Segmentation fault.
0x000000000043c274 in walkexpr (np=0x7fffffffc9b8, init=0x0) at src/cmd/gc/walk.c:587
587			*init = concat(*init, n->ninit);
(gdb) bt
#0  0x000000000043c274 in walkexpr (np=0x7fffffffc9b8, init=0x0) at src/cmd/gc/walk.c:587
#1  0x0000000000432d15 in copyexpr (n=0x7ffff7f69a48, t=<optimized out>, init=0x0) at src/cmd/gc/subr.c:2020
#2  0x000000000043f281 in walkdiv (init=0x0, np=0x7fffffffca70) at src/cmd/gc/walk.c:2901
#3  walkexpr (np=0x7ffff7f69760, init=0x0) at src/cmd/gc/walk.c:956
#4  0x000000000043d801 in walkexpr (np=0x7ffff7f69bc0, init=0x0) at src/cmd/gc/walk.c:988
#5  0x000000000043cc9b in walkexpr (np=0x7ffff7f69d38, init=0x0) at src/cmd/gc/walk.c:1068
#6  0x000000000043c50b in walkexpr (np=0x7ffff7f69f50, init=0x0) at src/cmd/gc/walk.c:879
#7  0x000000000043c50b in walkexpr (np=0x7ffff7f6a0c8, init=0x0) at src/cmd/gc/walk.c:879
#8  0x0000000000440a53 in walkexprlist (l=0x7ffff7f6a0c8, init=0x0) at src/cmd/gc/walk.c:357
#9  0x000000000043d0bf in walkexpr (np=0x7fffffffd318, init=0x0) at src/cmd/gc/walk.c:566
#10 0x00000000004402bf in vmkcall (fn=<optimized out>, t=0x0, init=0x0, va=0x7fffffffd368) at src/cmd/gc/walk.c:2275
#11 0x000000000044059a in mkcall (name=<optimized out>, t=0x0, init=0x0) at src/cmd/gc/walk.c:2287
#12 0x000000000042862b in callinstr (np=0x7fffffffd4c8, init=0x7fffffffd568, wr=0, skip=<optimized out>) at src/cmd/gc/racewalk.c:478
#13 0x00000000004288b7 in racewalknode (np=0x7ffff7f68108, init=0x7fffffffd568, wr=0, skip=0) at src/cmd/gc/racewalk.c:287
#14 0x0000000000428781 in racewalknode (np=0x7ffff7f65840, init=0x7fffffffd568, wr=0, skip=0) at src/cmd/gc/racewalk.c:302
#15 0x0000000000428abd in racewalklist (l=0x7ffff7f65840, init=0x0) at src/cmd/gc/racewalk.c:97
#16 0x0000000000428d0b in racewalk (fn=0x7ffff7f5f010) at src/cmd/gc/racewalk.c:63
#17 0x0000000000402b9c in compile (fn=0x7ffff7f5f010) at src/cmd/6g/../gc/pgen.c:67
#18 0x0000000000419f86 in funccompile (n=0x7ffff7f5f010, isclosure=0) at src/cmd/gc/dcl.c:1414
#19 0x0000000000424161 in p9main (argc=<optimized out>, argv=<optimized out>) at src/cmd/gc/lex.c:431
#20 0x0000000000401739 in main (argc=<optimized out>, argv=<optimized out>) at src/lib9/main.c:35

The problem is nil init passed to mkcall().

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6940045
2012-12-17 12:55:41 +04:00
Rémy Oudompheng
1947960a6f cmd/gc: fix defaultlit of shifts used in interface context.
Fixes #4545.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6937058
2012-12-15 19:37:59 +01:00
Daniel Morsing
bf59aafddc cmd/gc: Give better line numbers for errors in composite literals.
Credit to Russ for suggesting this fix.

Fixes #3925.

R=golang-dev, franciscossouza, rsc
CC=golang-dev
https://golang.org/cl/6920051
2012-12-12 16:43:54 +01:00
Rémy Oudompheng
11999306df cmd/gc: don't import the same package multiple times.
Implementation suggested by DMorsing.

R=golang-dev, dave, daniel.morsing, rsc
CC=golang-dev
https://golang.org/cl/6903059
2012-12-12 08:47:09 +01:00
Miquel Sabaté Solà
0dd0e1ad0c cmd/gc: merge casep and casee labels
The code inside the casee and casep labels can perfectly be merged since
they essentially do the same. The character to be stored where cp points is
just the character contained by the c variable.

R=golang-dev, dave, rsc
CC=golang-dev
https://golang.org/cl/6845112
2012-12-11 12:23:04 -05:00
Daniel Morsing
0d22573f6e cmd/gc: remove bad check for BADWIDTH
This check for BADWIDTH might happen while in defercheckwidth, making it raise errors for non-erroneous situations.

Fixes #4495.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6927043
2012-12-11 17:36:10 +01:00
Rémy Oudompheng
10d14b63c2 cmd/gc: prevent ngotype from allocating.
R=golang-dev, dave, rsc
CC=golang-dev
https://golang.org/cl/6904061
2012-12-09 19:27:23 +01:00
Rémy Oudompheng
561edbd63c cmd/gc: do not export useless private symbols.
Fixes #4252.

R=rsc, golang-dev, mirtchovski, daniel.morsing, dave, lvd
CC=golang-dev
https://golang.org/cl/6856126
2012-12-08 14:43:00 +01:00
Rémy Oudompheng
9146ac14ee cmd/gc: do not overflow parser stack on a long chain of else if.
Fixes #2615.

R=dave, minux.ma, iant, daniel.morsing, rsc
CC=golang-dev
https://golang.org/cl/6847078
2012-12-06 08:09:17 +01:00
Ian Lance Taylor
08918ba438 gc: avoid meaningless constant overflow error for inverted slice range
Used to say:

issue4251.go:12: inverted slice range
issue4251.go:12: constant -1 overflows uint64
issue4251.go:16: inverted slice range
issue4251.go:16: constant -1 overflows uint64
issue4251.go:20: inverted slice range
issue4251.go:20: constant -1 overflows uint64

With this patch, only gives the "inverted slice range" errors.

R=golang-dev, daniel.morsing
CC=golang-dev
https://golang.org/cl/6871058
2012-12-05 15:46:45 -08:00
Rémy Oudompheng
bcea0dd1d0 cmd/gc: fix inlining internal error with T.Method calls.
The compiler was confused when inlining a T.Method(f()) call
where f returns multiple values: support for this was marked
as TODO.

Variadic calls are not supported but are not inlined either.
Add a test preventively for that case.

Fixes #4167.

R=golang-dev, rsc, lvd
CC=golang-dev
https://golang.org/cl/6871043
2012-12-03 13:39:40 +01:00
Dmitriy Vyukov
c3c107f67c cmd/gc: racewalk: collect stack traces in sync and sync/atomic
W/o this change stack traces do not show from where sync.Once()
or atomic.XXX was called.
This change add funcenter/exit instrumentation to sync/sync.atomic
packages.

R=golang-dev
CC=golang-dev
https://golang.org/cl/6854112
2012-11-30 10:27:43 +04:00
Rémy Oudompheng
4cc9de9147 cmd/gc: add division rewrite to walk pass.
This allows 5g and 8g to benefit from the rewrite as shifts
or magic multiplies. The 64-bit arithmetic is not handled there,
and left in 6g.

Update #2230.

R=golang-dev, dave, mtj, iant, rsc
CC=golang-dev
https://golang.org/cl/6819123
2012-11-26 23:45:22 +01:00
Daniel Morsing
5188c0b59c cmd/gc: Make sure bools lose idealness when used with logical operators.
Bools from comparisons can be assigned to all bool types, but this idealness would propagate through logical operators when the result should have been lowered to a non-ideal form.

Fixes #3924.

R=golang-dev, remyoudompheng, r, rsc, mtj
CC=golang-dev
https://golang.org/cl/6855061
2012-11-26 22:23:13 +01:00
Dmitriy Vyukov
7f08218050 cnd/gc: fix build
R=golang-dev
CC=golang-dev
https://golang.org/cl/6856097
2012-11-26 22:14:43 +04:00
Dmitriy Vyukov
db8d7a292d cmd/go: racewalk: fix nested struct handling
Fixes #4424.
Fixes #4425.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6849093
2012-11-26 22:11:05 +04:00
Shenghou Ma
7c295f3f0c cmd/gc: fix invalid indirect error at statement level
Fixes #4429.

R=golang-dev, remyoudompheng, daniel.morsing, rsc
CC=golang-dev
https://golang.org/cl/6850097
2012-11-27 01:46:54 +08:00
Joel Sing
5da5e8e02f cmd/gc: check malloc return value
Check the return value from malloc - do not assume that we were
allocated memory just because we asked for it.

Update #4415.

R=minux.ma, daniel.morsing, remyoudompheng, rsc
CC=golang-dev
https://golang.org/cl/6782100
2012-11-26 22:03:31 +11:00
Robert Griesemer
8f3b703323 cmd/gc: complain about invalid whitespace chars
Fixes #4405.

R=rsc, bradfitz
CC=golang-dev
https://golang.org/cl/6855060
2012-11-19 09:09:04 -08:00
Dmitriy Vyukov
89bfddbf67 cmd/gc: racewalk: handle OEFACE/OCONVIFACE
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6821096
2012-11-14 16:30:53 +04:00
Dmitriy Vyukov
96833d3a25 cmd/gc: racewalk: fix instrumentation of structs
+ do not instrument go.itab.*

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6819106
2012-11-14 16:26:00 +04:00
Russ Cox
1120982590 reflect: add ArrayOf, ChanOf, MapOf, SliceOf
In order to add these, we need to be able to find references
to such types that already exist in the binary. To do that, introduce
a new linker section holding a list of the types corresponding to
arrays, chans, maps, and slices.

To offset the storage cost of this list, and to simplify the code,
remove the interface{} header from the representation of a
runtime type. It was used in early versions of the code but was
made obsolete by the kind field: a switch on kind is more efficient
than a type switch.

In the godoc binary, removing the interface{} header cuts two
words from each of about 10,000 types. Adding back the list of pointers
to array, chan, map, and slice types reintroduces one word for
each of about 500 types. On a 64-bit machine, then, this CL *removes*
a net 156 kB of read-only data from the binary.

This CL does not include the needed support for precise garbage
collection. I have created issue 4375 to track that.

This CL also does not set the 'algorithm' - specifically the equality
and copy functions - for a new array correctly, so I have unexported
ArrayOf for now. That is also part of issue 4375.

Fixes #2339.

R=r, remyoudompheng, mirtchovski, iant
CC=golang-dev
https://golang.org/cl/6572043
2012-11-13 13:06:29 -05:00
Rémy Oudompheng
0a47d2eff1 cmd/gc: fix typos in clearslim.
Fixes build failure.

R=golang-dev, bradfitz, dave
CC=golang-dev
https://golang.org/cl/6847043
2012-11-13 07:08:29 +01:00
Rémy Oudompheng
16072c7497 cmd/6g: extend componentgen to small arrays and structs.
Fixes #4092.

R=golang-dev, dave, rsc
CC=golang-dev
https://golang.org/cl/6819083
2012-11-13 00:08:04 +01:00
Russ Cox
761830f481 cmd/gc: fix export of inlined function body with type guard
When exporting a body containing
        x, ok := v.(Type)

the definition for Type was not being included, so when the body
was actually used, it would cause an "unknown type" compiler error.

Fixes #4370.

R=ken2
CC=golang-dev
https://golang.org/cl/6827064
2012-11-08 16:07:05 -05:00
Ian Lance Taylor
e3977f0d3a cmd/gc: warn about slice indexes larger than int in typecheck pass
Fixes GOARCH=386 build.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/6810098
2012-11-07 17:34:06 -08:00
Rémy Oudompheng
c208a3a263 cmd/gc: fix internal compiler error with broken structs.
Fixes #4359.

R=golang-dev, daniel.morsing, rsc
CC=golang-dev
https://golang.org/cl/6834043
2012-11-07 23:09:01 +01:00
Russ Cox
71282131a1 cmd/gc: fix escape analysis bug
The code assumed that the only choices were EscNone, EscScope, and EscHeap,
so that it makes sense to set EscScope only if the current setting is EscNone.
Now that we have the many variants of EscReturn, this logic is false, and it was
causing important EscScopes to be ignored in favor of EscReturn.

Fixes #4360.

R=ken2
CC=golang-dev, lvd
https://golang.org/cl/6816103
2012-11-07 15:15:21 -05:00
Russ Cox
cb856adea9 cmd/gc: annotate local variables with unique ids for inlining
Avoids problems with local declarations shadowing other names.
We write a more explicit form than the incoming program, so there
may be additional type annotations. For example:

        int := "hello"
        j := 2

would normally turn into

        var int string = "hello"
        var j int = 2

but the int variable shadows the int type in the second line.

This CL marks all local variables with a per-function sequence number,
so that this would instead be:

        var int·1 string = "hello"
        var j·2 int = 2

Fixes #4326.

R=ken2
CC=golang-dev
https://golang.org/cl/6816100
2012-11-07 09:59:19 -05:00
Russ Cox
c6f363b22a cmd/gc: fix go:nointerface export comment
R=ken
CC=golang-dev
https://golang.org/cl/6815073
2012-11-07 09:14:21 -05:00
Dmitriy Vyukov
a3a7244779 cmd/gc: racewalk: instrument returnsfromheap params
Fixes #4307.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6822073
2012-11-07 12:10:35 +04:00
Dmitriy Vyukov
abb313f8c8 cmd/gc: racewalk: do not double function calls
Current racewalk transformation looks like:
x := <-makeChan().c
\/\/\/\/\/\/\/\/\/
runtime.raceread(&makeChan().c)
x := <-makeChan().c
and so makeChan() is called twice.
With this CL the transformation looks like:
x := <-makeChan().c
\/\/\/\/\/\/\/\/\/
chan *tmp = &(makeChan().c)
raceread(&*tmp)
x := <-(*tmp)
Fixes #4245.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6822075
2012-11-07 12:06:27 +04:00
Dmitriy Vyukov
703043c8dc cmd/gc: refactor racewalk
It is refactoring towards generic walk
+ it handles mode nodes.
Partially fixes 4228 issue.

R=golang-dev, lvd, rsc
CC=golang-dev
https://golang.org/cl/6775098
2012-11-07 12:01:31 +04:00
Daniel Morsing
d098bffd84 cmd/gc, runtime: avoid unnecessary copy on type assertion.
When the first result of a type assertion is blank, the compiler would still copy out a potentially large non-interface type.

Fixes #1021.

R=golang-dev, bradfitz, rsc
CC=golang-dev
https://golang.org/cl/6812079
2012-11-06 20:40:40 +01:00
Ian Lance Taylor
2355409988 cmd/gc: don't require that slice index constants be small ints
The test for this is test/index.go, which is not run by
default.

R=remyoudompheng, rsc
CC=golang-dev
https://golang.org/cl/6812089
2012-11-06 11:36:59 -08:00
Ian Lance Taylor
72bf3bc176 cmd/gc: check for array bounds overflow in slice expression
The test for this is test/index.go, which is not run by
default.  That test does not currently pass even after this is
applied, due to issue 4348.

Fixes #4344.

R=golang-dev, daniel.morsing, rsc
CC=golang-dev
https://golang.org/cl/6815085
2012-11-06 11:35:58 -08:00
Rémy Oudompheng
c46f1f40da cmd/gc: instrument blocks for race detection.
It happens that blocks are used for function calls in a
quite low-level way so they cannot be instrumented as
usual.

Blocks are also used for inlined functions.

R=golang-dev, rsc, dvyukov
CC=golang-dev
https://golang.org/cl/6821068
2012-11-03 00:11:06 +01:00
Rémy Oudompheng
0b2353edcb cmd/5g, cmd/6g: fix out of registers with array indexing.
Compiling expressions like:
    s[s[s[s[s[s[s[s[s[s[s[s[i]]]]]]]]]]]]
make 5g and 6g run out of registers. Such expressions can arise
if a slice is used to represent a permutation and the user wants
to iterate it.

This is due to the usual problem of allocating registers before
going down the expression tree, instead of allocating them in a
postfix way.

The functions cgenr and agenr (that generate a value to a newly
allocated register instead of an existing location), are either
introduced or modified when they already existed to allocate
the new register as late as possible, and sudoaddable is disabled
for OINDEX nodes so that igen/agenr is used instead.

Update #4207.

R=dave, daniel.morsing, rsc
CC=golang-dev
https://golang.org/cl/6733055
2012-11-02 07:50:59 +01:00
Russ Cox
3d40062c68 cmd/gc, cmd/ld: struct field tracking
This is an experiment in static analysis of Go programs
to understand which struct fields a program might use.
It is not part of the Go language specification, it must
be enabled explicitly when building the toolchain,
and it may be removed at any time.

After building the toolchain with GOEXPERIMENT=fieldtrack,
a specific field can be marked for tracking by including
`go:"track"` in the field tag:

        package pkg

        type T struct {
                F int `go:"track"`
                G int // untracked
        }

To simplify usage, only named struct types can have
tracked fields, and only exported fields can be tracked.

The implementation works by making each function begin
with a sequence of no-op USEFIELD instructions declaring
which tracked fields are accessed by a specific function.
After the linker's dead code elimination removes unused
functions, the fields referred to by the remaining
USEFIELD instructions are the ones reported as used by
the binary.

The -k option to the linker specifies the fully qualified
symbol name (such as my/pkg.list) of a string variable that
should be initialized with the field tracking information
for the program. The field tracking string is a sequence
of lines, each terminated by a \n and describing a single
tracked field referred to by the program. Each line is made
up of one or more tab-separated fields. The first field is
the name of the tracked field, fully qualified, as in
"my/pkg.T.F". Subsequent fields give a shortest path of
reverse references from that field to a global variable or
function, corresponding to one way in which the program
might reach that field.

A common source of false positives in field tracking is
types with large method sets, because a reference to the
type descriptor carries with it references to all methods.
To address this problem, the CL also introduces a comment
annotation

        //go:nointerface

that marks an upcoming method declaration as unavailable
for use in satisfying interfaces, both statically and
dynamically. Such a method is also invisible to package
reflect.

Again, all of this is disabled by default. It only turns on
if you have GOEXPERIMENT=fieldtrack set during make.bash.

R=iant, ken
CC=golang-dev
https://golang.org/cl/6749064
2012-11-02 00:17:21 -04:00
Dmitriy Vyukov
936498e5dc cmd/gc: fix build
R=golang-dev
CC=golang-dev
https://golang.org/cl/6826047
2012-11-01 22:59:53 +04:00
Dmitriy Vyukov
de10a23db1 cmd/gc: racewalk: fix a bunch of minor issues
1. Prepend racefuncenter() to fn->enter -- fn->enter can contain new() calls,
and we want them to be in the scope of the function.
2. Dump fn->enter and fn->exit.
3. Add TODO that OTYPESW expression can contain interesting memory accesses.
4. Ignore only _ names instead of all names starting with _.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6822048
2012-11-01 22:56:04 +04:00
Rémy Oudompheng
ce287933d6 cmd/gc, runtime: pass PC directly to racefuncenter.
go test -race -run none -bench . encoding/json
benchmark                      old ns/op    new ns/op    delta
BenchmarkCodeEncoder          3207689000   1716149000  -46.50%
BenchmarkCodeMarshal          3206761000   1715677000  -46.50%
BenchmarkCodeDecoder          8647304000   4482709000  -48.16%
BenchmarkCodeUnmarshal        8032217000   3451248000  -57.03%
BenchmarkCodeUnmarshalReuse   8016722000   3480502000  -56.58%
BenchmarkSkipValue           10340453000   4560313000  -55.90%

benchmark                       old MB/s     new MB/s  speedup
BenchmarkCodeEncoder                0.60         1.13    1.88x
BenchmarkCodeMarshal                0.61         1.13    1.85x
BenchmarkCodeDecoder                0.22         0.43    1.95x
BenchmarkCodeUnmarshal              0.24         0.56    2.33x
BenchmarkCodeUnmarshalReuse         0.24         0.56    2.33x
BenchmarkSkipValue                  0.19         0.44    2.32x

Fixes #4248.

R=dvyukov, golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6815066
2012-11-01 19:43:29 +01:00
Dmitriy Vyukov
b11f85a8aa cmd/gc: racewalk: fix instrumentation of ninit lists
The idea is to (1) process ninit of all nodes,
and (2) put instrumentation of ninit into the nodes themselves (not the top-level statement ninit).
Fixes #4304.

R=golang-dev, rsc
CC=golang-dev, lvd
https://golang.org/cl/6818049
2012-11-01 22:11:12 +04:00
Rémy Oudompheng
8d95245d0d cmd/gc: fix incomplete export data when inlining with local variables.
When local declarations needed unexported types, these could
be missing in the export data.

Fixes build with -gcflags -lll, except for exp/gotype.

R=golang-dev, rsc, lvd
CC=golang-dev
https://golang.org/cl/6813067
2012-11-01 19:06:52 +01:00
Rémy Oudompheng
76500b14a1 cmd/gc: fix inlining bug with local variables.
Fixes #4323.

R=rsc, lvd, golang-dev
CC=golang-dev
https://golang.org/cl/6815061
2012-11-01 18:59:32 +01:00
Daniel Morsing
85d60a727c cmd/gc: do simple bounds checking of constant indices/slices in typecheck.
This should make the compiler emit errors specific to the bounds checking instead of overflow errors on the underlying types.

Updates #4232.

R=rsc
CC=golang-dev
https://golang.org/cl/6783054
2012-11-01 18:45:19 +01:00
Russ Cox
e4cef96be6 cmd/gc: avoid %#x of 0
Plan 9 and Go's lib9/fmt disagree on whether %#x includes the 0x prefix
when printing 0, because ANSI C gave bad advice long ago.

Avoiding that case makes binaries compiled on different systems compatible.

R=ken2
CC=akumar, golang-dev
https://golang.org/cl/6814066
2012-11-01 12:55:21 -04:00
Luuk van Dijk
530147e870 cmd/gc: inlining functions with local variables
- make sure dclcontext == PAUTO only in function bodies
- introduce PDISCARD to discard declarations in bodies of repeated imports
- skip printing initializing OAS'es in export mode, assuming they only occur after ODCL's
- remove ODCL and the initializing OAS from inl.c:ishairy
- fix confused use of ->typecheck in typecheckinl: it's about the ->inl, not about the fn.
- debuging aids: print ntype on ONAMEs too and -Emm instead of -Ell.

fixes #2812

R=rsc
CC=golang-dev
https://golang.org/cl/6800043
2012-10-29 13:55:27 +01:00
Luuk van Dijk
507fcf37d2 cmd/gc: escape analysis to track flow of in to out parameters.
includes step 0: synthesize outparams, from 6600044
includes step 1,2: give outparams loopdepth 0 and verify unchanged results
         generate esc:$mask tags, but still tie to sink if a param has mask != 0
from 6610054

adds final steps:
- have esccall generate n->escretval, a list of nodes the function results flow to
- use these in esccall and ORETURN/OAS2FUNC/and f(g())
- only tie parameters to sink if tag is absent, otherwise according to mask, tie them to escretval

R=rsc, bradfitz
CC=dave, gobot, golang-dev, iant, rsc
https://golang.org/cl/6741044
2012-10-29 13:38:21 +01:00
Russ Cox
80dbe74360 cmd/gc, cmd/ld: use go.weak instead of weak as the weak symbol prefix
Also defend our symbol prefixes (now just "go" and "type")
from use as import paths.

Fixes #4257.

R=ken2
CC=golang-dev
https://golang.org/cl/6744072
2012-10-23 11:16:08 -04:00
Daniel Morsing
48af64b295 cmd/gc: Mark use of builtin functions as calls.
Fixes #4097.

R=rsc
CC=golang-dev, gri
https://golang.org/cl/6749059
2012-10-22 19:14:30 +02:00
Luuk van Dijk
75692424d2 cmd/gc: escape analysis to track flow of in to out parameters.
includes step 0: synthesize outparams, from 6600044
step 1: give outparams loopdepth 0 and verify unchanged results
step 2: generate esc:$mask tags, but still tie to sink if a param has mask != 0
next step: use in esccall (and ORETURN with implicit OAS2FUNC) to avoid tying to sink

R=rsc
CC=golang-dev
https://golang.org/cl/6610054
2012-10-22 10:18:17 +02:00
Luuk van Dijk
976ca1a47d cmd/gc: track parameter flow, step 0: synthesize name nodes for anonymous PPARAMOUTs without breaking anything.
further work on parameter flow tracking for escape analysis depends on this.

R=rsc
CC=golang-dev
https://golang.org/cl/6600044
2012-10-22 10:09:52 +02:00
Luuk van Dijk
e7f89fcb1c cmd/gc: fix strict tree property for AST for OAS2RECV nodes.
in typecheck and walk, conversion from OAS2RECV to OAS2
and to OSELRECV2 duplicated the ->rlist->n to ->right
thereby destroying the strict tree-ness of the AST (up to
ONAMES) of course.  Several recursions in esc.c and inl.c
and probably elsewhere assume nodes of the tree aren't duplicated.
rather than defensively code around this, i'd rather assert
these cases away and fix their cause.

(this was tripped in 6741044)

R=rsc
CC=golang-dev
https://golang.org/cl/6750043
2012-10-22 10:01:14 +02:00
Rémy Oudompheng
319131f295 cmd/gc: fix inlining bug for composite literals in if statements.
Fixes #4230.

R=golang-dev, rsc
CC=golang-dev, remy
https://golang.org/cl/6640056
2012-10-22 08:38:23 +02:00
Russ Cox
922c0b4755 cmd/gc: rebuild builtin.c
Was not in sync with runtime.go, but the diffs
didn't really matter, so nothing broke.

R=ken2
CC=golang-dev
https://golang.org/cl/6733057
2012-10-21 17:15:56 -04:00
Daniel Morsing
d7a3407e3d cmd/gc: fix confusing error when using variable as type.
Fixes #3783.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6737053
2012-10-21 20:50:31 +02:00
Daniel Morsing
a7a3fe7238 cmd/gc: Friendlier errors on oversized arrays.
Someone new to the language may not know the connection between ints and arrays, which was the only thing that the previous error told you anything about.

Fixes #4256.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6739048
2012-10-21 19:22:51 +02:00
Rémy Oudompheng
a4682348c2 cmd/gc: don't squash complex literals when inlining.
Since this patch changes the way complex literals are written
in export data, there are a few other glitches.

Fixes #4159.

R=golang-dev, rsc
CC=golang-dev, remy
https://golang.org/cl/6674047
2012-10-17 20:33:44 +02:00
Dmitriy Vyukov
21b2ce724a cmd/gc: fix compiler crash during race instrumentation
The compiler is crashing on the following code:

type TypeID int
func (t *TypeID) encodeType(x int) (tt TypeID, err error) {
        switch x {
        case 0:
                return t.encodeType(x * x)
        }
        return 0, nil
}
The pass marks "return struct" {tt TypeID, err error} as used,
and this causes internal check failure.
I've added the test to:
https://golang.org/cl/6525052/diff/7020/src/pkg/runtime/race/regression_test.go

R=golang-dev, minux.ma, rsc
CC=golang-dev
https://golang.org/cl/6611049
2012-10-10 18:09:23 +04:00
Russ Cox
d749783f70 cmd/gc: skip over reported BOMs
This keeps the BOM runes from causing other errors.

R=golang-dev, remyoudompheng
CC=golang-dev
https://golang.org/cl/6625062
2012-10-07 16:35:45 -04:00
Rémy Oudompheng
caff439820 cmd/gc: more graceful handling of invalid fields in widstruct.
The protection against segfaults does not completely solve
crashes and breaks test/fixedbugs/bug365.go

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6615058
2012-10-07 21:46:10 +02:00
Russ Cox
54191126e4 cmd/gc: avoid crash in %N print
R=ken2
CC=golang-dev
https://golang.org/cl/6609052
2012-10-07 15:35:01 -04:00
Rémy Oudompheng
892fa3ae6c cmd/gc: replace "typechecking loop" by nicer errors in some cases.
For issue 3757:
BEFORE:  test/fixedbugs/bug463.go:12: typechecking loop involving a
             test/fixedbugs/bug463.go:12 a
             test/fixedbugs/bug463.go:12 <node DCLCONST>
AFTER:   test/fixedbugs/bug463.go:12: constant definition loop
             test/fixedbugs/bug463.go:12: a uses a

For issue 3937:
BEFORE: test/fixedbugs/bug464.go:12: typechecking loop involving foo
            test/fixedbugs/bug464.go:12 <T>
            test/fixedbugs/bug464.go:12 foo
            test/fixedbugs/bug464.go:12 <node DCLFUNC>
AFTER:  test/fixedbugs/bug464.go:12: foo is not a type

Fixes #3757.
Fixes #3937.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6614058
2012-10-07 17:35:21 +02:00
Daniel Morsing
87c35d8df1 cmd/gc: Don't accept qualified names as literal keys
Fixes #4067.

R=golang-dev, minux.ma, dave, rsc
CC=golang-dev
https://golang.org/cl/6622056
2012-10-07 16:47:53 +02:00
Shenghou Ma
9224b4c873 cmd/gc: fix output filename generation on Windows
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6610060
2012-10-07 14:14:46 +08:00
Akshat Kumar
51e8fe5b1b cmd/gc: don't dereference a nil Type pointer in widstruct
The nil dereference in the next few lines doesn't seem
to cause a segmentation fault on Unix, but does seem
to halt the Go compiler.

The following is a test case:

>>>
package main

func mine(int b) int {
        return b + 2
}

func main() {
        mine()

        c = mine()
}
<<<

Without this change only the following is caught:

typecheck.go:3: undefined: b
typecheck.go:4: undefined: b

with it, we catch all the errors:

typecheck.go:3: undefined: b
typecheck.go:4: undefined: b
typecheck.go:10: undefined: c
typecheck.go:10: cannot assign to c .

R=rsc, minux.ma
CC=golang-dev
https://golang.org/cl/6542060
2012-10-07 14:11:59 +08:00
Daniel Morsing
a45777fe99 cmd/gc: Don't export embedded builtins
Fixes #4124.

R=golang-dev, dave, minux.ma, remyoudompheng, rsc
CC=golang-dev
https://golang.org/cl/6543057
2012-10-07 06:53:57 +02:00
Rémy Oudompheng
0b2ca9e62f cmd/gc: avoid clobbering the AST in cgen_callmeth.
It confused the detection of init loops when involving
method calls.

Fixes #3890.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6620067
2012-10-07 00:52:40 +02:00
Rémy Oudompheng
94acfde22e cmd/gc: make rnd() more 64-bit-friendly.
Fixes #4200.

R=golang-dev, dave, rsc
CC=golang-dev
https://golang.org/cl/6619057
2012-10-07 00:29:55 +02:00
Dmitriy Vyukov
041fc8bf96 race: gc changes
This is the first part of a bigger change that adds data race detection feature:
https://golang.org/cl/6456044
This change makes gc compiler instrument memory accesses when supplied with -b flag.

R=rsc, nigeltao, lvd
CC=golang-dev
https://golang.org/cl/6497074
2012-10-02 10:05:46 +04:00
Luuk van Dijk
78ba449a3c cmd/gc: Missing break in esc switch.
R=rsc
CC=golang-dev
https://golang.org/cl/6594053
2012-10-01 16:33:06 +02:00
Shenghou Ma
9a3bc51c81 test/fixedbugs/bug454.go: add a test for CL 6564052
Also mention that ignoring second blank identifier of range is required by the spec in the code.

   Fixes #4173.

R=daniel.morsing, remyoudompheng, r
CC=golang-dev
https://golang.org/cl/6594043
2012-09-29 23:23:56 +08:00
Daniel Morsing
7936ab58f7 cmd/gc: Don't calculate second value in range if it is blank.
Low hanging fruit optimization. Will remove an expensive copy if the range variable is an array.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6564052
2012-09-26 21:10:29 +02:00
Rémy Oudompheng
f4e76d5e02 cmd/6g, cmd/8g: add OINDREG, ODOT, ODOTPTR cases to igen.
Apart from reducing the number of LEAL/LEAQ instructions by about
30%, it gives 8g easier registerization in several cases,
for example in strconv. Performance with 6g is not affected.

Before (386):
src/pkg/strconv/decimal.go:22   TEXT  (*decimal).String+0(SB),$240-12
src/pkg/strconv/extfloat.go:540 TEXT  (*extFloat).ShortestDecimal+0(SB),$584-20

After (386):
src/pkg/strconv/decimal.go:22   TEXT  (*decimal).String+0(SB),$196-12
src/pkg/strconv/extfloat.go:540 TEXT  (*extFloat).ShortestDecimal+0(SB),$420-20

Benchmarks with GOARCH=386 (on a Core 2).

benchmark                 old ns/op    new ns/op    delta
BenchmarkBinaryTree17    7110191000   7079644000   -0.43%
BenchmarkFannkuch11      7769274000   7766514000   -0.04%
BenchmarkGobDecode         33454820     34755400   +3.89%
BenchmarkGobEncode         11675710     11007050   -5.73%
BenchmarkGzip            2013519000   1593855000  -20.84%
BenchmarkGunzip           253368200    242667600   -4.22%
BenchmarkJSONEncode       152443900    120763400  -20.78%
BenchmarkJSONDecode       304112800    247461800  -18.63%
BenchmarkMandelbrot200     29245520     29240490   -0.02%
BenchmarkParse              8484105      8088660   -4.66%
BenchmarkRevcomp         2695688000   2841263000   +5.40%
BenchmarkTemplate         363759800    277271200  -23.78%

benchmark                       old ns/op    new ns/op    delta
BenchmarkAtof64Decimal                127          129   +1.57%
BenchmarkAtof64Float                  166          164   -1.20%
BenchmarkAtof64FloatExp               308          300   -2.60%
BenchmarkAtof64Big                    584          571   -2.23%
BenchmarkAppendFloatDecimal           440          430   -2.27%
BenchmarkAppendFloat                  995          776  -22.01%
BenchmarkAppendFloatExp               897          746  -16.83%
BenchmarkAppendFloatNegExp            900          752  -16.44%
BenchmarkAppendFloatBig              1528         1228  -19.63%
BenchmarkAppendFloat32Integer         443          453   +2.26%
BenchmarkAppendFloat32ExactFraction   812          661  -18.60%
BenchmarkAppendFloat32Point          1002          773  -22.85%
BenchmarkAppendFloat32Exp             858          725  -15.50%
BenchmarkAppendFloat32NegExp          848          728  -14.15%
BenchmarkAppendFloat64Fixed1          447          431   -3.58%
BenchmarkAppendFloat64Fixed2          480          462   -3.75%
BenchmarkAppendFloat64Fixed3          461          457   -0.87%
BenchmarkAppendFloat64Fixed4          509          484   -4.91%

Update #1914.

R=rsc, nigeltao
CC=golang-dev, remy
https://golang.org/cl/6494107
2012-09-24 23:07:44 +02:00
Russ Cox
54af752865 cmd/gc: fix escape analysis bug
Was not handling &x.y[0] and &x.y.z correctly where
y is an array or struct-valued field (not a pointer).

R=ken2
CC=golang-dev
https://golang.org/cl/6551059
2012-09-24 15:53:12 -04:00
Russ Cox
650160e36a cmd/gc: prepare for 64-bit ints
This CL makes the compiler understand that the type of
the len or cap of a map, slice, or string is 'int', not 'int32'.
It does not change the meaning of int, but it should make
the eventual change of the meaning of int in 6g a bit smoother.

Update #2188.

R=ken, dave, remyoudompheng
CC=golang-dev
https://golang.org/cl/6542059
2012-09-24 14:59:44 -04:00
Russ Cox
031b389ac1 cmd/gc: fix comment for caninl
Was describing an old implementation.

R=ken2
CC=golang-dev
https://golang.org/cl/6553066
2012-09-24 12:30:32 -04:00
Russ Cox
c29f4e00a1 cmd/gc: fix a spurious -u compile error
Fixes #4082.

R=dsymonds
CC=golang-dev
https://golang.org/cl/6545055
2012-09-21 21:12:41 -04:00
Daniel Morsing
804a43ca76 cmd/gc: fix double evaluation in interface comparison
During interface compare, the operands will be evaluated twice. The operands might include function calls for conversion, so make them cheap before comparing them.

R=rsc
CC=golang-dev
https://golang.org/cl/6498133
2012-09-18 17:40:53 +02:00
Lucio De Re
b29ed23ab5 build: fix various 'set and not used' for Plan 9
R=dave, minux.ma, rsc
CC=golang-dev
https://golang.org/cl/6501134
2012-09-17 17:25:26 -04:00
Daniel Morsing
551e263823 cmd/gc: add missing conversion from bool to interface in switches.
In switches without an expression, the compiler would not convert the implicit true to an interface, causing codegen errors.

Fixes #3980.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6497147
2012-09-17 21:29:10 +02:00
Jan Ziak
032e5bfb30 ld: add .gcdata and .gcbss sections
R=rsc
CC=golang-dev
https://golang.org/cl/6281048
2012-09-13 15:59:34 -04:00
Daniel Morsing
d06dcd4595 cmd/gc: Specify which package import caused an redeclaration error.
Fixes #4012.

R=dave, remyoudompheng, rsc
CC=golang-dev
https://golang.org/cl/6490082
2012-09-13 18:40:50 +02:00
Russ Cox
6ee91ced92 cmd/pack: rename __.SYMDEF to __.GOSYMDEF
This fixes a problem with ELF tools thinking they know the
format of the symbol table, as we do not use any of the
standard formats for that table.

This change will probably annoy the Plan 9 users, but I
believe there are other incompatibilities already that mean
they have to use a Go-specific nm.

Fixes #3473.

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/6500117
2012-09-13 10:26:21 -04:00
Jan Ziak
d09afc2efb gc: generate garbage collection info for types
R=rsc, nigeltao, minux.ma
CC=golang-dev
https://golang.org/cl/6290043
2012-09-12 12:08:27 -04:00
Daniel Morsing
8fd65b0e1d cmd/gc: Inline pointer sized T2I interface conversions
This CL also adds support for marking the likelyness of IF nodes in the AST being true. This feature is being used here to mark the slow path as unlikely.

src/pkg/runtime:
benchmark                  old ns/op    new ns/op    delta
BenchmarkConvT2IUintptr           16            1  -91.63%

test/bench/go1:
benchmark                 old ns/op    new ns/op    delta
BenchmarkBinaryTree17    5416917000   5461355000   +0.82%
BenchmarkFannkuch11      3810355000   3842609000   +0.85%
BenchmarkGobDecode         19950950     19855420   -0.48%
BenchmarkGobEncode         11301220     11308530   +0.06%
BenchmarkGzip             548119600    546869200   -0.23%
BenchmarkGunzip           176145400    180208300   +2.31%
BenchmarkJSONEncode        93117400     70163100  -24.65%
BenchmarkJSONDecode       406626800    409999200   +0.83%
BenchmarkMandelbrot200      6300992      6317866   +0.27%
BenchmarkParse              7664396      7451625   -2.78%
BenchmarkRevcomp         1189424000   1412332000  +18.74%
BenchmarkTemplate         491308400    458654200   -6.65%

benchmark                  old MB/s     new MB/s  speedup
BenchmarkGobDecode            38.47        38.66    1.00x
BenchmarkGobEncode            67.92        67.87    1.00x
BenchmarkGzip                 35.40        35.48    1.00x
BenchmarkGunzip              110.16       107.68    0.98x
BenchmarkJSONEncode           20.84        27.66    1.33x
BenchmarkJSONDecode            4.77         4.73    0.99x
BenchmarkParse                 7.56         7.77    1.03x
BenchmarkRevcomp             213.69       179.96    0.84x
BenchmarkTemplate              3.95         4.23    1.07x

R=rsc, dave, nigeltao
CC=golang-dev
https://golang.org/cl/6351090
2012-09-11 21:42:30 +02:00
Nigel Tao
0184081eb9 cmd/gc: recognize small TPTR64 values as small integer constants.
Given the following Go program:

func sum(s []int) int {
        ret := 0
        for _, x := range s {
                ret += x
        }
        return ret
}

6g would previously generate:

--- prog list "sum" ---
0000 (main.go:3) TEXT    sum+0(SB),$0-24
0001 (main.go:5) MOVQ    s+0(FP),CX
0002 (main.go:5) MOVL    s+8(FP),DI
0003 (main.go:5) MOVL    s+12(FP),BX
0004 (main.go:4) MOVL    $0,SI
0005 (main.go:5) MOVL    $0,AX
0006 (main.go:5) JMP     ,8
0007 (main.go:5) INCL    ,AX
0008 (main.go:5) CMPL    AX,DI
0009 (main.go:5) JGE     $0,16
0010 (main.go:5) MOVL    (CX),DX
0011 (main.go:5) MOVQ    $4,BX
0012 (main.go:5) ADDQ    CX,BX
0013 (main.go:5) MOVQ    BX,CX
0014 (main.go:6) ADDL    DX,SI
0015 (main.go:5) JMP     ,7
0016 (main.go:8) MOVL    SI,.noname+16(FP)
0017 (main.go:8) RET     ,

and now generates:

--- prog list "sum" ---
0000 (main.go:3) TEXT    sum+0(SB),$0-24
0001 (main.go:5) MOVQ    s+0(FP),CX
0002 (main.go:5) MOVL    s+8(FP),DI
0003 (main.go:5) MOVL    s+12(FP),BX
0004 (main.go:4) MOVL    $0,SI
0005 (main.go:5) MOVL    $0,AX
0006 (main.go:5) JMP     ,8
0007 (main.go:5) INCL    ,AX
0008 (main.go:5) CMPL    AX,DI
0009 (main.go:5) JGE     $0,14
0010 (main.go:5) MOVL    (CX),BP
0011 (main.go:5) ADDQ    $4,CX
0012 (main.go:6) ADDL    BP,SI
0013 (main.go:5) JMP     ,7
0014 (main.go:8) MOVL    SI,.noname+16(FP)
0015 (main.go:8) RET     ,

The key difference is that
0011 (main.go:5) MOVQ    $4,BX
0012 (main.go:5) ADDQ    CX,BX
0013 (main.go:5) MOVQ    BX,CX
has changed to
0011 (main.go:5) ADDQ    $4,CX

R=rsc, dave, remyoudompheng
CC=golang-dev
https://golang.org/cl/6506089
2012-09-11 19:45:28 +10:00
Rob Pike
6ce4930365 gc: initial BOM is legal.
Fixes #4040.

R=rsc
CC=golang-dev
https://golang.org/cl/6497098
2012-09-10 13:03:07 -07:00
Nigel Tao
481e5c6ad0 cmd/gc: re-order some OFOO constants. Rename ORRC to ORROTC to be
consistent with OLROT. Delete unused OBAD, OLRC.

R=rsc, dave
CC=golang-dev
https://golang.org/cl/6489082
2012-09-06 10:47:25 +10:00
Nigel Tao
1c675ac89d cmd/gc: add commentary to the OXXX constants.
R=rsc, daniel.morsing
CC=golang-dev
https://golang.org/cl/6495074
2012-09-05 09:34:52 +10:00
Russ Cox
a96c2b8c1a cmd/gc: fix PkgPath of byte, rune types
Fixes #3853.

R=ken2
CC=golang-dev
https://golang.org/cl/6492071
2012-09-01 19:55:55 -04:00
Daniel Morsing
1c2021ca14 cmd/gc: Suggest *T in error for x.(T) if it would work.
Accomplished by synchronizing the formatting of conversion errors between typecheck.c and subr.c

Fixes #3984.

R=golang-dev, remyoudompheng, rsc
CC=golang-dev
https://golang.org/cl/6500064
2012-09-01 13:52:55 -04:00
Rémy Oudompheng
ba97d52b85 cmd/gc: fix escape analysis bug with variable capture in loops.
Fixes #3975.

R=rsc, lvd
CC=golang-dev, remy
https://golang.org/cl/6475061
2012-08-31 22:23:37 +02:00