Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
372afcf9
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,发现更多精彩内容 >>
提交
372afcf9
编写于
3月 25, 2021
作者:
B
bors
浏览文件
操作
浏览文件
下载
差异文件
Auto merge of #83445 - erikdesjardins:rmunion, r=RalfJung
RemoveZsts: don't touch unions This should fix a Miri ICE r? `@RalfJung`
上级
dbc37a97
d5c1ad5c
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
65 addition
and
1 deletion
+65
-1
compiler/rustc_mir/src/transform/remove_zsts.rs
compiler/rustc_mir/src/transform/remove_zsts.rs
+33
-1
src/test/mir-opt/remove_zsts_dont_touch_unions.get_union.RemoveZsts.after.mir
...ove_zsts_dont_touch_unions.get_union.RemoveZsts.after.mir
+13
-0
src/test/mir-opt/remove_zsts_dont_touch_unions.rs
src/test/mir-opt/remove_zsts_dont_touch_unions.rs
+19
-0
未找到文件。
compiler/rustc_mir/src/transform/remove_zsts.rs
浏览文件 @
372afcf9
//! Removes assignments to ZST places.
use
crate
::
transform
::
MirPass
;
use
rustc_middle
::
mir
::{
Body
,
StatementKind
};
use
rustc_middle
::
mir
::
tcx
::
PlaceTy
;
use
rustc_middle
::
mir
::{
Body
,
LocalDecls
,
Place
,
StatementKind
};
use
rustc_middle
::
ty
::{
self
,
Ty
,
TyCtxt
};
pub
struct
RemoveZsts
;
...
...
@@ -28,6 +29,9 @@ fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
if
!
layout
.is_zst
()
{
continue
;
}
if
involves_a_union
(
place
,
local_decls
,
tcx
)
{
continue
;
}
if
tcx
.consider_optimizing
(||
{
format!
(
"RemoveZsts - Place: {:?} SourceInfo: {:?}"
,
...
...
@@ -55,3 +59,31 @@ fn maybe_zst(ty: Ty<'_>) -> bool {
_
=>
false
,
}
}
/// Miri lazily allocates memory for locals on assignment,
/// so we must preserve writes to unions and union fields,
/// or it will ICE on reads of those fields.
fn
involves_a_union
<
'tcx
>
(
place
:
Place
<
'tcx
>
,
local_decls
:
&
LocalDecls
<
'tcx
>
,
tcx
:
TyCtxt
<
'tcx
>
,
)
->
bool
{
let
mut
place_ty
=
PlaceTy
::
from_ty
(
local_decls
[
place
.local
]
.ty
);
if
is_union
(
place_ty
.ty
)
{
return
true
;
}
for
elem
in
place
.projection
{
place_ty
=
place_ty
.projection_ty
(
tcx
,
elem
);
if
is_union
(
place_ty
.ty
)
{
return
true
;
}
}
return
false
;
}
fn
is_union
(
ty
:
Ty
<
'_
>
)
->
bool
{
match
ty
.kind
()
{
ty
::
Adt
(
def
,
_
)
if
def
.is_union
()
=>
true
,
_
=>
false
,
}
}
src/test/mir-opt/remove_zsts_dont_touch_unions.get_union.RemoveZsts.after.mir
0 → 100644
浏览文件 @
372afcf9
// MIR for `get_union` after RemoveZsts
fn get_union() -> Foo {
let mut _0: Foo; // return place in scope 0 at $DIR/remove_zsts_dont_touch_unions.rs:12:19: 12:22
let mut _1: (); // in scope 0 at $DIR/remove_zsts_dont_touch_unions.rs:13:14: 13:16
bb0: {
StorageLive(_1); // scope 0 at $DIR/remove_zsts_dont_touch_unions.rs:13:14: 13:16
(_0.0: ()) = move _1; // scope 0 at $DIR/remove_zsts_dont_touch_unions.rs:13:5: 13:18
StorageDead(_1); // scope 0 at $DIR/remove_zsts_dont_touch_unions.rs:13:17: 13:18
return; // scope 0 at $DIR/remove_zsts_dont_touch_unions.rs:14:2: 14:2
}
}
src/test/mir-opt/remove_zsts_dont_touch_unions.rs
0 → 100644
浏览文件 @
372afcf9
// compile-flags: -Zmir-opt-level=3
// Ensure RemoveZsts doesn't remove ZST assignments to union fields,
// which causes problems in Miri.
union
Foo
{
x
:
(),
y
:
u64
,
}
// EMIT_MIR remove_zsts_dont_touch_unions.get_union.RemoveZsts.after.mir
fn
get_union
()
->
Foo
{
Foo
{
x
:
()
}
}
fn
main
()
{
get_union
();
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录