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
3c0fc400
Commit
3c0fc400
authored
Feb 17, 2009
by
Ken Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix unsafe.Sizeof("abc")
R=rsc OCL=25105 CL=25105
parent
575257d5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
5 deletions
+13
-5
dcl.c
src/cmd/gc/dcl.c
+13
-5
No files found.
src/cmd/gc/dcl.c
View file @
3c0fc400
...
...
@@ -1525,7 +1525,7 @@ unsafenmagic(Node *l, Node *r)
{
Node
*
n
;
Sym
*
s
;
Type
*
t
;
Type
*
t
,
*
tr
;
long
v
;
Val
val
;
...
...
@@ -1541,9 +1541,12 @@ unsafenmagic(Node *l, Node *r)
if
(
strcmp
(
s
->
name
,
"Sizeof"
)
==
0
)
{
walktype
(
r
,
Erv
);
if
(
r
->
type
==
T
)
tr
=
r
->
type
;
if
(
r
->
op
==
OLITERAL
&&
r
->
val
.
ctype
==
CTSTR
)
tr
=
types
[
TSTRING
];
if
(
tr
==
T
)
goto
no
;
v
=
r
->
type
->
width
;
v
=
tr
->
width
;
goto
yes
;
}
if
(
strcmp
(
s
->
name
,
"Offsetof"
)
==
0
)
{
...
...
@@ -1555,16 +1558,21 @@ unsafenmagic(Node *l, Node *r)
}
if
(
strcmp
(
s
->
name
,
"Alignof"
)
==
0
)
{
walktype
(
r
,
Erv
);
if
(
r
->
type
==
T
)
tr
=
r
->
type
;
if
(
r
->
op
==
OLITERAL
&&
r
->
val
.
ctype
==
CTSTR
)
tr
=
types
[
TSTRING
];
if
(
tr
==
T
)
goto
no
;
// make struct { byte; T; }
t
=
typ
(
TSTRUCT
);
t
->
type
=
typ
(
TFIELD
);
t
->
type
->
type
=
types
[
TUINT8
];
t
->
type
->
down
=
typ
(
TFIELD
);
t
->
type
->
down
->
type
=
r
->
type
;
t
->
type
->
down
->
type
=
tr
;
// compute struct widths
dowidth
(
t
);
// the offset of T is its required alignment
v
=
t
->
type
->
down
->
width
;
goto
yes
;
...
...
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