Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
6e66f586
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,发现更多精彩内容 >>
提交
6e66f586
编写于
2月 16, 2020
作者:
R
Ralf Jung
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fmt
上级
b133d677
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
28 addition
and
29 deletion
+28
-29
src/librustc_codegen_ssa/mir/block.rs
src/librustc_codegen_ssa/mir/block.rs
+10
-6
src/librustc_target/abi/mod.rs
src/librustc_target/abi/mod.rs
+15
-19
src/librustc_typeck/check/intrinsic.rs
src/librustc_typeck/check/intrinsic.rs
+3
-4
未找到文件。
src/librustc_codegen_ssa/mir/block.rs
浏览文件 @
6e66f586
...
...
@@ -524,13 +524,17 @@ fn codegen_call_terminator(
// These are intrinsics that compile to panics so that we can get a message
// which mentions the offending type, even from a const context.
#[derive(Debug,
PartialEq)]
enum
PanicIntrinsic
{
IfUninhabited
,
IfZeroInvalid
,
IfAnyInvalid
};
enum
PanicIntrinsic
{
IfUninhabited
,
IfZeroInvalid
,
IfAnyInvalid
,
};
let
panic_intrinsic
=
intrinsic
.and_then
(|
i
|
match
i
{
// FIXME: Move to symbols instead of strings.
"panic_if_uninhabited"
=>
Some
(
PanicIntrinsic
::
IfUninhabited
),
"panic_if_zero_invalid"
=>
Some
(
PanicIntrinsic
::
IfZeroInvalid
),
"panic_if_any_invalid"
=>
Some
(
PanicIntrinsic
::
IfAnyInvalid
),
_
=>
None
_
=>
None
,
});
if
let
Some
(
intrinsic
)
=
panic_intrinsic
{
use
PanicIntrinsic
::
*
;
...
...
@@ -538,10 +542,10 @@ fn codegen_call_terminator(
let
layout
=
bx
.layout_of
(
ty
);
let
do_panic
=
match
intrinsic
{
IfUninhabited
=>
layout
.abi
.is_uninhabited
(),
IfZeroInvalid
=>
// We unwrap as the error type is `!`.
!
layout
.might_permit_raw_init
(
&
bx
,
/*zero:*/
true
)
.unwrap
(),
IfAnyInvalid
=>
// We unwrap as the error type is `!`.
!
layout
.might_permit_raw_init
(
&
bx
,
/*zero:*/
false
)
.unwrap
(),
// We unwrap as the error type is `!`.
IfZeroInvalid
=>
!
layout
.might_permit_raw_init
(
&
bx
,
/*zero:*/
true
)
.unwrap
(),
// We unwrap as the error type is `!`.
IfAnyInvalid
=>
!
layout
.might_permit_raw_init
(
&
bx
,
/*zero:*/
false
)
.unwrap
(),
};
if
do_panic
{
let
msg_str
=
if
layout
.abi
.is_uninhabited
()
{
...
...
src/librustc_target/abi/mod.rs
浏览文件 @
6e66f586
...
...
@@ -1047,22 +1047,17 @@ pub fn is_zst(&self) -> bool {
/// FIXME: Once we removed all the conservatism, we could alternatively
/// create an all-0/all-undef constant and run the vonst value validator to see if
/// this is a valid value for the given type.
pub
fn
might_permit_raw_init
<
C
,
E
>
(
self
,
cx
:
&
C
,
zero
:
bool
,
)
->
Result
<
bool
,
E
>
pub
fn
might_permit_raw_init
<
C
,
E
>
(
self
,
cx
:
&
C
,
zero
:
bool
)
->
Result
<
bool
,
E
>
where
Self
:
Copy
,
Ty
:
TyLayoutMethods
<
'a
,
C
>
,
C
:
LayoutOf
<
Ty
=
Ty
,
TyLayout
:
MaybeResult
<
Self
,
Error
=
E
>>
+
HasDataLayout
C
:
LayoutOf
<
Ty
=
Ty
,
TyLayout
:
MaybeResult
<
Self
,
Error
=
E
>>
+
HasDataLayout
,
{
let
scalar_allows_raw_init
=
move
|
s
:
&
Scalar
|
->
bool
{
if
zero
{
let
range
=
&
s
.valid_range
;
// The range must contain 0.
range
.contains
(
&
0
)
||
(
*
range
.start
()
>
*
range
.end
())
// wrap-around allows 0
range
.contains
(
&
0
)
||
(
*
range
.start
()
>
*
range
.end
())
// wrap-around allows 0
}
else
{
// The range must include all values. `valid_range_exclusive` handles
// the wrap-around using target arithmetic; with wrap-around then the full
...
...
@@ -1076,13 +1071,11 @@ pub fn might_permit_raw_init<C, E>(
let
res
=
match
&
self
.abi
{
Abi
::
Uninhabited
=>
false
,
// definitely UB
Abi
::
Scalar
(
s
)
=>
scalar_allows_raw_init
(
s
),
Abi
::
ScalarPair
(
s1
,
s2
)
=>
scalar_allows_raw_init
(
s1
)
&&
scalar_allows_raw_init
(
s2
),
Abi
::
Vector
{
element
:
s
,
count
}
=>
*
count
==
0
||
scalar_allows_raw_init
(
s
),
Abi
::
ScalarPair
(
s1
,
s2
)
=>
scalar_allows_raw_init
(
s1
)
&&
scalar_allows_raw_init
(
s2
),
Abi
::
Vector
{
element
:
s
,
count
}
=>
*
count
==
0
||
scalar_allows_raw_init
(
s
),
Abi
::
Aggregate
{
..
}
=>
{
match
self
.variants
{
Variants
::
Multiple
{
..
}
=>
Variants
::
Multiple
{
..
}
=>
{
if
zero
{
// FIXME(#66151):
// could we identify the variant with discriminant 0, check that?
...
...
@@ -1091,17 +1084,20 @@ pub fn might_permit_raw_init<C, E>(
// FIXME(#66151): This needs to have some sort of discriminant,
// which cannot be undef. But for now we are conservative.
true
},
}
}
Variants
::
Single
{
..
}
=>
{
// For aggregates, recurse.
match
self
.fields
{
FieldPlacement
::
Union
(
..
)
=>
true
,
// An all-0 unit is fine.
FieldPlacement
::
Array
{
..
}
=>
// FIXME(#66151): The widely use smallvec 0.6 creates uninit arrays
// with any element type, so let us not (yet) complain about that.
/* count == 0 ||
self.field(cx, 0).to_result()?.might_permit_raw_init(cx, zero)? */
true
,
// FIXME(#66151): The widely use smallvec 0.6 creates uninit arrays
// with any element type, so let us not (yet) complain about that.
/* count == 0 ||
self.field(cx, 0).to_result()?.might_permit_raw_init(cx, zero)? */
{
true
}
FieldPlacement
::
Arbitrary
{
..
}
=>
{
// FIXME(#66151) cargo depends on sized-chunks 0.3.0 which
// has some illegal zero-initialization, so let us not (yet)
...
...
src/librustc_typeck/check/intrinsic.rs
浏览文件 @
6e66f586
...
...
@@ -147,10 +147,9 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
),
"rustc_peek"
=>
(
1
,
vec!
[
param
(
0
)],
param
(
0
)),
"caller_location"
=>
(
0
,
vec!
[],
tcx
.caller_location_ty
()),
"panic_if_uninhabited"
|
"panic_if_zero_invalid"
|
"panic_if_any_invalid"
=>
(
1
,
Vec
::
new
(),
tcx
.mk_unit
()),
"panic_if_uninhabited"
|
"panic_if_zero_invalid"
|
"panic_if_any_invalid"
=>
{
(
1
,
Vec
::
new
(),
tcx
.mk_unit
())
}
"init"
=>
(
1
,
Vec
::
new
(),
param
(
0
)),
"uninit"
=>
(
1
,
Vec
::
new
(),
param
(
0
)),
"forget"
=>
(
1
,
vec!
[
param
(
0
)],
tcx
.mk_unit
()),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录