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
d30c9a4b
Commit
d30c9a4b
authored
Sep 11, 2008
by
Ken Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement discussed function wo return statement
R=r OCL=15166 CL=15166
parent
5ea7649b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
5 deletions
+42
-5
gen.c
src/cmd/6g/gen.c
+4
-2
walk.c
src/cmd/gc/walk.c
+38
-3
No files found.
src/cmd/6g/gen.c
View file @
d30c9a4b
...
...
@@ -68,8 +68,10 @@ if(newproc == N) {
gclean
();
checklabels
();
// if(curfn->type->outtuple != 0)
// gins(AGOK, N, N);
if
(
curfn
->
type
->
outtuple
!=
0
)
{
nodconst
(
&
nod1
,
types
[
TUINT8
],
6
);
// 6 is opcode trap
gins
(
AINT
,
&
nod1
,
N
);
}
pc
->
as
=
ARET
;
// overwrite AEND
pc
->
lineno
=
lineno
;
...
...
src/cmd/gc/walk.c
View file @
d30c9a4b
...
...
@@ -10,6 +10,38 @@ static Type* sw3(Node*, Type*);
static
Node
*
curfn
;
static
Node
*
addtop
;
// can this code branch reach the end
// without an undcontitional RETURN
// this is hard, so it is conservative
int
walkret
(
Node
*
n
)
{
loop:
if
(
n
!=
N
)
switch
(
n
->
op
)
{
case
OLIST
:
if
(
n
->
right
==
N
)
{
n
=
n
->
left
;
goto
loop
;
}
n
=
n
->
right
;
goto
loop
;
// at this point, we have the last
// statement of the function
case
OGOTO
:
case
OPANIC
:
case
ORETURN
:
return
0
;
}
// all other statements
// will flow to the end
return
1
;
}
void
walk
(
Node
*
fn
)
{
...
...
@@ -18,12 +50,15 @@ walk(Node *fn)
curfn
=
fn
;
if
(
debug
[
'W'
])
{
snprint
(
s
,
sizeof
(
s
),
"
\n
before %S"
,
curfn
->
nname
->
sym
);
dump
(
s
,
fn
->
nbody
);
dump
(
s
,
cur
fn
->
nbody
);
}
walkstate
(
fn
->
nbody
);
if
(
curfn
->
type
->
outtuple
)
if
(
walkret
(
curfn
->
nbody
))
warn
(
"function ends without a return statement"
);
walkstate
(
curfn
->
nbody
);
if
(
debug
[
'W'
])
{
snprint
(
s
,
sizeof
(
s
),
"after %S"
,
curfn
->
nname
->
sym
);
dump
(
s
,
fn
->
nbody
);
dump
(
s
,
cur
fn
->
nbody
);
}
}
...
...
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