Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
2e562a4d
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,发现更多精彩内容 >>
未验证
提交
2e562a4d
编写于
7月 13, 2017
作者:
O
Oliver Schneider
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix static mutation tests
上级
7701ff2f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
25 addition
and
6 deletion
+25
-6
src/eval_context.rs
src/eval_context.rs
+1
-1
src/memory.rs
src/memory.rs
+20
-3
src/traits.rs
src/traits.rs
+1
-1
tests/compile-fail/stack_free.rs
tests/compile-fail/stack_free.rs
+3
-1
未找到文件。
src/eval_context.rs
浏览文件 @
2e562a4d
...
...
@@ -414,7 +414,7 @@ pub fn deallocate_local(&mut self, local: Option<Value>) -> EvalResult<'tcx> {
let
ptr
=
ptr
.to_ptr
()
?
;
self
.memory
.dump_alloc
(
ptr
.alloc_id
);
match
self
.memory
.get
(
ptr
.alloc_id
)
?
.kind
{
::
memory
::
Kind
::
Static
=>
{},
::
memory
::
Kind
::
Static
|
::
memory
::
Kind
::
UninitializedStatic
=>
{},
::
memory
::
Kind
::
Stack
=>
self
.memory
.deallocate
(
ptr
,
None
,
::
memory
::
Kind
::
Stack
)
?
,
other
=>
bug!
(
"local contained non-stack memory: {:?}"
,
other
),
}
...
...
src/memory.rs
浏览文件 @
2e562a4d
...
...
@@ -193,9 +193,9 @@ pub fn allocate_cached(&mut self, bytes: &[u8]) -> EvalResult<'tcx, MemoryPointe
return
Ok
(
MemoryPointer
::
new
(
alloc_id
,
0
));
}
let
ptr
=
self
.allocate
(
bytes
.len
()
as
u64
,
1
,
Kind
::
Static
)
?
;
let
ptr
=
self
.allocate
(
bytes
.len
()
as
u64
,
1
,
Kind
::
Uninitialized
Static
)
?
;
self
.write_bytes
(
PrimVal
::
Ptr
(
ptr
),
bytes
)
?
;
self
.mark_static_initalized
(
ptr
.alloc_id
,
Mutability
::
M
utable
)
?
;
self
.mark_static_initalized
(
ptr
.alloc_id
,
Mutability
::
Imm
utable
)
?
;
self
.literal_alloc_cache
.insert
(
bytes
.to_vec
(),
ptr
.alloc_id
);
Ok
(
ptr
)
}
...
...
@@ -605,7 +605,24 @@ pub fn mark_static_initalized(&mut self, alloc_id: AllocId, mutability: Mutabili
// do not use `self.get_mut(alloc_id)` here, because we might have already marked a
// sub-element or have circular pointers (e.g. `Rc`-cycles)
let
relocations
=
match
self
.alloc_map
.get_mut
(
&
alloc_id
)
{
Some
(
&
mut
Allocation
{
ref
mut
relocations
,
kind
:
ref
mut
kind
@
Kind
::
UninitializedStatic
,
ref
mut
mutable
,
..
})
=>
{
Some
(
&
mut
Allocation
{
ref
mut
relocations
,
ref
mut
kind
,
ref
mut
mutable
,
..
})
=>
{
match
*
kind
{
// const eval results can refer to "locals".
// E.g. `const Foo: &u32 = &1;` refers to the temp local that stores the `1`
Kind
::
Stack
|
// The entire point of this function
Kind
::
UninitializedStatic
|
// In the future const eval will allow heap allocations so we'll need to protect them
// from deallocation, too
Kind
::
Rust
|
Kind
::
C
=>
{},
Kind
::
Static
=>
{
trace!
(
"mark_static_initalized: skipping already initialized static referred to by static currently being initialized"
);
return
Ok
(());
},
// FIXME: This could be allowed, but not for env vars set during miri execution
Kind
::
Env
=>
return
Err
(
EvalError
::
Unimplemented
(
"statics can't refer to env vars"
.to_owned
())),
}
*
kind
=
Kind
::
Static
;
*
mutable
=
mutability
;
// take out the relocations vector to free the borrow on self, so we can call
...
...
src/traits.rs
浏览文件 @
2e562a4d
...
...
@@ -51,7 +51,7 @@ pub fn get_vtable(&mut self, ty: Ty<'tcx>, trait_ref: ty::PolyTraitRef<'tcx>) ->
let
ptr_size
=
self
.memory
.pointer_size
();
let
methods
=
::
rustc
::
traits
::
get_vtable_methods
(
self
.tcx
,
trait_ref
);
let
vtable
=
self
.memory
.allocate
(
ptr_size
*
(
3
+
methods
.count
()
as
u64
),
ptr_size
,
Kind
::
Static
)
?
;
let
vtable
=
self
.memory
.allocate
(
ptr_size
*
(
3
+
methods
.count
()
as
u64
),
ptr_size
,
Kind
::
Uninitialized
Static
)
?
;
let
drop
=
::
eval_context
::
resolve_drop_in_place
(
self
.tcx
,
ty
);
let
drop
=
self
.memory
.create_fn_alloc
(
drop
);
...
...
tests/compile-fail/stack_free.rs
浏览文件 @
2e562a4d
// error-pattern: tried to deallocate Stack memory but gave Rust as the kind
fn
main
()
{
let
x
=
42
;
let
bad_box
=
unsafe
{
std
::
mem
::
transmute
::
<&
i32
,
Box
<
i32
>>
(
&
x
)
};
drop
(
bad_box
);
//~ ERROR tried to deallocate Stack memory but gave Rust as the kind
drop
(
bad_box
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录