Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
39b12e2d
Commit
39b12e2d
authored
Aug 07, 2009
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug185 - return b,a from func() (a,b int)
R=ken OCL=32900 CL=32900
parent
0ab8dbef
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
4 deletions
+67
-4
walk.c
src/cmd/gc/walk.c
+34
-4
bug185.go
test/fixedbugs/bug185.go
+33
-0
No files found.
src/cmd/gc/walk.c
View file @
39b12e2d
...
...
@@ -247,12 +247,22 @@ walkstmtlist(NodeList *l)
walkstmt
(
&
l
->
n
);
}
static
int
samelist
(
NodeList
*
a
,
NodeList
*
b
)
{
for
(;
a
&&
b
;
a
=
a
->
next
,
b
=
b
->
next
)
if
(
a
->
n
!=
b
->
n
)
return
0
;
return
a
==
b
;
}
void
walkstmt
(
Node
**
np
)
{
NodeList
*
init
;
NodeList
*
ll
;
int
lno
;
NodeList
*
ll
,
*
rl
;
int
cl
,
lno
;
Node
*
n
;
n
=
*
np
;
...
...
@@ -350,8 +360,28 @@ walkstmt(Node **np)
case
ORETURN
:
walkexprlist
(
n
->
list
,
&
n
->
ninit
);
if
(
curfn
->
type
->
outnamed
&&
n
->
list
==
nil
)
{
// print("special return\n");
if
(
curfn
->
type
->
outnamed
&&
count
(
n
->
list
)
!=
1
)
{
if
(
n
->
list
==
nil
)
{
// print("special return\n");
break
;
}
// assign to the function out parameters,
// so that reorder3 can fix up conflicts
rl
=
nil
;
for
(
ll
=
curfn
->
dcl
;
ll
!=
nil
;
ll
=
ll
->
next
)
{
cl
=
ll
->
n
->
class
&
~
PHEAP
;
if
(
cl
==
PAUTO
)
break
;
if
(
cl
==
PPARAMOUT
)
rl
=
list
(
rl
,
ll
->
n
);
}
if
(
samelist
(
rl
,
n
->
list
))
{
// special return in disguise
n
->
list
=
nil
;
break
;
}
ll
=
ascompatee
(
n
->
op
,
rl
,
n
->
list
,
&
n
->
ninit
);
n
->
list
=
reorder3
(
ll
);
break
;
}
ll
=
ascompatte
(
n
->
op
,
getoutarg
(
curfn
->
type
),
n
->
list
,
1
,
&
n
->
ninit
);
...
...
test/fixedbugs/bug185.go
0 → 100644
View file @
39b12e2d
// $G $D/$F.go && $L $F.$A && ./$A.out
// Copyright 2009 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
func
g
()
{
}
func
f1
()
(
a
,
b
int
)
{
a
,
b
=
2
,
1
;
g
();
// defeat optimizer
return
a
,
b
;
}
func
f2
()
(
a
,
b
int
)
{
a
,
b
=
1
,
2
;
g
();
// defeat optimizer
return
b
,
a
;
}
func
main
()
{
x
,
y
:=
f1
();
if
x
!=
2
||
y
!=
1
{
panicln
(
"f1"
,
x
,
y
);
}
x
,
y
=
f2
();
if
x
!=
2
||
y
!=
1
{
panicln
(
"f2"
,
x
,
y
);
}
}
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