Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
7728de3e
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,发现更多精彩内容 >>
提交
7728de3e
编写于
10月 16, 2016
作者:
S
Scott Olson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Do not force_allocate checked binop destination.
上级
3f67c461
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
27 addition
and
48 deletion
+27
-48
src/interpreter/mod.rs
src/interpreter/mod.rs
+20
-21
src/interpreter/terminator/intrinsics.rs
src/interpreter/terminator/intrinsics.rs
+7
-27
未找到文件。
src/interpreter/mod.rs
浏览文件 @
7728de3e
...
...
@@ -394,6 +394,17 @@ fn pop_stack_frame(&mut self) -> EvalResult<'tcx, ()> {
Ok
(())
}
fn
binop_with_overflow
(
&
mut
self
,
op
:
mir
::
BinOp
,
left
:
&
mir
::
Operand
<
'tcx
>
,
right
:
&
mir
::
Operand
<
'tcx
>
,
)
->
EvalResult
<
'tcx
,
(
PrimVal
,
bool
)
>
{
let
left_primval
=
self
.eval_operand_to_primval
(
left
)
?
;
let
right_primval
=
self
.eval_operand_to_primval
(
right
)
?
;
primval
::
binary_op
(
op
,
left_primval
,
right_primval
)
}
/// Applies the binary operation `op` to the two operands and writes a tuple of the result
/// and a boolean signifying the potential overflow to the destination.
fn
intrinsic_with_overflow
(
...
...
@@ -402,25 +413,15 @@ fn intrinsic_with_overflow(
left
:
&
mir
::
Operand
<
'tcx
>
,
right
:
&
mir
::
Operand
<
'tcx
>
,
dest
:
Lvalue
,
dest_
layout
:
&
'tcx
Layout
,
dest_
ty
:
Ty
<
'tcx
>
,
)
->
EvalResult
<
'tcx
,
()
>
{
use
rustc
::
ty
::
layout
::
Layout
::
*
;
let
tup_layout
=
match
*
dest_layout
{
Univariant
{
ref
variant
,
..
}
=>
variant
,
_
=>
bug!
(
"checked bin op returns something other than a tuple"
),
};
let
overflowed
=
self
.intrinsic_overflowing
(
op
,
left
,
right
,
dest
)
?
;
// FIXME(solson)
let
dest
=
self
.force_allocation
(
dest
)
?
.to_ptr
();
let
offset
=
tup_layout
.offsets
[
1
]
.bytes
()
as
isize
;
self
.memory
.write_bool
(
dest
.offset
(
offset
),
overflowed
)
let
(
val
,
overflowed
)
=
self
.binop_with_overflow
(
op
,
left
,
right
)
?
;
let
val
=
Value
::
ByValPair
(
val
,
PrimVal
::
Bool
(
overflowed
));
self
.write_value
(
val
,
dest
,
dest_ty
)
}
/// Applies the binary operation `op` to the arguments and writes the result to the
destination.
/// Returns `true` if the operation overflowed.
/// Applies the binary operation `op` to the arguments and writes the result to the
///
destination.
Returns `true` if the operation overflowed.
fn
intrinsic_overflowing
(
&
mut
self
,
op
:
mir
::
BinOp
,
...
...
@@ -428,11 +429,9 @@ fn intrinsic_overflowing(
right
:
&
mir
::
Operand
<
'tcx
>
,
dest
:
Lvalue
,
)
->
EvalResult
<
'tcx
,
bool
>
{
let
left_primval
=
self
.eval_operand_to_primval
(
left
)
?
;
let
right_primval
=
self
.eval_operand_to_primval
(
right
)
?
;
let
(
val
,
overflow
)
=
primval
::
binary_op
(
op
,
left_primval
,
right_primval
)
?
;
let
(
val
,
overflowed
)
=
self
.binop_with_overflow
(
op
,
left
,
right
)
?
;
self
.write_primval
(
dest
,
val
)
?
;
Ok
(
overflow
)
Ok
(
overflow
ed
)
}
fn
assign_fields
<
I
:
IntoIterator
<
Item
=
u64
>>
(
...
...
@@ -479,7 +478,7 @@ fn eval_rvalue_into_lvalue(
}
CheckedBinaryOp
(
bin_op
,
ref
left
,
ref
right
)
=>
{
self
.intrinsic_with_overflow
(
bin_op
,
left
,
right
,
dest
,
dest_
layout
)
?
;
self
.intrinsic_with_overflow
(
bin_op
,
left
,
right
,
dest
,
dest_
ty
)
?
;
}
UnaryOp
(
un_op
,
ref
operand
)
=>
{
...
...
src/interpreter/terminator/intrinsics.rs
浏览文件 @
7728de3e
...
...
@@ -31,35 +31,15 @@ pub(super) fn call_intrinsic(
let
intrinsic_name
=
&
self
.tcx
.item_name
(
def_id
)
.as_str
()[
..
];
match
intrinsic_name
{
"add_with_overflow"
=>
{
self
.intrinsic_with_overflow
(
mir
::
BinOp
::
Add
,
&
args
[
0
],
&
args
[
1
],
dest
,
dest_layout
,
)
?
}
"add_with_overflow"
=>
self
.intrinsic_with_overflow
(
mir
::
BinOp
::
Add
,
&
args
[
0
],
&
args
[
1
],
dest
,
dest_ty
)
?
,
"sub_with_overflow"
=>
{
self
.intrinsic_with_overflow
(
mir
::
BinOp
::
Sub
,
&
args
[
0
],
&
args
[
1
],
dest
,
dest_layout
,
)
?
}
"sub_with_overflow"
=>
self
.intrinsic_with_overflow
(
mir
::
BinOp
::
Sub
,
&
args
[
0
],
&
args
[
1
],
dest
,
dest_ty
)
?
,
"mul_with_overflow"
=>
self
.intrinsic_with_overflow
(
mir
::
BinOp
::
Mul
,
&
args
[
0
],
&
args
[
1
],
dest
,
dest_ty
)
?
,
"mul_with_overflow"
=>
{
self
.intrinsic_with_overflow
(
mir
::
BinOp
::
Mul
,
&
args
[
0
],
&
args
[
1
],
dest
,
dest_layout
,
)
?
}
"arith_offset"
=>
{
let
ptr
=
args_ptrs
[
0
]
.read_ptr
(
&
self
.memory
)
?
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录