Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
ffd482e2
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,发现更多精彩内容 >>
提交
ffd482e2
编写于
7月 03, 2017
作者:
R
Ralf Jung
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
check the assumptions made by the unchecked_ and copy_nonoverlapping intrinsics
上级
f118ff43
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
85 addition
and
6 deletion
+85
-6
src/eval_context.rs
src/eval_context.rs
+1
-1
src/memory.rs
src/memory.rs
+7
-1
src/terminator/intrinsic.rs
src/terminator/intrinsic.rs
+11
-4
tests/compile-fail/copy_nonoverlapping.rs
tests/compile-fail/copy_nonoverlapping.rs
+24
-0
tests/compile-fail/div-by-zero.rs
tests/compile-fail/div-by-zero.rs
+21
-0
tests/compile-fail/overflowing-unchecked-rsh.rs
tests/compile-fail/overflowing-unchecked-rsh.rs
+21
-0
未找到文件。
src/eval_context.rs
浏览文件 @
ffd482e2
...
...
@@ -1022,7 +1022,7 @@ pub(super) fn operand_ty(&self, operand: &mir::Operand<'tcx>) -> Ty<'tcx> {
fn
copy
(
&
mut
self
,
src
:
PrimVal
,
dest
:
PrimVal
,
ty
:
Ty
<
'tcx
>
)
->
EvalResult
<
'tcx
>
{
let
size
=
self
.type_size
(
ty
)
?
.expect
(
"cannot copy from an unsized type"
);
let
align
=
self
.type_align
(
ty
)
?
;
self
.memory
.copy
(
src
,
dest
,
size
,
align
)
?
;
self
.memory
.copy
(
src
,
dest
,
size
,
align
,
false
)
?
;
Ok
(())
}
...
...
src/memory.rs
浏览文件 @
ffd482e2
...
...
@@ -658,7 +658,7 @@ pub fn mark_static_initalized(&mut self, alloc_id: AllocId, mutable: bool) -> Ev
Ok
(())
}
pub
fn
copy
(
&
mut
self
,
src
:
PrimVal
,
dest
:
PrimVal
,
size
:
u64
,
align
:
u64
)
->
EvalResult
<
'tcx
>
{
pub
fn
copy
(
&
mut
self
,
src
:
PrimVal
,
dest
:
PrimVal
,
size
:
u64
,
align
:
u64
,
nonoverlapping
:
bool
)
->
EvalResult
<
'tcx
>
{
if
size
==
0
{
return
Ok
(());
}
...
...
@@ -675,6 +675,12 @@ pub fn copy(&mut self, src: PrimVal, dest: PrimVal, size: u64, align: u64) -> Ev
unsafe
{
assert_eq!
(
size
as
usize
as
u64
,
size
);
if
src
.alloc_id
==
dest
.alloc_id
{
if
nonoverlapping
{
if
(
src
.offset
<=
dest
.offset
&&
src
.offset
+
size
>
dest
.offset
)
||
(
dest
.offset
<=
src
.offset
&&
dest
.offset
+
size
>
src
.offset
)
{
return
Err
(
EvalError
::
Intrinsic
(
format!
(
"copy_nonoverlapping called on overlapping ranges"
)));
}
}
ptr
::
copy
(
src_bytes
,
dest_bytes
,
size
as
usize
);
}
else
{
ptr
::
copy_nonoverlapping
(
src_bytes
,
dest_bytes
,
size
as
usize
);
...
...
src/terminator/intrinsic.rs
浏览文件 @
ffd482e2
...
...
@@ -140,7 +140,6 @@ pub(super) fn call_intrinsic(
"copy"
|
"copy_nonoverlapping"
=>
{
// FIXME: check whether overlapping occurs
let
elem_ty
=
substs
.type_at
(
0
);
let
elem_size
=
self
.type_size
(
elem_ty
)
?
.expect
(
"cannot copy unsized value"
);
if
elem_size
!=
0
{
...
...
@@ -148,7 +147,7 @@ pub(super) fn call_intrinsic(
let
src
=
arg_vals
[
0
]
.read_ptr
(
&
self
.memory
)
?
;
let
dest
=
arg_vals
[
1
]
.read_ptr
(
&
self
.memory
)
?
;
let
count
=
self
.value_to_primval
(
arg_vals
[
2
],
usize
)
?
.to_u64
()
?
;
self
.memory
.copy
(
src
,
dest
,
count
*
elem_size
,
elem_align
)
?
;
self
.memory
.copy
(
src
,
dest
,
count
*
elem_size
,
elem_align
,
intrinsic_name
.ends_with
(
"_nonoverlapping"
)
)
?
;
}
}
...
...
@@ -408,12 +407,20 @@ pub(super) fn call_intrinsic(
}
"unchecked_shl"
=>
{
// FIXME Check for too-wide shifts
let
bits
=
self
.type_size
(
dest_ty
)
?
.expect
(
"intrinsic can't be called on unsized type"
)
as
u128
*
8
;
let
rhs
=
self
.value_to_primval
(
arg_vals
[
1
],
substs
.type_at
(
0
))
?
.to_bytes
()
?
;
if
rhs
>=
bits
{
return
Err
(
EvalError
::
Intrinsic
(
format!
(
"Overflowing shift by {} in unchecked_shl"
,
rhs
)));
}
self
.intrinsic_overflowing
(
mir
::
BinOp
::
Shl
,
&
args
[
0
],
&
args
[
1
],
dest
,
dest_ty
)
?
;
}
"unchecked_shr"
=>
{
// FIXME Check for too-wide shifts
let
bits
=
self
.type_size
(
dest_ty
)
?
.expect
(
"intrinsic can't be called on unsized type"
)
as
u128
*
8
;
let
rhs
=
self
.value_to_primval
(
arg_vals
[
1
],
substs
.type_at
(
0
))
?
.to_bytes
()
?
;
if
rhs
>=
bits
{
return
Err
(
EvalError
::
Intrinsic
(
format!
(
"Overflowing shift by {} in unchecked_shr"
,
rhs
)));
}
self
.intrinsic_overflowing
(
mir
::
BinOp
::
Shr
,
&
args
[
0
],
&
args
[
1
],
dest
,
dest_ty
)
?
;
}
...
...
tests/compile-fail/copy_nonoverlapping.rs
0 → 100644
浏览文件 @
ffd482e2
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(core_intrinsics)]
use
std
::
intrinsics
::
*
;
//error-pattern: copy_nonoverlapping called on overlapping ranges
fn
main
()
{
let
mut
data
=
[
0u8
;
16
];
unsafe
{
let
a
=
&
data
[
0
]
as
*
const
_
;
let
b
=
&
mut
data
[
1
]
as
*
mut
_
;
std
::
ptr
::
copy_nonoverlapping
(
a
,
b
,
2
);
}
}
tests/compile-fail/div-by-zero.rs
0 → 100644
浏览文件 @
ffd482e2
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(core_intrinsics)]
use
std
::
intrinsics
::
*
;
//error-pattern: Division by 0 in unchecked_div
fn
main
()
{
unsafe
{
let
_
n
=
unchecked_div
(
1i64
,
0
);
}
}
tests/compile-fail/overflowing-unchecked-rsh.rs
0 → 100644
浏览文件 @
ffd482e2
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(core_intrinsics)]
use
std
::
intrinsics
::
*
;
//error-pattern: Overflowing shift by 64 in unchecked_shr
fn
main
()
{
unsafe
{
let
_
n
=
unchecked_shr
(
1i64
,
64
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录