Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
98cda6cb
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,发现更多精彩内容 >>
提交
98cda6cb
编写于
2月 07, 2017
作者:
O
Oliver Schneider
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
freeze -> static
上级
fd3bbfde
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
10 addition
and
12 deletion
+10
-12
src/error.rs
src/error.rs
+2
-2
src/eval_context.rs
src/eval_context.rs
+4
-6
src/memory.rs
src/memory.rs
+3
-3
tests/compile-fail/modifying_constants.rs
tests/compile-fail/modifying_constants.rs
+1
-1
未找到文件。
src/error.rs
浏览文件 @
98cda6cb
...
...
@@ -119,9 +119,9 @@ fn description(&self) -> &str {
EvalError
::
TypeNotPrimitive
(
_
)
=>
"expected primitive type, got nonprimitive"
,
EvalError
::
ReallocatedStaticMemory
=>
"tried to reallocate
frozen
memory"
,
"tried to reallocate
static
memory"
,
EvalError
::
DeallocatedStaticMemory
=>
"tried to deallocate
frozen
memory"
,
"tried to deallocate
static
memory"
,
EvalError
::
Layout
(
_
)
=>
"rustc layout computation failed"
,
EvalError
::
UnterminatedCString
(
_
)
=>
...
...
src/eval_context.rs
浏览文件 @
98cda6cb
...
...
@@ -314,7 +314,7 @@ pub(super) fn pop_stack_frame(&mut self) -> EvalResult<'tcx> {
match
frame
.return_to_block
{
StackPopCleanup
::
MarkStatic
(
mutable
)
=>
if
let
Lvalue
::
Global
(
id
)
=
frame
.return_lvalue
{
let
global_value
=
self
.globals
.get_mut
(
&
id
)
.expect
(
"global should have been cached (
freeze/
static)"
);
.expect
(
"global should have been cached (static)"
);
match
global_value
.value
{
Value
::
ByRef
(
ptr
)
=>
self
.memory
.mark_static
(
ptr
.alloc_id
,
mutable
)
?
,
Value
::
ByVal
(
val
)
=>
if
let
PrimVal
::
Ptr
(
ptr
)
=
val
{
...
...
@@ -332,7 +332,7 @@ pub(super) fn pop_stack_frame(&mut self) -> EvalResult<'tcx> {
assert
!
(
global_value
.mutable
);
global_value
.mutable
=
mutable
;
}
else
{
bug!
(
"StackPopCleanup::
Freeze
on: {:?}"
,
frame
.return_lvalue
);
bug!
(
"StackPopCleanup::
MarkStatic
on: {:?}"
,
frame
.return_lvalue
);
},
StackPopCleanup
::
Goto
(
target
)
=>
self
.goto_block
(
target
),
StackPopCleanup
::
None
=>
{},
...
...
@@ -343,10 +343,8 @@ pub(super) fn pop_stack_frame(&mut self) -> EvalResult<'tcx> {
trace!
(
"deallocating local"
);
self
.memory
.dump_alloc
(
ptr
.alloc_id
);
match
self
.memory
.deallocate
(
ptr
)
{
// Any frozen memory means that it belongs to a constant or something referenced
// by a constant. We could alternatively check whether the alloc_id is frozen
// before calling deallocate, but this is much simpler and is probably the
// rare case.
// We could alternatively check whether the alloc_id is static before calling
// deallocate, but this is much simpler and is probably the rare case.
Ok
(())
|
Err
(
EvalError
::
DeallocatedStaticMemory
)
=>
{},
other
=>
return
other
,
}
...
...
src/memory.rs
浏览文件 @
98cda6cb
...
...
@@ -39,7 +39,7 @@ pub struct Allocation {
pub
align
:
u64
,
/// Whether the allocation may be modified.
/// Use the `mark_static` method of `Memory` to ensure that an error occurs, if the memory of this
/// allocation is modified in the future.
/// allocation is modified
or deallocated
in the future.
pub
static_kind
:
StaticKind
,
}
...
...
@@ -626,7 +626,7 @@ fn get_bytes_mut(&mut self, ptr: Pointer, size: u64, align: u64) -> EvalResult<'
impl
<
'a
,
'tcx
>
Memory
<
'a
,
'tcx
>
{
/// mark an allocation as static, either mutable or not
pub
fn
mark_static
(
&
mut
self
,
alloc_id
:
AllocId
,
mutable
:
bool
)
->
EvalResult
<
'tcx
>
{
// do not use `self.get_mut(alloc_id)` here, because we might have already
frozen
a
// 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
,
static_kind
:
ref
mut
kind
@
StaticKind
::
NotStatic
,
..
})
=>
{
...
...
@@ -636,7 +636,7 @@ pub fn mark_static(&mut self, alloc_id: AllocId, mutable: bool) -> EvalResult<'t
StaticKind
::
Immutable
};
// take out the relocations vector to free the borrow on self, so we can call
//
freeze
recursively
//
mark
recursively
mem
::
replace
(
relocations
,
Default
::
default
())
},
None
if
alloc_id
==
NEVER_ALLOC_ID
||
alloc_id
==
ZST_ALLOC_ID
=>
return
Ok
(()),
...
...
tests/compile-fail/modifying_constants.rs
浏览文件 @
98cda6cb
fn
main
()
{
let
x
=
&
1
;
// the `&1` is promoted to a constant, but it used to be that only the pointer is
frozen
, not the pointee
let
x
=
&
1
;
// the `&1` is promoted to a constant, but it used to be that only the pointer is
marked static
, not the pointee
let
y
=
unsafe
{
&
mut
*
(
x
as
*
const
i32
as
*
mut
i32
)
};
*
y
=
42
;
//~ ERROR tried to modify constant memory
assert_eq!
(
*
x
,
42
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录