Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
61e7ba15
R
Rust
项目概览
int
/
Rust
接近 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
61e7ba15
编写于
8月 16, 2018
作者:
R
Ralf Jung
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix dynamically determining size and alignment
上级
e314a4e7
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
20 addition
and
17 deletion
+20
-17
src/librustc_mir/interpret/eval_context.rs
src/librustc_mir/interpret/eval_context.rs
+20
-17
未找到文件。
src/librustc_mir/interpret/eval_context.rs
浏览文件 @
61e7ba15
...
...
@@ -24,7 +24,7 @@
use
syntax
::
ast
::
Mutability
;
use
super
::{
Value
,
ValTy
,
Operand
,
MemPlace
,
MPlaceTy
,
Place
,
PlaceExtra
,
Value
,
Operand
,
MemPlace
,
MPlaceTy
,
Place
,
PlaceExtra
,
Memory
,
Machine
};
...
...
@@ -466,18 +466,19 @@ pub fn layout_of_local(
self
.layout_of
(
local_ty
)
}
/// Return the
size and alignment of the valu
e at the given type.
/// Return the
actual dynamic size and alignment of the plac
e at the given type.
/// Note that the value does not matter if the type is sized. For unsized types,
/// the value has to be a fat pointer, and we only care about the "extra" data in it.
pub
fn
size_and_align_of_
val
(
pub
fn
size_and_align_of_
mplace
(
&
self
,
val
:
Val
Ty
<
'tcx
>
,
mplace
:
MPlace
Ty
<
'tcx
>
,
)
->
EvalResult
<
'tcx
,
(
Size
,
Align
)
>
{
let
pointee_ty
=
val
.layout.ty
.builtin_deref
(
true
)
.unwrap
()
.ty
;
let
layout
=
self
.layout_of
(
pointee_ty
)
?
;
if
!
layout
.is_unsized
()
{
Ok
(
layout
.size_and_align
())
if
let
PlaceExtra
::
None
=
mplace
.extra
{
assert
!
(
!
mplace
.layout
.is_unsized
());
Ok
(
mplace
.layout
.size_and_align
())
}
else
{
let
layout
=
mplace
.layout
;
assert
!
(
layout
.is_unsized
());
match
layout
.ty.sty
{
ty
::
TyAdt
(
..
)
|
ty
::
TyTuple
(
..
)
=>
{
// First get the size of all statically known fields.
...
...
@@ -498,12 +499,8 @@ pub fn size_and_align_of_val(
// Recurse to get the size of the dynamically sized field (must be
// the last field).
let
field_layout
=
layout
.field
(
self
,
layout
.fields
.count
()
-
1
)
?
;
let
(
unsized_size
,
unsized_align
)
=
self
.size_and_align_of_val
(
ValTy
{
value
:
val
.value
,
layout
:
field_layout
})
?
;
let
field
=
self
.mplace_field
(
mplace
,
layout
.fields
.count
()
as
u64
-
1
)
?
;
let
(
unsized_size
,
unsized_align
)
=
self
.size_and_align_of_mplace
(
field
)
?
;
// FIXME (#26403, #27023): We should be adding padding
// to `sized_size` (to accommodate the `unsized_align`
...
...
@@ -533,18 +530,24 @@ pub fn size_and_align_of_val(
Ok
((
size
.abi_align
(
align
),
align
))
}
ty
::
TyDynamic
(
..
)
=>
{
let
(
_
,
vtable
)
=
val
.to_scalar_dyn_trait
()
?
;
let
vtable
=
match
mplace
.extra
{
PlaceExtra
::
Vtable
(
vtable
)
=>
vtable
,
_
=>
bug!
(
"Expected vtable"
),
};
// the second entry in the vtable is the dynamic size of the object.
self
.read_size_and_align_from_vtable
(
vtable
)
}
ty
::
TySlice
(
_
)
|
ty
::
TyStr
=>
{
let
len
=
match
mplace
.extra
{
PlaceExtra
::
Length
(
len
)
=>
len
,
_
=>
bug!
(
"Expected length"
),
};
let
(
elem_size
,
align
)
=
layout
.field
(
self
,
0
)
?
.size_and_align
();
let
(
_
,
len
)
=
val
.to_scalar_slice
(
self
)
?
;
Ok
((
elem_size
*
len
,
align
))
}
_
=>
bug!
(
"size_of_val::<{:?}>"
,
layout
.ty
),
_
=>
bug!
(
"size_of_val::<{:?}>
not supported
"
,
layout
.ty
),
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录