Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
acc1dc29
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,发现更多精彩内容 >>
未验证
提交
acc1dc29
编写于
3月 29, 2020
作者:
D
Dylan DPC
提交者:
GitHub
3月 29, 2020
浏览文件
操作
浏览文件
下载
差异文件
Rollup merge of #70508 - RalfJung:scalar-from, r=eddyb
Miri: use more specialized Scalar::from_ constructors where appropriate
上级
96e29348
bd9e0464
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
15 addition
and
19 deletion
+15
-19
src/librustc_mir/interpret/cast.rs
src/librustc_mir/interpret/cast.rs
+1
-1
src/librustc_mir/interpret/intrinsics.rs
src/librustc_mir/interpret/intrinsics.rs
+5
-3
src/librustc_mir/interpret/operand.rs
src/librustc_mir/interpret/operand.rs
+3
-7
src/librustc_mir/interpret/place.rs
src/librustc_mir/interpret/place.rs
+3
-3
src/librustc_mir/interpret/step.rs
src/librustc_mir/interpret/step.rs
+3
-5
未找到文件。
src/librustc_mir/interpret/cast.rs
浏览文件 @
acc1dc29
...
...
@@ -208,7 +208,7 @@ fn cast_from_int_like(
Char
=>
{
// `u8` to `char` cast
Ok
(
Scalar
::
from_u
int
(
u8
::
try_from
(
v
)
.unwrap
(),
Size
::
from_bytes
(
4
)))
Ok
(
Scalar
::
from_u
32
(
u8
::
try_from
(
v
)
.unwrap
()
.into
(
)))
}
// Casts to bool are not permitted by rustc, no need to handle them here.
...
...
src/librustc_mir/interpret/intrinsics.rs
浏览文件 @
acc1dc29
...
...
@@ -2,6 +2,8 @@
//! looking at their MIR. Intrinsics/functions supported here are shared by CTFE
//! and miri.
use
std
::
convert
::
TryFrom
;
use
rustc
::
mir
::{
self
,
interpret
::{
ConstValue
,
GlobalId
,
InterpResult
,
Scalar
},
...
...
@@ -220,7 +222,7 @@ pub fn emulate_intrinsic(
sym
::
discriminant_value
=>
{
let
place
=
self
.deref_operand
(
args
[
0
])
?
;
let
discr_val
=
self
.read_discriminant
(
place
.into
())
?
.0
;
self
.write_scalar
(
Scalar
::
from_u
int
(
discr_val
,
dest
.layout.size
),
dest
)
?
;
self
.write_scalar
(
Scalar
::
from_u
64
(
u64
::
try_from
(
discr_val
)
.unwrap
()
),
dest
)
?
;
}
sym
::
unchecked_shl
|
sym
::
unchecked_shr
...
...
@@ -275,7 +277,6 @@ pub fn emulate_intrinsic(
}
sym
::
ptr_offset_from
=>
{
let
isize_layout
=
self
.layout_of
(
self
.tcx.types.isize
)
?
;
let
a
=
self
.read_immediate
(
args
[
0
])
?
.to_scalar
()
?
;
let
b
=
self
.read_immediate
(
args
[
1
])
?
.to_scalar
()
?
;
...
...
@@ -292,7 +293,7 @@ pub fn emulate_intrinsic(
let
a
=
a
.to_machine_usize
(
self
)
?
;
let
b
=
b
.to_machine_usize
(
self
)
?
;
if
a
==
b
&&
a
!=
0
{
self
.write_scalar
(
Scalar
::
from_
int
(
0
,
isize_layout
.size
),
dest
)
?
;
self
.write_scalar
(
Scalar
::
from_
machine_isize
(
0
,
self
),
dest
)
?
;
true
}
else
{
false
...
...
@@ -312,6 +313,7 @@ pub fn emulate_intrinsic(
);
}
let
usize_layout
=
self
.layout_of
(
self
.tcx.types.usize
)
?
;
let
isize_layout
=
self
.layout_of
(
self
.tcx.types.isize
)
?
;
let
a_offset
=
ImmTy
::
from_uint
(
a
.offset
.bytes
(),
usize_layout
);
let
b_offset
=
ImmTy
::
from_uint
(
b
.offset
.bytes
(),
usize_layout
);
let
(
val
,
_
overflowed
,
_
ty
)
=
...
...
src/librustc_mir/interpret/operand.rs
浏览文件 @
acc1dc29
...
...
@@ -54,10 +54,7 @@ fn from(val: Pointer<Tag>) -> Self {
impl
<
'tcx
,
Tag
>
Immediate
<
Tag
>
{
pub
fn
new_slice
(
val
:
Scalar
<
Tag
>
,
len
:
u64
,
cx
:
&
impl
HasDataLayout
)
->
Self
{
Immediate
::
ScalarPair
(
val
.into
(),
Scalar
::
from_uint
(
len
,
cx
.data_layout
()
.pointer_size
)
.into
(),
)
Immediate
::
ScalarPair
(
val
.into
(),
Scalar
::
from_machine_usize
(
len
,
cx
)
.into
())
}
pub
fn
new_dyn_trait
(
val
:
Scalar
<
Tag
>
,
vtable
:
Pointer
<
Tag
>
)
->
Self
{
...
...
@@ -621,7 +618,7 @@ pub fn read_discriminant(
let
real_discr
=
if
discr_val
.layout.abi
.is_signed
()
{
// going from layout tag type to typeck discriminant type
// requires first sign extending with the discriminant layout
let
sexted
=
sign_extend
(
bits_discr
,
discr_val
.layout.size
)
as
i128
;
let
sexted
=
sign_extend
(
bits_discr
,
discr_val
.layout.size
);
// and then zeroing with the typeck discriminant type
let
discr_ty
=
rval
.layout
...
...
@@ -631,8 +628,7 @@ pub fn read_discriminant(
.repr
.discr_type
();
let
size
=
layout
::
Integer
::
from_attr
(
self
,
discr_ty
)
.size
();
let
truncatee
=
sexted
as
u128
;
truncate
(
truncatee
,
size
)
truncate
(
sexted
,
size
)
}
else
{
bits_discr
};
...
...
src/librustc_mir/interpret/place.rs
浏览文件 @
acc1dc29
...
...
@@ -180,7 +180,7 @@ impl<'tcx, Tag> MPlaceTy<'tcx, Tag> {
#[inline]
pub
fn
dangling
(
layout
:
TyLayout
<
'tcx
>
,
cx
:
&
impl
HasDataLayout
)
->
Self
{
let
align
=
layout
.align.abi
;
let
ptr
=
Scalar
::
from_
uint
(
align
.bytes
(),
cx
.pointer_size
()
);
let
ptr
=
Scalar
::
from_
machine_usize
(
align
.bytes
(),
cx
);
// `Poison` this to make sure that the pointer value `ptr` is never observable by the program.
MPlaceTy
{
mplace
:
MemPlace
{
ptr
,
align
,
meta
:
MemPlaceMeta
::
Poison
},
layout
}
}
...
...
@@ -504,7 +504,7 @@ fn mplace_subslice(
// implement this.
ty
::
Array
(
inner
,
_
)
=>
(
MemPlaceMeta
::
None
,
self
.tcx
.mk_array
(
inner
,
inner_len
)),
ty
::
Slice
(
..
)
=>
{
let
len
=
Scalar
::
from_
uint
(
inner_len
,
self
.pointer_size
()
);
let
len
=
Scalar
::
from_
machine_usize
(
inner_len
,
self
);
(
MemPlaceMeta
::
Meta
(
len
),
base
.layout.ty
)
}
_
=>
bug!
(
"cannot subslice non-array type: `{:?}`"
,
base
.layout.ty
),
...
...
@@ -1044,7 +1044,7 @@ pub fn allocate_str(
kind
:
MemoryKind
<
M
::
MemoryKind
>
,
)
->
MPlaceTy
<
'tcx
,
M
::
PointerTag
>
{
let
ptr
=
self
.memory
.allocate_bytes
(
str
.as_bytes
(),
kind
);
let
meta
=
Scalar
::
from_
uint
(
u128
::
try_from
(
str
.len
())
.unwrap
(),
self
.pointer_size
()
);
let
meta
=
Scalar
::
from_
machine_usize
(
u64
::
try_from
(
str
.len
())
.unwrap
(),
self
);
let
mplace
=
MemPlace
{
ptr
:
ptr
.into
(),
align
:
Align
::
from_bytes
(
1
)
.unwrap
(),
...
...
src/librustc_mir/interpret/step.rs
浏览文件 @
acc1dc29
...
...
@@ -3,7 +3,7 @@
//! The main entry point is the `step` method.
use
rustc
::
mir
;
use
rustc
::
mir
::
interpret
::{
InterpResult
,
PointerArithmetic
,
Scalar
};
use
rustc
::
mir
::
interpret
::{
InterpResult
,
Scalar
};
use
rustc
::
ty
::
layout
::
LayoutOf
;
use
super
::{
InterpCx
,
Machine
};
...
...
@@ -229,8 +229,7 @@ pub fn eval_rvalue_into_place(
let
src
=
self
.eval_place
(
place
)
?
;
let
mplace
=
self
.force_allocation
(
src
)
?
;
let
len
=
mplace
.len
(
self
)
?
;
let
size
=
self
.pointer_size
();
self
.write_scalar
(
Scalar
::
from_uint
(
len
,
size
),
dest
)
?
;
self
.write_scalar
(
Scalar
::
from_machine_usize
(
len
,
self
),
dest
)
?
;
}
AddressOf
(
_
,
ref
place
)
|
Ref
(
_
,
_
,
ref
place
)
=>
{
...
...
@@ -254,8 +253,7 @@ pub fn eval_rvalue_into_place(
!
layout
.is_unsized
(),
"SizeOf nullary MIR operator called for unsized type"
);
let
size
=
self
.pointer_size
();
self
.write_scalar
(
Scalar
::
from_uint
(
layout
.size
.bytes
(),
size
),
dest
)
?
;
self
.write_scalar
(
Scalar
::
from_machine_usize
(
layout
.size
.bytes
(),
self
),
dest
)
?
;
}
Cast
(
kind
,
ref
operand
,
_
)
=>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录