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
e852202f
Commit
e852202f
authored
Jun 17, 2011
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gc: descriptive panic for nil pointer -> value method call
R=ken2 CC=golang-dev
https://golang.org/cl/4646042
parent
f4c7db0e
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
38 additions
and
5 deletions
+38
-5
src/cmd/5g/reg.c
src/cmd/5g/reg.c
+1
-0
src/cmd/6g/reg.c
src/cmd/6g/reg.c
+1
-0
src/cmd/8g/reg.c
src/cmd/8g/reg.c
+1
-0
src/cmd/gc/builtin.c.boot
src/cmd/gc/builtin.c.boot
+3
-1
src/cmd/gc/runtime.go
src/cmd/gc/runtime.go
+1
-0
src/cmd/gc/subr.c
src/cmd/gc/subr.c
+26
-4
src/pkg/runtime/error.go
src/pkg/runtime/error.go
+5
-0
No files found.
src/cmd/5g/reg.c
View file @
e852202f
...
...
@@ -1525,6 +1525,7 @@ noreturn(Prog *p)
symlist
[
1
]
=
pkglookup
(
"panicslice"
,
runtimepkg
);
symlist
[
2
]
=
pkglookup
(
"throwinit"
,
runtimepkg
);
symlist
[
3
]
=
pkglookup
(
"panic"
,
runtimepkg
);
symlist
[
4
]
=
pkglookup
(
"panicwrap"
,
runtimepkg
);
}
s
=
p
->
to
.
sym
;
...
...
src/cmd/6g/reg.c
View file @
e852202f
...
...
@@ -1677,6 +1677,7 @@ noreturn(Prog *p)
symlist
[
1
]
=
pkglookup
(
"panicslice"
,
runtimepkg
);
symlist
[
2
]
=
pkglookup
(
"throwinit"
,
runtimepkg
);
symlist
[
3
]
=
pkglookup
(
"panic"
,
runtimepkg
);
symlist
[
4
]
=
pkglookup
(
"panicwrap"
,
runtimepkg
);
}
s
=
p
->
to
.
sym
;
...
...
src/cmd/8g/reg.c
View file @
e852202f
...
...
@@ -1533,6 +1533,7 @@ noreturn(Prog *p)
symlist
[
1
]
=
pkglookup
(
"panicslice"
,
runtimepkg
);
symlist
[
2
]
=
pkglookup
(
"throwinit"
,
runtimepkg
);
symlist
[
3
]
=
pkglookup
(
"panic"
,
runtimepkg
);
symlist
[
4
]
=
pkglookup
(
"panicwrap"
,
runtimepkg
);
}
s
=
p
->
to
.
sym
;
...
...
src/cmd/gc/builtin.c.boot
View file @
e852202f
...
...
@@ -6,6 +6,7 @@ char *runtimeimport =
"func \"\".panicslice ()\n"
"func \"\".throwreturn ()\n"
"func \"\".throwinit ()\n"
"func \"\".panicwrap (? string, ? string, ? string)\n"
"func \"\".panic (? interface { })\n"
"func \"\".recover (? *int32) interface { }\n"
"func \"\".printbool (? bool)\n"
...
...
@@ -22,6 +23,7 @@ char *runtimeimport =
"func \"\".printsp ()\n"
"func \"\".goprintf ()\n"
"func \"\".concatstring ()\n"
"func \"\".append ()\n"
"func \"\".appendslice (typ *uint8, x any, y []any) any\n"
"func \"\".cmpstring (? string, ? string) int\n"
"func \"\".slicestring (? string, ? int, ? int) string\n"
...
...
@@ -81,7 +83,7 @@ char *runtimeimport =
"func \"\".selectgo (sel *uint8)\n"
"func \"\".block ()\n"
"func \"\".makeslice (typ *uint8, nel int64, cap int64) []any\n"
"func \"\".growslice (typ *uint8, old []any,
cap
int64) []any\n"
"func \"\".growslice (typ *uint8, old []any,
n
int64) []any\n"
"func \"\".sliceslice1 (old []any, lb uint64, width uint64) []any\n"
"func \"\".sliceslice (old []any, lb uint64, hb uint64, width uint64) []any\n"
"func \"\".slicearray (old *any, nel uint64, lb uint64, hb uint64, width uint64) []any\n"
...
...
src/cmd/gc/runtime.go
View file @
e852202f
...
...
@@ -15,6 +15,7 @@ func panicindex()
func
panicslice
()
func
throwreturn
()
func
throwinit
()
func
panicwrap
(
string
,
string
,
string
)
func
panic
(
interface
{})
func
recover
(
*
int32
)
interface
{}
...
...
src/cmd/gc/subr.c
View file @
e852202f
...
...
@@ -3131,8 +3131,9 @@ genwrapper(Type *rcvr, Type *method, Sym *newnam, int iface)
NodeList
*
l
,
*
args
,
*
in
,
*
out
;
Type
*
tpad
;
int
isddd
;
Val
v
;
if
(
0
&&
debug
[
'r'
])
if
(
debug
[
'r'
])
print
(
"genwrapper rcvrtype=%T method=%T newnam=%S
\n
"
,
rcvr
,
method
,
newnam
);
...
...
@@ -3174,17 +3175,38 @@ genwrapper(Type *rcvr, Type *method, Sym *newnam, int iface)
args
=
list
(
args
,
l
->
n
->
left
);
isddd
=
l
->
n
->
left
->
isddd
;
}
// generate nil pointer check for better error
if
(
isptr
[
rcvr
->
etype
]
&&
rcvr
->
type
==
getthisx
(
method
->
type
)
->
type
->
type
)
{
// generating wrapper from *T to T.
n
=
nod
(
OIF
,
N
,
N
);
n
->
ntest
=
nod
(
OEQ
,
this
->
left
,
nodnil
());
// these strings are already in the reflect tables,
// so no space cost to use them here.
l
=
nil
;
v
.
ctype
=
CTSTR
;
v
.
u
.
sval
=
strlit
(
rcvr
->
type
->
sym
->
pkg
->
name
);
// package name
l
=
list
(
l
,
nodlit
(
v
));
v
.
u
.
sval
=
strlit
(
rcvr
->
type
->
sym
->
name
);
// type name
l
=
list
(
l
,
nodlit
(
v
));
v
.
u
.
sval
=
strlit
(
method
->
sym
->
name
);
l
=
list
(
l
,
nodlit
(
v
));
// method name
call
=
nod
(
OCALL
,
syslook
(
"panicwrap"
,
0
),
N
);
call
->
list
=
l
;
n
->
nbody
=
list1
(
call
);
fn
->
nbody
=
list
(
fn
->
nbody
,
n
);
}
// generate call
call
=
nod
(
OCALL
,
adddot
(
nod
(
OXDOT
,
this
->
left
,
newname
(
method
->
sym
))),
N
);
call
->
list
=
args
;
call
->
isddd
=
isddd
;
fn
->
nbody
=
list1
(
call
);
if
(
method
->
type
->
outtuple
>
0
)
{
n
=
nod
(
ORETURN
,
N
,
N
);
n
->
list
=
fn
->
nbody
;
fn
->
nbody
=
list1
(
n
)
;
n
->
list
=
list1
(
call
)
;
call
=
n
;
}
fn
->
nbody
=
list
(
fn
->
nbody
,
call
);
if
(
0
&&
debug
[
'r'
])
dumplist
(
"genwrapper body"
,
fn
->
nbody
);
...
...
src/pkg/runtime/error.go
View file @
e852202f
...
...
@@ -131,3 +131,8 @@ func printany(i interface{}) {
print
(
"("
,
typestring
(
i
),
") "
,
i
)
}
}
// called from generated code
func
panicwrap
(
pkg
,
typ
,
meth
string
)
{
panic
(
"value method "
+
pkg
+
"."
+
typ
+
"."
+
meth
+
" called using nil *"
+
typ
+
" pointer"
)
}
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