Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
343b3f01
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,发现更多精彩内容 >>
提交
343b3f01
编写于
4月 02, 2020
作者:
R
Ralf Jung
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
switch assignment check back to testing layout equality
上级
351b7d09
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
23 addition
and
18 deletion
+23
-18
src/librustc_mir/interpret/eval_context.rs
src/librustc_mir/interpret/eval_context.rs
+21
-16
src/librustc_mir/interpret/place.rs
src/librustc_mir/interpret/place.rs
+2
-2
未找到文件。
src/librustc_mir/interpret/eval_context.rs
浏览文件 @
343b3f01
...
...
@@ -18,7 +18,7 @@
use
rustc_middle
::
ty
::
subst
::
SubstsRef
;
use
rustc_middle
::
ty
::{
self
,
Ty
,
TyCtxt
,
TypeFoldable
};
use
rustc_span
::
source_map
::
DUMMY_SP
;
use
rustc_target
::
abi
::{
Align
,
HasDataLayout
,
LayoutOf
,
Size
,
TargetDataLayout
};
use
rustc_target
::
abi
::{
A
bi
,
A
lign
,
HasDataLayout
,
LayoutOf
,
Size
,
TargetDataLayout
};
use
super
::{
Immediate
,
MPlaceTy
,
Machine
,
MemPlace
,
MemPlaceMeta
,
Memory
,
OpTy
,
Operand
,
Place
,
PlaceTy
,
...
...
@@ -212,20 +212,25 @@ fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyAndLayout {
/// Test if it is valid for a MIR assignment to assign `src`-typed place to `dest`-typed value.
/// This test should be symmetric, as it is primarily about layout compatibility.
pub
(
super
)
fn
mir_assign_valid_types
<
'tcx
>
(
src
:
Ty
<
'tcx
>
,
dest
:
Ty
<
'tcx
>
)
->
bool
{
src
==
dest
||
match
(
&
src
.kind
,
&
dest
.kind
)
{
(
ty
::
Ref
(
_
,
src_pointee
,
_
),
ty
::
Ref
(
_
,
dest_pointee
,
_
))
=>
{
// After optimizations, there can be assignments that change reference mutability.
// This does not affect reference layout, so that is fine.
src_pointee
==
dest_pointee
}
(
ty
::
FnPtr
(
_
),
ty
::
FnPtr
(
_
))
=>
{
// All function pointers have equal layout, and thus can be assigned.
true
}
_
=>
false
,
}
pub
(
super
)
fn
mir_assign_valid_types
<
'tcx
>
(
src
:
TyAndLayout
<
'tcx
>
,
dest
:
TyAndLayout
<
'tcx
>
,
)
->
bool
{
if
src
.ty
==
dest
.ty
{
// Equal types, all is good.
return
true
;
}
// Type-changing assignments can happen for (at least) two reasons:
// - `&mut T` -> `&T` gets optimized from a reborrow to a mere assignment.
// - Subtyping is used. While all normal lifetimes are erased, higher-ranked lifetime
// bounds are still around and can lead to type differences.
// There is no good way to check the latter, so we compare layouts instead -- but only
// for values with `Scalar`/`ScalarPair` abi.
// FIXME: Do something more accurate, type-based.
match
&
src
.abi
{
Abi
::
Scalar
(
..
)
|
Abi
::
ScalarPair
(
..
)
=>
src
.layout
==
dest
.layout
,
_
=>
false
,
}
}
/// Use the already known layout if given (but sanity check in debug mode),
...
...
@@ -241,7 +246,7 @@ pub(super) fn from_known_layout<'tcx>(
if
cfg!
(
debug_assertions
)
{
let
check_layout
=
compute
()
?
;
assert
!
(
mir_assign_valid_types
(
check_layout
.ty
,
known_layout
.ty
),
mir_assign_valid_types
(
check_layout
,
known_layout
),
"expected type differs from actual type.
\n
expected: {:?}
\n
actual: {:?}"
,
known_layout
.ty
,
check_layout
.ty
,
...
...
src/librustc_mir/interpret/place.rs
浏览文件 @
343b3f01
...
...
@@ -868,7 +868,7 @@ fn copy_op_no_validate(
// We do NOT compare the types for equality, because well-typed code can
// actually "transmute" `&mut T` to `&T` in an assignment without a cast.
assert
!
(
mir_assign_valid_types
(
src
.layout
.ty
,
dest
.layout.ty
),
mir_assign_valid_types
(
src
.layout
,
dest
.layout
),
"type mismatch when copying!
\n
src: {:?},
\n
dest: {:?}"
,
src
.layout.ty
,
dest
.layout.ty
,
...
...
@@ -922,7 +922,7 @@ pub fn copy_op_transmute(
src
:
OpTy
<
'tcx
,
M
::
PointerTag
>
,
dest
:
PlaceTy
<
'tcx
,
M
::
PointerTag
>
,
)
->
InterpResult
<
'tcx
>
{
if
mir_assign_valid_types
(
src
.layout
.ty
,
dest
.layout.ty
)
{
if
mir_assign_valid_types
(
src
.layout
,
dest
.layout
)
{
// Fast path: Just use normal `copy_op`
return
self
.copy_op
(
src
,
dest
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录