Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
c53aa298
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,发现更多精彩内容 >>
提交
c53aa298
编写于
7月 30, 2018
作者:
O
Oliver Schneider
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Address stylistic review comments and rebase fallout
上级
32eb10f5
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
44 addition
and
83 deletion
+44
-83
src/librustc/mir/interpret/value.rs
src/librustc/mir/interpret/value.rs
+6
-3
src/librustc_mir/interpret/const_eval.rs
src/librustc_mir/interpret/const_eval.rs
+4
-4
src/librustc_mir/interpret/eval_context.rs
src/librustc_mir/interpret/eval_context.rs
+22
-64
src/librustc_mir/interpret/memory.rs
src/librustc_mir/interpret/memory.rs
+4
-4
src/librustc_mir/interpret/place.rs
src/librustc_mir/interpret/place.rs
+1
-1
src/librustc_mir/interpret/terminator/drop.rs
src/librustc_mir/interpret/terminator/drop.rs
+1
-1
src/librustc_mir/interpret/terminator/mod.rs
src/librustc_mir/interpret/terminator/mod.rs
+1
-1
src/librustc_mir/interpret/traits.rs
src/librustc_mir/interpret/traits.rs
+3
-3
src/librustc_mir/transform/const_prop.rs
src/librustc_mir/transform/const_prop.rs
+2
-2
未找到文件。
src/librustc/mir/interpret/value.rs
浏览文件 @
c53aa298
...
@@ -28,8 +28,11 @@ impl<'tcx> ConstValue<'tcx> {
...
@@ -28,8 +28,11 @@ impl<'tcx> ConstValue<'tcx> {
pub
fn
from_byval_value
(
val
:
Value
)
->
EvalResult
<
'static
,
Self
>
{
pub
fn
from_byval_value
(
val
:
Value
)
->
EvalResult
<
'static
,
Self
>
{
Ok
(
match
val
{
Ok
(
match
val
{
Value
::
ByRef
(
..
)
=>
bug!
(),
Value
::
ByRef
(
..
)
=>
bug!
(),
Value
::
ScalarPair
(
a
,
b
)
=>
ConstValue
::
ScalarPair
(
a
.read
()
?
,
b
.read
()
?
),
Value
::
ScalarPair
(
a
,
b
)
=>
ConstValue
::
ScalarPair
(
Value
::
Scalar
(
val
)
=>
ConstValue
::
Scalar
(
val
.read
()
?
),
a
.unwrap_or_err
()
?
,
b
.unwrap_or_err
()
?
,
),
Value
::
Scalar
(
val
)
=>
ConstValue
::
Scalar
(
val
.unwrap_or_err
()
?
),
})
})
}
}
...
@@ -197,7 +200,7 @@ fn from(s: Scalar) -> Self {
...
@@ -197,7 +200,7 @@ fn from(s: Scalar) -> Self {
}
}
impl
ScalarMaybeUndef
{
impl
ScalarMaybeUndef
{
pub
fn
read
(
self
)
->
EvalResult
<
'static
,
Scalar
>
{
pub
fn
unwrap_or_err
(
self
)
->
EvalResult
<
'static
,
Scalar
>
{
match
self
{
match
self
{
ScalarMaybeUndef
::
Scalar
(
scalar
)
=>
Ok
(
scalar
),
ScalarMaybeUndef
::
Scalar
(
scalar
)
=>
Ok
(
scalar
),
ScalarMaybeUndef
::
Undef
=>
err!
(
ReadUndefBytes
),
ScalarMaybeUndef
::
Undef
=>
err!
(
ReadUndefBytes
),
...
...
src/librustc_mir/interpret/const_eval.rs
浏览文件 @
c53aa298
...
@@ -88,8 +88,8 @@ pub fn value_to_const_value<'tcx>(
...
@@ -88,8 +88,8 @@ pub fn value_to_const_value<'tcx>(
}
}
let
val
=
(||
{
let
val
=
(||
{
match
val
{
match
val
{
Value
::
Scalar
(
val
)
=>
Ok
(
ConstValue
::
Scalar
(
val
.
read
()
?
)),
Value
::
Scalar
(
val
)
=>
Ok
(
ConstValue
::
Scalar
(
val
.
unwrap_or_err
()
?
)),
Value
::
ScalarPair
(
a
,
b
)
=>
Ok
(
ConstValue
::
ScalarPair
(
a
.
read
()
?
,
b
.read
()
?
)),
Value
::
ScalarPair
(
a
,
b
)
=>
Ok
(
ConstValue
::
ScalarPair
(
a
.
unwrap_or_err
()
?
,
b
.unwrap_or_err
()
?
)),
Value
::
ByRef
(
ptr
,
align
)
=>
{
Value
::
ByRef
(
ptr
,
align
)
=>
{
let
ptr
=
ptr
.to_ptr
()
.unwrap
();
let
ptr
=
ptr
.to_ptr
()
.unwrap
();
let
alloc
=
ecx
.memory
.get
(
ptr
.alloc_id
)
?
;
let
alloc
=
ecx
.memory
.get
(
ptr
.alloc_id
)
?
;
...
@@ -441,7 +441,7 @@ pub fn const_val_field<'a, 'tcx>(
...
@@ -441,7 +441,7 @@ pub fn const_val_field<'a, 'tcx>(
let
place
=
ecx
.allocate_place_for_value
(
value
,
layout
,
variant
)
?
;
let
place
=
ecx
.allocate_place_for_value
(
value
,
layout
,
variant
)
?
;
let
(
place
,
layout
)
=
ecx
.place_field
(
place
,
field
,
layout
)
?
;
let
(
place
,
layout
)
=
ecx
.place_field
(
place
,
field
,
layout
)
?
;
let
(
ptr
,
align
)
=
place
.to_ptr_align
();
let
(
ptr
,
align
)
=
place
.to_ptr_align
();
let
mut
new_value
=
Value
::
ByRef
(
ptr
.
read
()
?
,
align
);
let
mut
new_value
=
Value
::
ByRef
(
ptr
.
unwrap_or_err
()
?
,
align
);
new_value
=
ecx
.try_read_by_ref
(
new_value
,
layout
.ty
)
?
;
new_value
=
ecx
.try_read_by_ref
(
new_value
,
layout
.ty
)
?
;
use
rustc_data_structures
::
indexed_vec
::
Idx
;
use
rustc_data_structures
::
indexed_vec
::
Idx
;
match
(
value
,
new_value
)
{
match
(
value
,
new_value
)
{
...
@@ -485,7 +485,7 @@ pub fn const_variant_index<'a, 'tcx>(
...
@@ -485,7 +485,7 @@ pub fn const_variant_index<'a, 'tcx>(
},
},
Value
::
ByRef
(
ptr
,
align
)
=>
(
ptr
,
align
),
Value
::
ByRef
(
ptr
,
align
)
=>
(
ptr
,
align
),
};
};
let
place
=
Place
::
from_scalar_ptr
(
ptr
,
align
);
let
place
=
Place
::
from_scalar_ptr
(
ptr
.into
()
,
align
);
ecx
.read_discriminant_as_variant_index
(
place
,
layout
)
ecx
.read_discriminant_as_variant_index
(
place
,
layout
)
}
}
...
...
src/librustc_mir/interpret/eval_context.rs
浏览文件 @
c53aa298
...
@@ -616,7 +616,7 @@ pub(super) fn pop_stack_frame(&mut self) -> EvalResult<'tcx> {
...
@@ -616,7 +616,7 @@ pub(super) fn pop_stack_frame(&mut self) -> EvalResult<'tcx> {
if
let
Place
::
Ptr
{
ptr
,
..
}
=
frame
.return_place
{
if
let
Place
::
Ptr
{
ptr
,
..
}
=
frame
.return_place
{
// FIXME: to_ptr()? might be too extreme here, static zsts might reach this under certain conditions
// FIXME: to_ptr()? might be too extreme here, static zsts might reach this under certain conditions
self
.memory
.mark_static_initialized
(
self
.memory
.mark_static_initialized
(
ptr
.
read
()
?
.to_ptr
()
?
.alloc_id
,
ptr
.
unwrap_or_err
()
?
.to_ptr
()
?
.alloc_id
,
mutable
,
mutable
,
)
?
)
?
}
else
{
}
else
{
...
@@ -744,7 +744,7 @@ pub(super) fn eval_rvalue_into_place(
...
@@ -744,7 +744,7 @@ pub(super) fn eval_rvalue_into_place(
let
(
dest
,
dest_align
)
=
self
.force_allocation
(
dest
)
?
.to_ptr_align
();
let
(
dest
,
dest_align
)
=
self
.force_allocation
(
dest
)
?
.to_ptr_align
();
if
length
>
0
{
if
length
>
0
{
let
dest
=
dest
.
read
()
?
;
let
dest
=
dest
.
unwrap_or_err
()
?
;
//write the first value
//write the first value
self
.write_value_to_ptr
(
value
,
dest
,
dest_align
,
elem_ty
)
?
;
self
.write_value_to_ptr
(
value
,
dest
,
dest_align
,
elem_ty
)
?
;
...
@@ -1082,7 +1082,7 @@ pub fn allocate_place_for_value(
...
@@ -1082,7 +1082,7 @@ pub fn allocate_place_for_value(
},
},
};
};
Ok
(
Place
::
Ptr
{
Ok
(
Place
::
Ptr
{
ptr
,
ptr
:
ptr
.into
()
,
align
,
align
,
extra
:
variant
.map_or
(
PlaceExtra
::
None
,
PlaceExtra
::
DowncastVariant
),
extra
:
variant
.map_or
(
PlaceExtra
::
None
,
PlaceExtra
::
DowncastVariant
),
})
})
...
@@ -1120,7 +1120,7 @@ pub fn force_allocation(&mut self, place: Place) -> EvalResult<'tcx, Place> {
...
@@ -1120,7 +1120,7 @@ pub fn force_allocation(&mut self, place: Place) -> EvalResult<'tcx, Place> {
/// ensures this Value is not a ByRef
/// ensures this Value is not a ByRef
pub
fn
follow_by_ref_value
(
pub
fn
follow_by_ref_value
(
&
mut
self
,
&
self
,
value
:
Value
,
value
:
Value
,
ty
:
Ty
<
'tcx
>
,
ty
:
Ty
<
'tcx
>
,
)
->
EvalResult
<
'tcx
,
Value
>
{
)
->
EvalResult
<
'tcx
,
Value
>
{
...
@@ -1133,13 +1133,13 @@ pub fn follow_by_ref_value(
...
@@ -1133,13 +1133,13 @@ pub fn follow_by_ref_value(
}
}
pub
fn
value_to_scalar
(
pub
fn
value_to_scalar
(
&
mut
self
,
&
self
,
ValTy
{
value
,
ty
}
:
ValTy
<
'tcx
>
,
ValTy
{
value
,
ty
}
:
ValTy
<
'tcx
>
,
)
->
EvalResult
<
'tcx
,
Scalar
>
{
)
->
EvalResult
<
'tcx
,
Scalar
>
{
match
self
.follow_by_ref_value
(
value
,
ty
)
?
{
match
self
.follow_by_ref_value
(
value
,
ty
)
?
{
Value
::
ByRef
{
..
}
=>
bug!
(
"follow_by_ref_value can't result in `ByRef`"
),
Value
::
ByRef
{
..
}
=>
bug!
(
"follow_by_ref_value can't result in `ByRef`"
),
Value
::
Scalar
(
scalar
)
=>
Ok
(
scalar
),
Value
::
Scalar
(
scalar
)
=>
scalar
.unwrap_or_err
(
),
Value
::
ScalarPair
(
..
)
=>
bug!
(
"value_to_scalar can't work with fat pointers"
),
Value
::
ScalarPair
(
..
)
=>
bug!
(
"value_to_scalar can't work with fat pointers"
),
}
}
...
@@ -1179,7 +1179,7 @@ pub fn write_value(
...
@@ -1179,7 +1179,7 @@ pub fn write_value(
match
dest
{
match
dest
{
Place
::
Ptr
{
ptr
,
align
,
extra
}
=>
{
Place
::
Ptr
{
ptr
,
align
,
extra
}
=>
{
assert_eq!
(
extra
,
PlaceExtra
::
None
);
assert_eq!
(
extra
,
PlaceExtra
::
None
);
self
.write_value_to_ptr
(
src_val
,
ptr
.
read
()
?
,
align
,
dest_ty
)
self
.write_value_to_ptr
(
src_val
,
ptr
.
unwrap_or_err
()
?
,
align
,
dest_ty
)
}
}
Place
::
Local
{
frame
,
local
}
=>
{
Place
::
Local
{
frame
,
local
}
=>
{
...
@@ -1288,37 +1288,6 @@ pub fn read_value(&self, ptr: Scalar, align: Align, ty: Ty<'tcx>) -> EvalResult<
...
@@ -1288,37 +1288,6 @@ pub fn read_value(&self, ptr: Scalar, align: Align, ty: Ty<'tcx>) -> EvalResult<
}
}
}
}
pub
(
crate
)
fn
read_ptr
(
&
self
,
ptr
:
Pointer
,
ptr_align
:
Align
,
pointee_ty
:
Ty
<
'tcx
>
,
)
->
EvalResult
<
'tcx
,
Value
>
{
let
ptr_size
=
self
.memory
.pointer_size
();
let
p
:
ScalarMaybeUndef
=
self
.memory
.read_ptr_sized
(
ptr
,
ptr_align
)
?
;
if
self
.type_is_sized
(
pointee_ty
)
{
Ok
(
Value
::
Scalar
(
p
))
}
else
{
trace!
(
"reading fat pointer extra of type {}"
,
pointee_ty
);
let
extra
=
ptr
.offset
(
ptr_size
,
self
)
?
;
match
self
.tcx
.struct_tail
(
pointee_ty
)
.sty
{
ty
::
TyDynamic
(
..
)
=>
Ok
(
Value
::
ScalarPair
(
p
,
self
.memory
.read_ptr_sized
(
extra
,
ptr_align
)
?
,
)),
ty
::
TySlice
(
..
)
|
ty
::
TyStr
=>
{
let
len
=
self
.memory
.read_ptr_sized
(
extra
,
ptr_align
)
?
.read
()
?
.to_bits
(
ptr_size
)
?
;
Ok
(
p
.to_value_with_len
(
len
as
u64
,
self
.tcx.tcx
))
},
_
=>
bug!
(
"unsized scalar ptr read from {:?}"
,
pointee_ty
),
}
}
}
fn
validate_scalar
(
fn
validate_scalar
(
&
self
,
&
self
,
value
:
Scalar
,
value
:
Scalar
,
...
@@ -1330,8 +1299,11 @@ fn validate_scalar(
...
@@ -1330,8 +1299,11 @@ fn validate_scalar(
trace!
(
"validate scalar: {:#?}, {:#?}, {:#?}, {}"
,
value
,
size
,
scalar
,
ty
);
trace!
(
"validate scalar: {:#?}, {:#?}, {:#?}, {}"
,
value
,
size
,
scalar
,
ty
);
let
(
lo
,
hi
)
=
scalar
.valid_range
.clone
()
.into_inner
();
let
(
lo
,
hi
)
=
scalar
.valid_range
.clone
()
.into_inner
();
let
(
bits
,
defined
)
=
match
value
{
let
bits
=
match
value
{
Scalar
::
Bits
{
bits
,
defined
}
=>
(
bits
,
defined
),
Scalar
::
Bits
{
bits
,
size
:
value_size
}
=>
{
assert_eq!
(
value_size
as
u64
,
size
.bytes
());
bits
},
Scalar
::
Ptr
(
_
)
=>
{
Scalar
::
Ptr
(
_
)
=>
{
let
ptr_size
=
self
.memory
.pointer_size
();
let
ptr_size
=
self
.memory
.pointer_size
();
let
ptr_max
=
u128
::
max_value
()
>>
(
128
-
ptr_size
.bits
());
let
ptr_max
=
u128
::
max_value
()
>>
(
128
-
ptr_size
.bits
());
...
@@ -1374,30 +1346,16 @@ fn validate_scalar(
...
@@ -1374,30 +1346,16 @@ fn validate_scalar(
}
}
use
std
::
ops
::
RangeInclusive
;
use
std
::
ops
::
RangeInclusive
;
let
in_range
=
|
bound
:
RangeInclusive
<
u128
>
|
{
let
in_range
=
|
bound
:
RangeInclusive
<
u128
>
|
bound
.contains
(
&
bits
);
defined
as
u64
>=
size
.bits
()
&&
bound
.contains
(
&
bits
)
};
if
lo
>
hi
{
if
lo
>
hi
{
if
in_range
(
0
..=
hi
)
||
in_range
(
lo
..=
u128
::
max_value
())
{
if
in_range
(
0
..=
hi
)
||
in_range
(
lo
..=
u128
::
max_value
())
{
Ok
(())
Ok
(())
}
else
if
defined
as
u64
>=
size
.bits
()
{
validation_failure!
(
bits
,
path
,
format!
(
"something in the range {:?} or {:?}"
,
..=
hi
,
lo
..
)
)
}
else
{
}
else
{
validation_failure!
(
"undefined bytes"
,
path
)
validation_failure!
(
"undefined bytes"
,
path
)
}
}
}
else
{
}
else
{
if
in_range
(
scalar
.valid_range
.clone
())
{
if
in_range
(
scalar
.valid_range
.clone
())
{
Ok
(())
Ok
(())
}
else
if
defined
as
u64
>=
size
.bits
()
{
validation_failure!
(
bits
,
path
,
format!
(
"something in the range {:?}"
,
scalar
.valid_range
)
)
}
else
{
}
else
{
validation_failure!
(
"undefined bytes"
,
path
)
validation_failure!
(
"undefined bytes"
,
path
)
}
}
...
@@ -1455,7 +1413,7 @@ pub fn validate_ptr_target(
...
@@ -1455,7 +1413,7 @@ pub fn validate_ptr_target(
// expectation.
// expectation.
layout
::
Abi
::
Scalar
(
ref
scalar
)
=>
{
layout
::
Abi
::
Scalar
(
ref
scalar
)
=>
{
let
size
=
scalar
.value
.size
(
self
);
let
size
=
scalar
.value
.size
(
self
);
let
value
=
self
.memory
.read_scalar
(
ptr
,
ptr_align
,
size
)
?
;
let
value
=
self
.memory
.read_scalar
(
ptr
,
ptr_align
,
size
)
?
.unwrap_or_err
()
?
;
self
.validate_scalar
(
value
,
size
,
scalar
,
&
path
,
layout
.ty
)
?
;
self
.validate_scalar
(
value
,
size
,
scalar
,
&
path
,
layout
.ty
)
?
;
if
scalar
.value
==
Primitive
::
Pointer
{
if
scalar
.value
==
Primitive
::
Pointer
{
// ignore integer pointers, we can't reason about the final hardware
// ignore integer pointers, we can't reason about the final hardware
...
@@ -1538,7 +1496,7 @@ pub fn validate_ptr_target(
...
@@ -1538,7 +1496,7 @@ pub fn validate_ptr_target(
}
}
}
}
pub
fn
try_read_by_ref
(
&
mut
self
,
mut
val
:
Value
,
ty
:
Ty
<
'tcx
>
)
->
EvalResult
<
'tcx
,
Value
>
{
pub
fn
try_read_by_ref
(
&
self
,
mut
val
:
Value
,
ty
:
Ty
<
'tcx
>
)
->
EvalResult
<
'tcx
,
Value
>
{
// Convert to ByVal or ScalarPair if possible
// Convert to ByVal or ScalarPair if possible
if
let
Value
::
ByRef
(
ptr
,
align
)
=
val
{
if
let
Value
::
ByRef
(
ptr
,
align
)
=
val
{
if
let
Some
(
read_val
)
=
self
.try_read_value
(
ptr
,
align
,
ty
)
?
{
if
let
Some
(
read_val
)
=
self
.try_read_value
(
ptr
,
align
,
ty
)
?
{
...
@@ -1548,7 +1506,7 @@ pub fn try_read_by_ref(&mut self, mut val: Value, ty: Ty<'tcx>) -> EvalResult<'t
...
@@ -1548,7 +1506,7 @@ pub fn try_read_by_ref(&mut self, mut val: Value, ty: Ty<'tcx>) -> EvalResult<'t
Ok
(
val
)
Ok
(
val
)
}
}
pub
fn
try_read_value
(
&
mut
self
,
ptr
:
Scalar
,
ptr_align
:
Align
,
ty
:
Ty
<
'tcx
>
)
->
EvalResult
<
'tcx
,
Option
<
Value
>>
{
pub
fn
try_read_value
(
&
self
,
ptr
:
Scalar
,
ptr_align
:
Align
,
ty
:
Ty
<
'tcx
>
)
->
EvalResult
<
'tcx
,
Option
<
Value
>>
{
let
mut
layout
=
self
.layout_of
(
ty
)
?
;
let
mut
layout
=
self
.layout_of
(
ty
)
?
;
self
.memory
.check_align
(
ptr
,
ptr_align
)
?
;
self
.memory
.check_align
(
ptr
,
ptr_align
)
?
;
...
@@ -1563,9 +1521,9 @@ pub fn try_read_value(&mut self, ptr: Scalar, ptr_align: Align, ty: Ty<'tcx>) ->
...
@@ -1563,9 +1521,9 @@ pub fn try_read_value(&mut self, ptr: Scalar, ptr_align: Align, ty: Ty<'tcx>) ->
layout
::
Variants
::
Tagged
{
..
}
=>
{
layout
::
Variants
::
Tagged
{
..
}
=>
{
let
variant_index
=
self
.read_discriminant_as_variant_index
(
let
variant_index
=
self
.read_discriminant_as_variant_index
(
Place
::
from_ptr
(
ptr
,
ptr_align
),
Place
::
from_ptr
(
ptr
,
ptr_align
),
layout
.ty
,
layout
,
)
?
;
)
?
;
layout
=
layout
.for_variant
(
&
self
,
variant_index
);
layout
=
layout
.for_variant
(
self
,
variant_index
);
trace!
(
"variant layout: {:#?}"
,
layout
);
trace!
(
"variant layout: {:#?}"
,
layout
);
},
},
layout
::
Variants
::
Single
{
..
}
=>
{},
layout
::
Variants
::
Single
{
..
}
=>
{},
...
@@ -1578,10 +1536,10 @@ pub fn try_read_value(&mut self, ptr: Scalar, ptr_align: Align, ty: Ty<'tcx>) ->
...
@@ -1578,10 +1536,10 @@ pub fn try_read_value(&mut self, ptr: Scalar, ptr_align: Align, ty: Ty<'tcx>) ->
}
}
layout
::
Abi
::
ScalarPair
(
ref
a
,
ref
b
)
=>
{
layout
::
Abi
::
ScalarPair
(
ref
a
,
ref
b
)
=>
{
let
(
a
,
b
)
=
(
&
a
.value
,
&
b
.value
);
let
(
a
,
b
)
=
(
&
a
.value
,
&
b
.value
);
let
(
a_size
,
b_size
)
=
(
a
.size
(
&
self
),
b
.size
(
&
self
));
let
(
a_size
,
b_size
)
=
(
a
.size
(
self
),
b
.size
(
self
));
let
a_ptr
=
ptr
;
let
a_ptr
=
ptr
;
let
b_offset
=
a_size
.abi_align
(
b
.align
(
&
self
));
let
b_offset
=
a_size
.abi_align
(
b
.align
(
self
));
let
b_ptr
=
ptr
.offset
(
b_offset
,
&
self
)
?
.into
();
let
b_ptr
=
ptr
.offset
(
b_offset
,
self
)
?
.into
();
let
a_val
=
self
.memory
.read_scalar
(
a_ptr
,
ptr_align
,
a_size
)
?
;
let
a_val
=
self
.memory
.read_scalar
(
a_ptr
,
ptr_align
,
a_size
)
?
;
let
b_val
=
self
.memory
.read_scalar
(
b_ptr
,
ptr_align
,
b_size
)
?
;
let
b_val
=
self
.memory
.read_scalar
(
b_ptr
,
ptr_align
,
b_size
)
?
;
Ok
(
Some
(
Value
::
ScalarPair
(
a_val
,
b_val
)))
Ok
(
Some
(
Value
::
ScalarPair
(
a_val
,
b_val
)))
...
@@ -1929,7 +1887,7 @@ fn init_value(&mut self, ty: Ty<'tcx>) -> EvalResult<'tcx, Value> {
...
@@ -1929,7 +1887,7 @@ fn init_value(&mut self, ty: Ty<'tcx>) -> EvalResult<'tcx, Value> {
ScalarMaybeUndef
::
Undef
,
ScalarMaybeUndef
::
Undef
,
ScalarMaybeUndef
::
Undef
,
ScalarMaybeUndef
::
Undef
,
),
),
_
=>
Value
::
ByRef
(
self
.alloc_ptr
(
ty
)
?
.into
(),
layout
.align
),
_
=>
Value
::
ByRef
(
self
.alloc_ptr
(
layout
)
?
.into
(),
layout
.align
),
})
})
}
}
}
}
...
...
src/librustc_mir/interpret/memory.rs
浏览文件 @
c53aa298
...
@@ -1011,11 +1011,11 @@ fn into_ptr_vtable_pair(
...
@@ -1011,11 +1011,11 @@ fn into_ptr_vtable_pair(
let
vtable
=
mem
.read_ptr_sized
(
let
vtable
=
mem
.read_ptr_sized
(
ref_ptr
.ptr_offset
(
mem
.pointer_size
(),
&
mem
.tcx.data_layout
)
?
.to_ptr
()
?
,
ref_ptr
.ptr_offset
(
mem
.pointer_size
(),
&
mem
.tcx.data_layout
)
?
.to_ptr
()
?
,
align
align
)
?
.
read
()
?
.to_ptr
()
?
;
)
?
.
unwrap_or_err
()
?
.to_ptr
()
?
;
Ok
((
ptr
,
vtable
))
Ok
((
ptr
,
vtable
))
}
}
Value
::
ScalarPair
(
ptr
,
vtable
)
=>
Ok
((
ptr
,
vtable
.
read
()
?
.to_ptr
()
?
)),
Value
::
ScalarPair
(
ptr
,
vtable
)
=>
Ok
((
ptr
,
vtable
.
unwrap_or_err
()
?
.to_ptr
()
?
)),
_
=>
bug!
(
"expected ptr and vtable, got {:?}"
,
value
),
_
=>
bug!
(
"expected ptr and vtable, got {:?}"
,
value
),
}
}
}
}
...
@@ -1031,11 +1031,11 @@ fn into_slice(
...
@@ -1031,11 +1031,11 @@ fn into_slice(
let
len
=
mem
.read_ptr_sized
(
let
len
=
mem
.read_ptr_sized
(
ref_ptr
.ptr_offset
(
mem
.pointer_size
(),
&
mem
.tcx.data_layout
)
?
.to_ptr
()
?
,
ref_ptr
.ptr_offset
(
mem
.pointer_size
(),
&
mem
.tcx.data_layout
)
?
.to_ptr
()
?
,
align
align
)
?
.
read
()
?
.to_bits
(
mem
.pointer_size
())
?
as
u64
;
)
?
.
unwrap_or_err
()
?
.to_bits
(
mem
.pointer_size
())
?
as
u64
;
Ok
((
ptr
,
len
))
Ok
((
ptr
,
len
))
}
}
Value
::
ScalarPair
(
ptr
,
val
)
=>
{
Value
::
ScalarPair
(
ptr
,
val
)
=>
{
let
len
=
val
.
read
()
?
.to_bits
(
self
.memory
()
.pointer_size
())
?
;
let
len
=
val
.
unwrap_or_err
()
?
.to_bits
(
self
.memory
()
.pointer_size
())
?
;
Ok
((
ptr
,
len
as
u64
))
Ok
((
ptr
,
len
as
u64
))
}
}
Value
::
Scalar
(
_
)
=>
bug!
(
"expected ptr and length, got {:?}"
,
value
),
Value
::
Scalar
(
_
)
=>
bug!
(
"expected ptr and length, got {:?}"
,
value
),
...
...
src/librustc_mir/interpret/place.rs
浏览文件 @
c53aa298
...
@@ -197,7 +197,7 @@ pub fn read_place(&self, place: Place) -> EvalResult<'tcx, Value> {
...
@@ -197,7 +197,7 @@ pub fn read_place(&self, place: Place) -> EvalResult<'tcx, Value> {
match
place
{
match
place
{
Place
::
Ptr
{
ptr
,
align
,
extra
}
=>
{
Place
::
Ptr
{
ptr
,
align
,
extra
}
=>
{
assert_eq!
(
extra
,
PlaceExtra
::
None
);
assert_eq!
(
extra
,
PlaceExtra
::
None
);
Ok
(
Value
::
ByRef
(
ptr
.
read
()
?
,
align
))
Ok
(
Value
::
ByRef
(
ptr
.
unwrap_or_err
()
?
,
align
))
}
}
Place
::
Local
{
frame
,
local
}
=>
self
.stack
[
frame
]
.locals
[
local
]
.access
(),
Place
::
Local
{
frame
,
local
}
=>
self
.stack
[
frame
]
.locals
[
local
]
.access
(),
}
}
...
...
src/librustc_mir/interpret/terminator/drop.rs
浏览文件 @
c53aa298
...
@@ -52,7 +52,7 @@ fn drop(
...
@@ -52,7 +52,7 @@ fn drop(
let
instance
=
match
ty
.sty
{
let
instance
=
match
ty
.sty
{
ty
::
TyDynamic
(
..
)
=>
{
ty
::
TyDynamic
(
..
)
=>
{
if
let
Value
::
ScalarPair
(
_
,
vtable
)
=
arg
{
if
let
Value
::
ScalarPair
(
_
,
vtable
)
=
arg
{
self
.read_drop_type_from_vtable
(
vtable
.
read
()
?
.to_ptr
()
?
)
?
self
.read_drop_type_from_vtable
(
vtable
.
unwrap_or_err
()
?
.to_ptr
()
?
)
?
}
else
{
}
else
{
bug!
(
"expected fat ptr, got {:?}"
,
arg
);
bug!
(
"expected fat ptr, got {:?}"
,
arg
);
}
}
...
...
src/librustc_mir/interpret/terminator/mod.rs
浏览文件 @
c53aa298
...
@@ -392,7 +392,7 @@ fn eval_fn_call(
...
@@ -392,7 +392,7 @@ fn eval_fn_call(
let
fn_ptr
=
self
.memory
.read_ptr_sized
(
let
fn_ptr
=
self
.memory
.read_ptr_sized
(
vtable
.offset
(
ptr_size
*
(
idx
as
u64
+
3
),
&
self
)
?
,
vtable
.offset
(
ptr_size
*
(
idx
as
u64
+
3
),
&
self
)
?
,
ptr_align
ptr_align
)
?
.
read
()
?
.to_ptr
()
?
;
)
?
.
unwrap_or_err
()
?
.to_ptr
()
?
;
let
instance
=
self
.memory
.get_fn
(
fn_ptr
)
?
;
let
instance
=
self
.memory
.get_fn
(
fn_ptr
)
?
;
let
mut
args
=
args
.to_vec
();
let
mut
args
=
args
.to_vec
();
let
ty
=
self
.layout_of
(
args
[
0
]
.ty
)
?
.field
(
&
self
,
0
)
?
.ty
;
let
ty
=
self
.layout_of
(
args
[
0
]
.ty
)
?
.field
(
&
self
,
0
)
?
.ty
;
...
...
src/librustc_mir/interpret/traits.rs
浏览文件 @
c53aa298
...
@@ -72,7 +72,7 @@ pub fn read_drop_type_from_vtable(
...
@@ -72,7 +72,7 @@ pub fn read_drop_type_from_vtable(
)
->
EvalResult
<
'tcx
,
ty
::
Instance
<
'tcx
>>
{
)
->
EvalResult
<
'tcx
,
ty
::
Instance
<
'tcx
>>
{
// we don't care about the pointee type, we just want a pointer
// we don't care about the pointee type, we just want a pointer
let
pointer_align
=
self
.tcx.data_layout.pointer_align
;
let
pointer_align
=
self
.tcx.data_layout.pointer_align
;
let
drop_fn
=
self
.memory
.read_ptr_sized
(
vtable
,
pointer_align
)
?
.
read
()
?
.to_ptr
()
?
;
let
drop_fn
=
self
.memory
.read_ptr_sized
(
vtable
,
pointer_align
)
?
.
unwrap_or_err
()
?
.to_ptr
()
?
;
self
.memory
.get_fn
(
drop_fn
)
self
.memory
.get_fn
(
drop_fn
)
}
}
...
@@ -82,11 +82,11 @@ pub fn read_size_and_align_from_vtable(
...
@@ -82,11 +82,11 @@ pub fn read_size_and_align_from_vtable(
)
->
EvalResult
<
'tcx
,
(
Size
,
Align
)
>
{
)
->
EvalResult
<
'tcx
,
(
Size
,
Align
)
>
{
let
pointer_size
=
self
.memory
.pointer_size
();
let
pointer_size
=
self
.memory
.pointer_size
();
let
pointer_align
=
self
.tcx.data_layout.pointer_align
;
let
pointer_align
=
self
.tcx.data_layout.pointer_align
;
let
size
=
self
.memory
.read_ptr_sized
(
vtable
.offset
(
pointer_size
,
self
)
?
,
pointer_align
)
?
.
read
()
?
.to_bits
(
pointer_size
)
?
as
u64
;
let
size
=
self
.memory
.read_ptr_sized
(
vtable
.offset
(
pointer_size
,
self
)
?
,
pointer_align
)
?
.
unwrap_or_err
()
?
.to_bits
(
pointer_size
)
?
as
u64
;
let
align
=
self
.memory
.read_ptr_sized
(
let
align
=
self
.memory
.read_ptr_sized
(
vtable
.offset
(
pointer_size
*
2
,
self
)
?
,
vtable
.offset
(
pointer_size
*
2
,
self
)
?
,
pointer_align
pointer_align
)
?
.
read
()
?
.to_bits
(
pointer_size
)
?
as
u64
;
)
?
.
unwrap_or_err
()
?
.to_bits
(
pointer_size
)
?
as
u64
;
Ok
((
Size
::
from_bytes
(
size
),
Align
::
from_bytes
(
align
,
align
)
.unwrap
()))
Ok
((
Size
::
from_bytes
(
size
),
Align
::
from_bytes
(
align
,
align
)
.unwrap
()))
}
}
}
}
src/librustc_mir/transform/const_prop.rs
浏览文件 @
c53aa298
...
@@ -369,7 +369,7 @@ fn const_prop(
...
@@ -369,7 +369,7 @@ fn const_prop(
Value
::
Scalar
(
Scalar
::
Bits
{
Value
::
Scalar
(
Scalar
::
Bits
{
bits
:
n
as
u128
,
bits
:
n
as
u128
,
size
:
self
.tcx.data_layout.pointer_size
.bytes
()
as
u8
,
size
:
self
.tcx.data_layout.pointer_size
.bytes
()
as
u8
,
}),
}
.into
()
),
self
.tcx
.layout_of
(
self
.param_env
.and
(
self
.tcx.types.usize
))
.ok
()
?
,
self
.tcx
.layout_of
(
self
.param_env
.and
(
self
.tcx.types.usize
))
.ok
()
?
,
span
,
span
,
)))
)))
...
@@ -391,7 +391,7 @@ fn const_prop(
...
@@ -391,7 +391,7 @@ fn const_prop(
this
.ecx
.value_to_scalar
(
ValTy
{
value
:
val
.0
,
ty
:
val
.1
.ty
})
this
.ecx
.value_to_scalar
(
ValTy
{
value
:
val
.0
,
ty
:
val
.1
.ty
})
})
?
;
})
?
;
let
val
=
self
.use_ecx
(
source_info
,
|
this
|
this
.ecx
.unary_op
(
op
,
prim
,
val
.1
))
?
;
let
val
=
self
.use_ecx
(
source_info
,
|
this
|
this
.ecx
.unary_op
(
op
,
prim
,
val
.1
))
?
;
Some
((
Value
::
Scalar
(
val
),
place_layout
,
span
))
Some
((
Value
::
Scalar
(
val
.into
()
),
place_layout
,
span
))
}
}
Rvalue
::
CheckedBinaryOp
(
op
,
ref
left
,
ref
right
)
|
Rvalue
::
CheckedBinaryOp
(
op
,
ref
left
,
ref
right
)
|
Rvalue
::
BinaryOp
(
op
,
ref
left
,
ref
right
)
=>
{
Rvalue
::
BinaryOp
(
op
,
ref
left
,
ref
right
)
=>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录