Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
5d9dbe19
Commit
5d9dbe19
authored
Jun 16, 2011
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gc: work around goto bug
R=ken2 CC=golang-dev
https://golang.org/cl/4629042
parent
f011bd37
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
159 additions
and
0 deletions
+159
-0
src/cmd/5g/gsubr.c
src/cmd/5g/gsubr.c
+58
-0
src/cmd/6g/gsubr.c
src/cmd/6g/gsubr.c
+35
-0
src/cmd/8g/gsubr.c
src/cmd/8g/gsubr.c
+35
-0
src/cmd/gc/dcl.c
src/cmd/gc/dcl.c
+5
-0
src/cmd/gc/gen.c
src/cmd/gc/gen.c
+1
-0
src/cmd/gc/go.h
src/cmd/gc/go.h
+3
-0
test/fixedbugs/bug344.go
test/fixedbugs/bug344.go
+22
-0
No files found.
src/cmd/5g/gsubr.c
View file @
5d9dbe19
...
...
@@ -124,6 +124,64 @@ newplist(void)
return
pl
;
}
void
clearstk
(
void
)
{
Plist
*
pl
;
Prog
*
p
,
*
p1
,
*
p2
,
*
p3
;
Node
dst
,
end
,
zero
,
con
;
if
(
plast
->
firstpc
->
to
.
offset
<=
0
)
return
;
// reestablish context for inserting code
// at beginning of function.
pl
=
plast
;
p1
=
pl
->
firstpc
;
p2
=
p1
->
link
;
pc
=
mal
(
sizeof
(
*
pc
));
clearp
(
pc
);
p1
->
link
=
pc
;
// zero stack frame
// MOVW $4(SP), R1
nodreg
(
&
dst
,
types
[
tptr
],
1
);
p
=
gins
(
AMOVW
,
N
,
&
dst
);
p
->
from
.
type
=
D_CONST
;
p
->
from
.
reg
=
REGSP
;
p
->
from
.
offset
=
4
;
// MOVW $n(R1), R2
nodreg
(
&
end
,
types
[
tptr
],
2
);
p
=
gins
(
AMOVW
,
N
,
&
end
);
p
->
from
.
type
=
D_CONST
;
p
->
from
.
reg
=
1
;
p
->
from
.
offset
=
p1
->
to
.
offset
;
// MOVW $0, R3
nodreg
(
&
zero
,
types
[
TUINT32
],
3
);
nodconst
(
&
con
,
types
[
TUINT32
],
0
);
gmove
(
&
con
,
&
zero
);
// L:
// MOVW.P R3, 0(R1) +4
// CMP R1, R2
// BNE L
p
=
gins
(
AMOVW
,
&
zero
,
&
dst
);
p
->
to
.
type
=
D_OREG
;
p
->
to
.
offset
=
4
;
p
->
scond
|=
C_PBIT
;
p3
=
p
;
p
=
gins
(
ACMP
,
&
dst
,
N
);
raddr
(
&
end
,
p
);
patch
(
gbranch
(
ABNE
,
T
),
p3
);
// continue with original code.
gins
(
ANOP
,
N
,
N
)
->
link
=
p2
;
pc
=
P
;
}
void
gused
(
Node
*
n
)
{
...
...
src/cmd/6g/gsubr.c
View file @
5d9dbe19
...
...
@@ -120,6 +120,41 @@ newplist(void)
return
pl
;
}
void
clearstk
(
void
)
{
Plist
*
pl
;
Prog
*
p1
,
*
p2
;
Node
sp
,
di
,
cx
,
con
;
if
((
uint32
)
plast
->
firstpc
->
to
.
offset
<=
0
)
return
;
// reestablish context for inserting code
// at beginning of function.
pl
=
plast
;
p1
=
pl
->
firstpc
;
p2
=
p1
->
link
;
pc
=
mal
(
sizeof
(
*
pc
));
clearp
(
pc
);
p1
->
link
=
pc
;
// zero stack frame
nodreg
(
&
sp
,
types
[
tptr
],
D_SP
);
nodreg
(
&
di
,
types
[
tptr
],
D_DI
);
nodreg
(
&
cx
,
types
[
TUINT64
],
D_CX
);
nodconst
(
&
con
,
types
[
TUINT64
],
(
uint32
)
p1
->
to
.
offset
/
widthptr
);
gins
(
ACLD
,
N
,
N
);
gins
(
AMOVQ
,
&
sp
,
&
di
);
gins
(
AMOVQ
,
&
con
,
&
cx
);
gins
(
AREP
,
N
,
N
);
gins
(
ASTOSQ
,
N
,
N
);
// continue with original code.
gins
(
ANOP
,
N
,
N
)
->
link
=
p2
;
pc
=
P
;
}
void
gused
(
Node
*
n
)
{
...
...
src/cmd/8g/gsubr.c
View file @
5d9dbe19
...
...
@@ -122,6 +122,41 @@ newplist(void)
return
pl
;
}
void
clearstk
(
void
)
{
Plist
*
pl
;
Prog
*
p1
,
*
p2
;
Node
sp
,
di
,
cx
,
con
;
if
(
plast
->
firstpc
->
to
.
offset
<=
0
)
return
;
// reestablish context for inserting code
// at beginning of function.
pl
=
plast
;
p1
=
pl
->
firstpc
;
p2
=
p1
->
link
;
pc
=
mal
(
sizeof
(
*
pc
));
clearp
(
pc
);
p1
->
link
=
pc
;
// zero stack frame
nodreg
(
&
sp
,
types
[
tptr
],
D_SP
);
nodreg
(
&
di
,
types
[
tptr
],
D_DI
);
nodreg
(
&
cx
,
types
[
TUINT32
],
D_CX
);
nodconst
(
&
con
,
types
[
TUINT32
],
p1
->
to
.
offset
/
widthptr
);
gins
(
ACLD
,
N
,
N
);
gins
(
AMOVL
,
&
sp
,
&
di
);
gins
(
AMOVL
,
&
con
,
&
cx
);
gins
(
AREP
,
N
,
N
);
gins
(
ASTOSL
,
N
,
N
);
// continue with original code.
gins
(
ANOP
,
N
,
N
)
->
link
=
p2
;
pc
=
P
;
}
void
gused
(
Node
*
n
)
{
...
...
src/cmd/gc/dcl.c
View file @
5d9dbe19
...
...
@@ -1241,9 +1241,14 @@ funccompile(Node *n, int isclosure)
stksize
=
0
;
dclcontext
=
PAUTO
;
funcdepth
=
n
->
funcdepth
+
1
;
hasgoto
=
0
;
compile
(
n
);
if
(
hasgoto
)
clearstk
();
curfn
=
nil
;
funcdepth
=
0
;
dclcontext
=
PEXTERN
;
}
src/cmd/gc/gen.c
View file @
5d9dbe19
...
...
@@ -209,6 +209,7 @@ gen(Node *n)
break
;
case
OGOTO
:
hasgoto
=
1
;
newlab
(
OGOTO
,
n
,
N
);
gjmp
(
P
);
break
;
...
...
src/cmd/gc/go.h
View file @
5d9dbe19
...
...
@@ -1257,3 +1257,6 @@ void zhist(Biobuf *b, int line, vlong offset);
void
zname
(
Biobuf
*
b
,
Sym
*
s
,
int
t
);
void
data
(
void
);
void
text
(
void
);
EXTERN
int
hasgoto
;
void
clearstk
(
void
);
test/fixedbugs/bug344.go
0 → 100644
View file @
5d9dbe19
// $G $D/$F.go && $L $F.$A && ./$A.out || echo BUG: bug344
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
main
import
"fmt"
func
main
()
{
// invalid use of goto.
// do whatever you like, just don't crash.
i
:=
42
a
:=
[]
*
int
{
&
i
,
&
i
,
&
i
,
&
i
}
x
:=
a
[
0
]
goto
start
for
_
,
x
=
range
a
{
start
:
fmt
.
Sprint
(
*
x
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment