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
05ac3008
Commit
05ac3008
authored
Sep 23, 2012
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cmd/gc: fix use of nil interface, slice
Fixes #3670. R=ken2 CC=golang-dev
https://golang.org/cl/6542058
parent
b51ad9cf
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
74 additions
and
1 deletion
+74
-1
cgen.c
src/cmd/5g/cgen.c
+15
-0
cgen.c
src/cmd/6g/cgen.c
+14
-0
gsubr.c
src/cmd/6g/gsubr.c
+7
-0
cgen.c
src/cmd/8g/cgen.c
+14
-0
gsubr.c
src/cmd/8g/gsubr.c
+6
-0
bug444.go
test/fixedbugs/bug444.go
+18
-1
No files found.
src/cmd/5g/cgen.c
View file @
05ac3008
...
@@ -554,6 +554,21 @@ agen(Node *n, Node *res)
...
@@ -554,6 +554,21 @@ agen(Node *n, Node *res)
while
(
n
->
op
==
OCONVNOP
)
while
(
n
->
op
==
OCONVNOP
)
n
=
n
->
left
;
n
=
n
->
left
;
if
(
isconst
(
n
,
CTNIL
)
&&
n
->
type
->
width
>
widthptr
)
{
// Use of a nil interface or nil slice.
// Create a temporary we can take the address of and read.
// The generated code is just going to panic, so it need not
// be terribly efficient. See issue 3670.
tempname
(
&
n1
,
n
->
type
);
clearfat
(
&
n1
);
regalloc
(
&
n2
,
types
[
tptr
],
res
);
gins
(
ALEAQ
,
&
n1
,
&
n2
);
gmove
(
&
n2
,
res
);
regfree
(
&
n2
);
goto
ret
;
}
if
(
n
->
addable
)
{
if
(
n
->
addable
)
{
memset
(
&
n1
,
0
,
sizeof
n1
);
memset
(
&
n1
,
0
,
sizeof
n1
);
n1
.
op
=
OADDR
;
n1
.
op
=
OADDR
;
...
...
src/cmd/6g/cgen.c
View file @
05ac3008
...
@@ -518,6 +518,20 @@ agen(Node *n, Node *res)
...
@@ -518,6 +518,20 @@ agen(Node *n, Node *res)
while
(
n
->
op
==
OCONVNOP
)
while
(
n
->
op
==
OCONVNOP
)
n
=
n
->
left
;
n
=
n
->
left
;
if
(
isconst
(
n
,
CTNIL
)
&&
n
->
type
->
width
>
widthptr
)
{
// Use of a nil interface or nil slice.
// Create a temporary we can take the address of and read.
// The generated code is just going to panic, so it need not
// be terribly efficient. See issue 3670.
tempname
(
&
n1
,
n
->
type
);
clearfat
(
&
n1
);
regalloc
(
&
n2
,
types
[
tptr
],
res
);
gins
(
ALEAQ
,
&
n1
,
&
n2
);
gmove
(
&
n2
,
res
);
regfree
(
&
n2
);
goto
ret
;
}
if
(
n
->
addable
)
{
if
(
n
->
addable
)
{
regalloc
(
&
n1
,
types
[
tptr
],
res
);
regalloc
(
&
n1
,
types
[
tptr
],
res
);
gins
(
ALEAQ
,
n
,
&
n1
);
gins
(
ALEAQ
,
n
,
&
n1
);
...
...
src/cmd/6g/gsubr.c
View file @
05ac3008
...
@@ -990,6 +990,13 @@ gins(int as, Node *f, Node *t)
...
@@ -990,6 +990,13 @@ gins(int as, Node *f, Node *t)
case
AMOVSD
:
case
AMOVSD
:
if
(
f
!=
N
&&
t
!=
N
&&
samaddr
(
f
,
t
))
if
(
f
!=
N
&&
t
!=
N
&&
samaddr
(
f
,
t
))
return
nil
;
return
nil
;
break
;
case
ALEAQ
:
if
(
f
!=
N
&&
isconst
(
f
,
CTNIL
))
{
fatal
(
"gins LEAQ nil %T"
,
f
->
type
);
}
break
;
}
}
memset
(
&
af
,
0
,
sizeof
af
);
memset
(
&
af
,
0
,
sizeof
af
);
...
...
src/cmd/8g/cgen.c
View file @
05ac3008
...
@@ -509,6 +509,20 @@ agen(Node *n, Node *res)
...
@@ -509,6 +509,20 @@ agen(Node *n, Node *res)
while
(
n
->
op
==
OCONVNOP
)
while
(
n
->
op
==
OCONVNOP
)
n
=
n
->
left
;
n
=
n
->
left
;
if
(
isconst
(
n
,
CTNIL
)
&&
n
->
type
->
width
>
widthptr
)
{
// Use of a nil interface or nil slice.
// Create a temporary we can take the address of and read.
// The generated code is just going to panic, so it need not
// be terribly efficient. See issue 3670.
tempname
(
&
n1
,
n
->
type
);
clearfat
(
&
n1
);
regalloc
(
&
n2
,
types
[
tptr
],
res
);
gins
(
ALEAL
,
&
n1
,
&
n2
);
gmove
(
&
n2
,
res
);
regfree
(
&
n2
);
return
;
}
// addressable var is easy
// addressable var is easy
if
(
n
->
addable
)
{
if
(
n
->
addable
)
{
if
(
n
->
op
==
OREGISTER
)
if
(
n
->
op
==
OREGISTER
)
...
...
src/cmd/8g/gsubr.c
View file @
05ac3008
...
@@ -1732,6 +1732,12 @@ gins(int as, Node *f, Node *t)
...
@@ -1732,6 +1732,12 @@ gins(int as, Node *f, Node *t)
case
AMOVL
:
case
AMOVL
:
if
(
f
!=
N
&&
t
!=
N
&&
samaddr
(
f
,
t
))
if
(
f
!=
N
&&
t
!=
N
&&
samaddr
(
f
,
t
))
return
nil
;
return
nil
;
break
;
case
ALEAL
:
if
(
f
!=
N
&&
isconst
(
f
,
CTNIL
))
fatal
(
"gins LEAQ nil %T"
,
f
->
type
);
break
;
}
}
memset
(
&
af
,
0
,
sizeof
af
);
memset
(
&
af
,
0
,
sizeof
af
);
...
...
test/fixedbugs/bug444.go
View file @
05ac3008
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
// The no-op conversion here used to confuse the compiler
// The no-op conversion here used to confuse the compiler
// into doing a load-effective-address of nil.
// into doing a load-effective-address of nil.
// See issue 3670.
package
main
package
main
...
@@ -13,7 +14,23 @@ import "reflect"
...
@@ -13,7 +14,23 @@ import "reflect"
type
T
interface
{}
type
T
interface
{}
var
x
bool
func
main
()
{
func
main
()
{
reflect
.
TypeOf
(
nil
)
reflect
.
TypeOf
(
nil
)
reflect
.
TypeOf
(
T
(
nil
))
// used to fail
reflect
.
TypeOf
(
T
(
nil
))
// used to miscompile
shouldPanic
()
}
func
f
()
byte
{
return
[]
byte
(
nil
)[
0
]
// used to miscompile
}
func
shouldPanic
()
{
defer
func
()
{
if
recover
()
==
nil
{
panic
(
"not panicking"
)
}
}()
f
()
}
}
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