Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
cf29344c
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,发现更多精彩内容 >>
提交
cf29344c
编写于
3月 04, 2016
作者:
A
Ariel Ben-Yehuda
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
truncate i8-s to i1-s when loading constants
Fixes #30891
上级
b9e61c9f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
36 addition
and
9 deletion
+36
-9
src/librustc_trans/trans/consts.rs
src/librustc_trans/trans/consts.rs
+17
-9
src/test/run-pass/issue-30891.rs
src/test/run-pass/issue-30891.rs
+19
-0
未找到文件。
src/librustc_trans/trans/consts.rs
浏览文件 @
cf29344c
...
...
@@ -161,13 +161,17 @@ pub fn addr_of(ccx: &CrateContext,
gv
}
fn
const_deref_ptr
(
cx
:
&
CrateContext
,
v
:
ValueRef
)
->
ValueRef
{
/// Deref a constant pointer
fn
load_const
(
cx
:
&
CrateContext
,
v
:
ValueRef
,
t
:
Ty
)
->
ValueRef
{
let
v
=
match
cx
.const_unsized
()
.borrow
()
.get
(
&
v
)
{
Some
(
&
v
)
=>
v
,
None
=>
v
};
unsafe
{
llvm
::
LLVMGetInitializer
(
v
)
let
d
=
unsafe
{
llvm
::
LLVMGetInitializer
(
v
)
};
if
t
.is_bool
()
{
unsafe
{
llvm
::
LLVMConstTrunc
(
d
,
Type
::
i1
(
cx
)
.to_ref
())
}
}
else
{
d
}
}
...
...
@@ -178,7 +182,7 @@ fn const_deref<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
match
ty
.builtin_deref
(
true
,
ty
::
NoPreference
)
{
Some
(
mt
)
=>
{
if
type_is_sized
(
cx
.tcx
(),
mt
.ty
)
{
(
const_deref_ptr
(
cx
,
v
),
mt
.ty
)
(
load_const
(
cx
,
v
,
mt
.ty
),
mt
.ty
)
}
else
{
// Derefing a fat pointer does not change the representation,
// just the type to the unsized contents.
...
...
@@ -588,7 +592,10 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
let
is_float
=
ty
.is_fp
();
let
signed
=
ty
.is_signed
();
let
(
te2
,
_
)
=
try!
(
const_expr
(
cx
,
&
e2
,
param_substs
,
fn_args
,
trueconst
));
let
(
te2
,
ty2
)
=
try!
(
const_expr
(
cx
,
&
e2
,
param_substs
,
fn_args
,
trueconst
));
debug!
(
"const_expr_unadjusted: te2={}, ty={:?}"
,
cx
.tn
()
.val_to_string
(
te2
),
ty2
);
try!
(
check_binary_expr_validity
(
cx
,
e
,
ty
,
te1
,
te2
,
trueconst
));
...
...
@@ -671,13 +678,13 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
};
let
(
arr
,
len
)
=
match
bt
.sty
{
ty
::
TyArray
(
_
,
u
)
=>
(
bv
,
C_uint
(
cx
,
u
)),
ty
::
TySlice
(
_
)
|
ty
::
TyStr
=>
{
ty
::
TySlice
(
..
)
|
ty
::
TyStr
=>
{
let
e1
=
const_get_elt
(
cx
,
bv
,
&
[
0
]);
(
const_deref_ptr
(
cx
,
e1
),
const_get_elt
(
cx
,
bv
,
&
[
1
]))
(
load_const
(
cx
,
e1
,
bt
),
const_get_elt
(
cx
,
bv
,
&
[
1
]))
},
ty
::
TyRef
(
_
,
mt
)
=>
match
mt
.ty.sty
{
ty
::
TyArray
(
_
,
u
)
=>
{
(
const_deref_ptr
(
cx
,
bv
),
C_uint
(
cx
,
u
))
(
load_const
(
cx
,
bv
,
mt
.ty
),
C_uint
(
cx
,
u
))
},
_
=>
cx
.sess
()
.span_bug
(
base
.span
,
&
format!
(
"index-expr base must be a vector
\
...
...
@@ -891,7 +898,8 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
expr
::
trans_def_fn_unadjusted
(
cx
,
e
,
def
,
param_substs
)
.val
}
Def
::
Const
(
def_id
)
|
Def
::
AssociatedConst
(
def_id
)
=>
{
const_deref_ptr
(
cx
,
try!
(
get_const_val
(
cx
,
def_id
,
e
,
param_substs
)))
load_const
(
cx
,
try!
(
get_const_val
(
cx
,
def_id
,
e
,
param_substs
)),
ety
)
}
Def
::
Variant
(
enum_did
,
variant_did
)
=>
{
let
vinfo
=
cx
.tcx
()
.lookup_adt_def
(
enum_did
)
.variant_with_id
(
variant_did
);
...
...
src/test/run-pass/issue-30891.rs
0 → 100644
浏览文件 @
cf29344c
// Copyright 2016 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.
const
ERROR_CONST
:
bool
=
true
;
fn
get
()
->
bool
{
false
||
ERROR_CONST
}
pub
fn
main
()
{
assert_eq!
(
get
(),
true
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录