Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
c977daf9
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,发现更多精彩内容 >>
提交
c977daf9
编写于
3月 02, 2017
作者:
E
Eduard-Mihai Burtescu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rustc_trans: avoid sizing_type_of everywhere possible.
上级
49872b85
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
53 addition
and
82 deletion
+53
-82
src/librustc_trans/abi.rs
src/librustc_trans/abi.rs
+3
-9
src/librustc_trans/adt.rs
src/librustc_trans/adt.rs
+6
-14
src/librustc_trans/base.rs
src/librustc_trans/base.rs
+4
-6
src/librustc_trans/common.rs
src/librustc_trans/common.rs
+2
-4
src/librustc_trans/consts.rs
src/librustc_trans/consts.rs
+1
-1
src/librustc_trans/debuginfo/metadata.rs
src/librustc_trans/debuginfo/metadata.rs
+1
-1
src/librustc_trans/debuginfo/mod.rs
src/librustc_trans/debuginfo/mod.rs
+1
-1
src/librustc_trans/glue.rs
src/librustc_trans/glue.rs
+7
-14
src/librustc_trans/intrinsic.rs
src/librustc_trans/intrinsic.rs
+7
-7
src/librustc_trans/meth.rs
src/librustc_trans/meth.rs
+2
-7
src/librustc_trans/mir/block.rs
src/librustc_trans/mir/block.rs
+2
-2
src/librustc_trans/mir/constant.rs
src/librustc_trans/mir/constant.rs
+6
-11
src/librustc_trans/mir/rvalue.rs
src/librustc_trans/mir/rvalue.rs
+1
-1
src/librustc_trans/type_of.rs
src/librustc_trans/type_of.rs
+10
-4
未找到文件。
src/librustc_trans/abi.rs
浏览文件 @
c977daf9
...
...
@@ -439,14 +439,10 @@ fn unadjusted<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
match
ret_ty
.sty
{
// These are not really pointers but pairs, (pointer, len)
ty
::
TyRef
(
_
,
ty
::
TypeAndMut
{
ty
,
..
})
=>
{
let
llty
=
type_of
::
sizing_type_of
(
ccx
,
ty
);
let
llsz
=
llsize_of_alloc
(
ccx
,
llty
);
ret
.attrs
.set_dereferenceable
(
llsz
);
ret
.attrs
.set_dereferenceable
(
ccx
.size_of
(
ty
));
}
ty
::
TyAdt
(
def
,
_
)
if
def
.is_box
()
=>
{
let
llty
=
type_of
::
sizing_type_of
(
ccx
,
ret_ty
.boxed_ty
());
let
llsz
=
llsize_of_alloc
(
ccx
,
llty
);
ret
.attrs
.set_dereferenceable
(
llsz
);
ret
.attrs
.set_dereferenceable
(
ccx
.size_of
(
ret_ty
.boxed_ty
()));
}
_
=>
{}
}
...
...
@@ -517,9 +513,7 @@ fn unadjusted<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
args
.push
(
info
);
}
else
{
if
let
Some
(
inner
)
=
rust_ptr_attrs
(
ty
,
&
mut
arg
)
{
let
llty
=
type_of
::
sizing_type_of
(
ccx
,
inner
);
let
llsz
=
llsize_of_alloc
(
ccx
,
llty
);
arg
.attrs
.set_dereferenceable
(
llsz
);
arg
.attrs
.set_dereferenceable
(
ccx
.size_of
(
inner
));
}
args
.push
(
arg
);
}
...
...
src/librustc_trans/adt.rs
浏览文件 @
c977daf9
...
...
@@ -47,7 +47,7 @@
use
llvm
::{
ValueRef
,
True
,
IntEQ
,
IntNE
};
use
rustc
::
ty
::
layout
;
use
rustc
::
ty
::{
self
,
Ty
,
AdtKind
};
use
rustc
::
ty
::{
self
,
Ty
};
use
common
::
*
;
use
builder
::
Builder
;
use
base
;
...
...
@@ -285,11 +285,6 @@ pub fn trans_get_discr<'a, 'tcx>(
cast_to
:
Option
<
Type
>
,
range_assert
:
bool
)
->
ValueRef
{
let
(
def
,
substs
)
=
match
t
.sty
{
ty
::
TyAdt
(
ref
def
,
substs
)
if
def
.adt_kind
()
==
AdtKind
::
Enum
=>
(
def
,
substs
),
_
=>
bug!
(
"{} is not an enum"
,
t
)
};
debug!
(
"trans_get_discr t: {:?}"
,
t
);
let
l
=
bcx
.ccx
.layout_of
(
t
);
...
...
@@ -297,19 +292,17 @@ pub fn trans_get_discr<'a, 'tcx>(
layout
::
CEnum
{
discr
,
min
,
max
,
..
}
=>
{
load_discr
(
bcx
,
discr
,
scrutinee
,
alignment
,
min
,
max
,
range_assert
)
}
layout
::
General
{
discr
,
..
}
=>
{
layout
::
General
{
discr
,
ref
variants
,
..
}
=>
{
let
ptr
=
bcx
.struct_gep
(
scrutinee
,
0
);
load_discr
(
bcx
,
discr
,
ptr
,
alignment
,
0
,
def
.
variants
.len
()
as
u64
-
1
,
0
,
variants
.len
()
as
u64
-
1
,
range_assert
)
}
layout
::
Univariant
{
..
}
|
layout
::
UntaggedUnion
{
..
}
=>
C_u8
(
bcx
.ccx
,
0
),
layout
::
RawNullablePointer
{
nndiscr
,
..
}
=>
{
let
cmp
=
if
nndiscr
==
0
{
IntEQ
}
else
{
IntNE
};
let
llptrty
=
type_of
::
sizing_type_of
(
bcx
.ccx
,
monomorphize
::
field_ty
(
bcx
.tcx
(),
substs
,
&
def
.variants
[
nndiscr
as
usize
]
.fields
[
0
]));
bcx
.icmp
(
cmp
,
bcx
.load
(
scrutinee
,
alignment
.to_align
()),
C_null
(
llptrty
))
let
discr
=
bcx
.load
(
scrutinee
,
alignment
.to_align
());
bcx
.icmp
(
cmp
,
discr
,
C_null
(
val_ty
(
discr
)))
}
layout
::
StructWrappedNullablePointer
{
nndiscr
,
ref
discrfield
,
..
}
=>
{
struct_wrapped_nullable_bitdiscr
(
bcx
,
nndiscr
,
discrfield
,
scrutinee
,
alignment
)
...
...
@@ -383,9 +376,8 @@ pub fn trans_set_discr<'a, 'tcx>(bcx: &Builder<'a, 'tcx>, t: Ty<'tcx>, val: Valu
assert_eq!
(
to
,
Disr
(
0
));
}
layout
::
RawNullablePointer
{
nndiscr
,
..
}
=>
{
let
nnty
=
compute_fields
(
bcx
.ccx
,
t
,
nndiscr
as
usize
,
false
)[
0
];
if
to
.0
!=
nndiscr
{
let
llptrty
=
type_of
::
sizing_type_of
(
bcx
.ccx
,
nnty
);
let
llptrty
=
val_ty
(
val
)
.element_type
(
);
bcx
.store
(
C_null
(
llptrty
),
val
,
None
);
}
}
...
...
src/librustc_trans/base.rs
浏览文件 @
c977daf9
...
...
@@ -59,7 +59,6 @@
use
debuginfo
;
use
declare
;
use
machine
;
use
machine
::
llsize_of
;
use
meth
;
use
mir
;
use
monomorphize
::{
self
,
Instance
};
...
...
@@ -534,14 +533,13 @@ pub fn memcpy_ty<'a, 'tcx>(
)
{
let
ccx
=
bcx
.ccx
;
if
type_is_zero_size
(
ccx
,
t
)
{
let
size
=
ccx
.size_of
(
t
);
if
size
==
0
{
return
;
}
let
llty
=
type_of
::
type_of
(
ccx
,
t
);
let
llsz
=
llsize_of
(
ccx
,
llty
);
let
llalign
=
align
.unwrap_or_else
(||
type_of
::
align_of
(
ccx
,
t
));
call_memcpy
(
bcx
,
dst
,
src
,
llsz
,
llalign
as
u32
);
let
align
=
align
.unwrap_or_else
(||
ccx
.align_of
(
t
));
call_memcpy
(
bcx
,
dst
,
src
,
C_uint
(
ccx
,
size
),
align
);
}
pub
fn
call_memset
<
'a
,
'tcx
>
(
b
:
&
Builder
<
'a
,
'tcx
>
,
...
...
src/librustc_trans/common.rs
浏览文件 @
c977daf9
...
...
@@ -125,10 +125,8 @@ pub fn type_is_imm_pair<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty: Ty<'tcx>)
/// Identify types which have size zero at runtime.
pub
fn
type_is_zero_size
<
'a
,
'tcx
>
(
ccx
:
&
CrateContext
<
'a
,
'tcx
>
,
ty
:
Ty
<
'tcx
>
)
->
bool
{
use
machine
::
llsize_of_alloc
;
use
type_of
::
sizing_type_of
;
let
llty
=
sizing_type_of
(
ccx
,
ty
);
llsize_of_alloc
(
ccx
,
llty
)
==
0
let
layout
=
ccx
.layout_of
(
ty
);
!
layout
.is_unsized
()
&&
layout
.size
(
&
ccx
.tcx
()
.data_layout
)
.bytes
()
==
0
}
/*
...
...
src/librustc_trans/consts.rs
浏览文件 @
c977daf9
...
...
@@ -255,7 +255,7 @@ pub fn trans_static<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
ccx
.statics_to_rauw
()
.borrow_mut
()
.push
((
g
,
new_g
));
new_g
};
llvm
::
LLVMSetAlignment
(
g
,
type_of
::
align_of
(
ccx
,
ty
));
llvm
::
LLVMSetAlignment
(
g
,
ccx
.align_of
(
ty
));
llvm
::
LLVMSetInitializer
(
g
,
v
);
// As an optimization, all shared statics which do not have interior
...
...
src/librustc_trans/debuginfo/metadata.rs
浏览文件 @
c977daf9
...
...
@@ -1772,7 +1772,7 @@ pub fn create_global_var_metadata(cx: &CrateContext,
let
var_name
=
CString
::
new
(
var_name
)
.unwrap
();
let
linkage_name
=
CString
::
new
(
linkage_name
)
.unwrap
();
let
global_align
=
type_of
::
align_of
(
cx
,
variable_type
);
let
global_align
=
cx
.align_of
(
variable_type
);
unsafe
{
llvm
::
LLVMRustDIBuilderCreateStaticVariable
(
DIB
(
cx
),
...
...
src/librustc_trans/debuginfo/mod.rs
浏览文件 @
c977daf9
...
...
@@ -449,7 +449,7 @@ pub fn declare_local<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
LocalVariable
|
CapturedVariable
=>
(
0
,
DW_TAG_auto_variable
)
};
let
align
=
::
type_of
::
align_of
(
cx
,
variable_type
);
let
align
=
cx
.align_of
(
variable_type
);
let
name
=
CString
::
new
(
variable_name
.as_str
()
.as_bytes
())
.unwrap
();
match
(
variable_access
,
&
[][
..
])
{
...
...
src/librustc_trans/glue.rs
浏览文件 @
c977daf9
...
...
@@ -19,10 +19,8 @@
use
rustc
::
traits
;
use
rustc
::
ty
::{
self
,
Ty
,
TypeFoldable
};
use
common
::
*
;
use
machine
::
*
;
use
meth
;
use
monomorphize
;
use
type_of
::{
sizing_type_of
,
align_of
};
use
value
::
Value
;
use
builder
::
Builder
;
...
...
@@ -69,9 +67,8 @@ pub fn size_and_align_of_dst<'a, 'tcx>(bcx: &Builder<'a, 'tcx>, t: Ty<'tcx>, inf
debug!
(
"calculate size of DST: {}; with lost info: {:?}"
,
t
,
Value
(
info
));
if
bcx
.ccx
.shared
()
.type_is_sized
(
t
)
{
let
sizing_type
=
sizing_type_of
(
bcx
.ccx
,
t
);
let
size
=
llsize_of_alloc
(
bcx
.ccx
,
sizing_type
);
let
align
=
align_of
(
bcx
.ccx
,
t
);
let
size
=
bcx
.ccx
.size_of
(
t
);
let
align
=
bcx
.ccx
.align_of
(
t
);
debug!
(
"size_and_align_of_dst t={} info={:?} size: {} align: {}"
,
t
,
Value
(
info
),
size
,
align
);
let
size
=
C_uint
(
bcx
.ccx
,
size
);
...
...
@@ -82,9 +79,8 @@ pub fn size_and_align_of_dst<'a, 'tcx>(bcx: &Builder<'a, 'tcx>, t: Ty<'tcx>, inf
ty
::
TyAdt
(
def
,
substs
)
=>
{
let
ccx
=
bcx
.ccx
;
// First get the size of all statically known fields.
// Don't use type_of::sizing_type_of because that expects t to be sized,
// and it also rounds up to alignment, which we want to avoid,
// as the unsized field's alignment could be smaller.
// Don't use size_of because it also rounds up to alignment, which we
// want to avoid, as the unsized field's alignment could be smaller.
assert
!
(
!
t
.is_simd
());
let
layout
=
ccx
.layout_of
(
t
);
debug!
(
"DST {} layout: {:?}"
,
t
,
layout
);
...
...
@@ -154,14 +150,11 @@ pub fn size_and_align_of_dst<'a, 'tcx>(bcx: &Builder<'a, 'tcx>, t: Ty<'tcx>, inf
(
meth
::
SIZE
.get_usize
(
bcx
,
info
),
meth
::
ALIGN
.get_usize
(
bcx
,
info
))
}
ty
::
TySlice
(
_
)
|
ty
::
TyStr
=>
{
let
unit
_ty
=
t
.sequence_element_type
(
bcx
.tcx
());
let
unit
=
t
.sequence_element_type
(
bcx
.tcx
());
// The info in this case is the length of the str, so the size is that
// times the unit size.
let
llunit_ty
=
sizing_type_of
(
bcx
.ccx
,
unit_ty
);
let
unit_align
=
llalign_of_min
(
bcx
.ccx
,
llunit_ty
);
let
unit_size
=
llsize_of_alloc
(
bcx
.ccx
,
llunit_ty
);
(
bcx
.mul
(
info
,
C_uint
(
bcx
.ccx
,
unit_size
)),
C_uint
(
bcx
.ccx
,
unit_align
))
(
bcx
.mul
(
info
,
C_uint
(
bcx
.ccx
,
bcx
.ccx
.size_of
(
unit
))),
C_uint
(
bcx
.ccx
,
bcx
.ccx
.align_of
(
unit
)))
}
_
=>
bug!
(
"Unexpected unsized type, found {}"
,
t
)
}
...
...
src/librustc_trans/intrinsic.rs
浏览文件 @
c977daf9
...
...
@@ -151,7 +151,7 @@ pub fn trans_intrinsic_call<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
}
"min_align_of"
=>
{
let
tp_ty
=
substs
.type_at
(
0
);
C_uint
(
ccx
,
type_of
::
align_of
(
ccx
,
tp_ty
))
C_uint
(
ccx
,
ccx
.align_of
(
tp_ty
))
}
"min_align_of_val"
=>
{
let
tp_ty
=
substs
.type_at
(
0
);
...
...
@@ -160,7 +160,7 @@ pub fn trans_intrinsic_call<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
glue
::
size_and_align_of_dst
(
bcx
,
tp_ty
,
llargs
[
1
]);
llalign
}
else
{
C_uint
(
ccx
,
type_of
::
align_of
(
ccx
,
tp_ty
))
C_uint
(
ccx
,
ccx
.align_of
(
tp_ty
))
}
}
"pref_align_of"
=>
{
...
...
@@ -234,7 +234,7 @@ pub fn trans_intrinsic_call<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
}
let
load
=
bcx
.volatile_load
(
ptr
);
unsafe
{
llvm
::
LLVMSetAlignment
(
load
,
type_of
::
align_of
(
ccx
,
tp_ty
));
llvm
::
LLVMSetAlignment
(
load
,
ccx
.align_of
(
tp_ty
));
}
to_immediate
(
bcx
,
load
,
tp_ty
)
},
...
...
@@ -252,7 +252,7 @@ pub fn trans_intrinsic_call<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
let
ptr
=
bcx
.pointercast
(
llargs
[
0
],
val_ty
(
val
)
.ptr_to
());
let
store
=
bcx
.volatile_store
(
val
,
ptr
);
unsafe
{
llvm
::
LLVMSetAlignment
(
store
,
type_of
::
align_of
(
ccx
,
tp_ty
));
llvm
::
LLVMSetAlignment
(
store
,
ccx
.align_of
(
tp_ty
));
}
}
C_nil
(
ccx
)
...
...
@@ -634,7 +634,7 @@ fn modify_as_needed<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
if
val_ty
(
llval
)
!=
Type
::
void
(
ccx
)
&&
machine
::
llsize_of_alloc
(
ccx
,
val_ty
(
llval
))
!=
0
{
if
let
Some
(
ty
)
=
fn_ty
.ret.cast
{
let
ptr
=
bcx
.pointercast
(
llresult
,
ty
.ptr_to
());
bcx
.store
(
llval
,
ptr
,
Some
(
type_of
::
align_of
(
ccx
,
ret_ty
)));
bcx
.store
(
llval
,
ptr
,
Some
(
ccx
.align_of
(
ret_ty
)));
}
else
{
store_ty
(
bcx
,
llval
,
llresult
,
Alignment
::
AbiAligned
,
ret_ty
);
}
...
...
@@ -651,7 +651,7 @@ fn copy_intrinsic<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
->
ValueRef
{
let
ccx
=
bcx
.ccx
;
let
lltp_ty
=
type_of
::
type_of
(
ccx
,
tp_ty
);
let
align
=
C_i32
(
ccx
,
type_of
::
align_of
(
ccx
,
tp_ty
)
as
i32
);
let
align
=
C_i32
(
ccx
,
ccx
.align_of
(
tp_ty
)
as
i32
);
let
size
=
machine
::
llsize_of
(
ccx
,
lltp_ty
);
let
int_size
=
machine
::
llbitsize_of_real
(
ccx
,
ccx
.int_type
());
...
...
@@ -685,7 +685,7 @@ fn memset_intrinsic<'a, 'tcx>(
count
:
ValueRef
)
->
ValueRef
{
let
ccx
=
bcx
.ccx
;
let
align
=
C_i32
(
ccx
,
type_of
::
align_of
(
ccx
,
ty
)
as
i32
);
let
align
=
C_i32
(
ccx
,
ccx
.align_of
(
ty
)
as
i32
);
let
lltp_ty
=
type_of
::
type_of
(
ccx
,
ty
);
let
size
=
machine
::
llsize_of
(
ccx
,
lltp_ty
);
let
dst
=
bcx
.pointercast
(
dst
,
Type
::
i8p
(
ccx
));
...
...
src/librustc_trans/meth.rs
浏览文件 @
c977daf9
...
...
@@ -17,7 +17,6 @@
use
machine
;
use
monomorphize
;
use
type_
::
Type
;
use
type_of
::
*
;
use
value
::
Value
;
use
rustc
::
ty
;
...
...
@@ -80,14 +79,10 @@ pub fn get_vtable<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
// Not in the cache. Build it.
let
nullptr
=
C_null
(
Type
::
nil
(
ccx
)
.ptr_to
());
let
size_ty
=
sizing_type_of
(
ccx
,
ty
);
let
size
=
machine
::
llsize_of_alloc
(
ccx
,
size_ty
);
let
align
=
align_of
(
ccx
,
ty
);
let
mut
components
:
Vec
<
_
>
=
[
callee
::
get_fn
(
ccx
,
monomorphize
::
resolve_drop_in_place
(
ccx
.shared
(),
ty
)),
C_uint
(
ccx
,
size
),
C_uint
(
ccx
,
align
)
C_uint
(
ccx
,
ccx
.size_of
(
ty
)
),
C_uint
(
ccx
,
ccx
.align_of
(
ty
)
)
]
.iter
()
.cloned
()
.collect
();
if
let
Some
(
trait_ref
)
=
trait_ref
{
...
...
src/librustc_trans/mir/block.rs
浏览文件 @
c977daf9
...
...
@@ -24,8 +24,8 @@
use
machine
::
llalign_of_min
;
use
meth
;
use
monomorphize
;
use
type_of
;
use
tvec
;
use
type_of
::{
self
,
align_of
};
use
type_
::
Type
;
use
rustc_data_structures
::
indexed_vec
::
IndexVec
;
...
...
@@ -910,7 +910,7 @@ fn trans_transmute_into(&mut self, bcx: &Builder<'a, 'tcx>,
let
cast_ptr
=
bcx
.pointercast
(
dst
.llval
,
llty
.ptr_to
());
let
in_type
=
val
.ty
;
let
out_type
=
dst
.ty
.to_ty
(
bcx
.tcx
());;
let
llalign
=
cmp
::
min
(
align_of
(
bcx
.ccx
,
in_type
),
align_of
(
bcx
.ccx
,
out_type
));
let
llalign
=
cmp
::
min
(
bcx
.ccx
.align_of
(
in_type
),
bcx
.ccx
.align_of
(
out_type
));
self
.store_operand
(
bcx
,
cast_ptr
,
Some
(
llalign
),
val
);
}
...
...
src/librustc_trans/mir/constant.rs
浏览文件 @
c977daf9
...
...
@@ -148,7 +148,7 @@ pub fn to_operand<'a>(&self, ccx: &CrateContext<'a, 'tcx>) -> OperandRef<'tcx> {
}
else
{
// Otherwise, or if the value is not immediate, we create
// a constant LLVM global and cast its address if necessary.
let
align
=
type_of
::
align_of
(
ccx
,
self
.ty
);
let
align
=
ccx
.align_of
(
self
.ty
);
let
ptr
=
consts
::
addr_of
(
ccx
,
self
.llval
,
align
,
"const"
);
OperandValue
::
Ref
(
consts
::
ptrcast
(
ptr
,
llty
.ptr_to
()),
Alignment
::
AbiAligned
)
};
...
...
@@ -717,7 +717,7 @@ fn const_rvalue(&self, rvalue: &mir::Rvalue<'tcx>,
Base
::
Value
(
llval
)
=>
{
// FIXME: may be wrong for &*(&simd_vec as &fmt::Debug)
let
align
=
if
self
.ccx
.shared
()
.type_is_sized
(
ty
)
{
type_of
::
align_of
(
self
.ccx
,
ty
)
self
.ccx
.align_of
(
ty
)
}
else
{
self
.ccx
.tcx
()
.data_layout.pointer_align
.abi
()
as
machine
::
llalign
};
...
...
@@ -1022,25 +1022,20 @@ fn trans_const<'a, 'tcx>(
C_vector
(
vals
)
}
layout
::
RawNullablePointer
{
nndiscr
,
..
}
=>
{
let
nnty
=
adt
::
compute_fields
(
ccx
,
t
,
nndiscr
as
usize
,
false
)[
0
];
if
variant_index
as
u64
==
nndiscr
{
assert_eq!
(
vals
.len
(),
1
);
vals
[
0
]
}
else
{
C_null
(
type_of
::
sizing_type_of
(
ccx
,
nnty
))
C_null
(
type_of
::
type_of
(
ccx
,
t
))
}
}
layout
::
StructWrappedNullablePointer
{
ref
nonnull
,
nndiscr
,
..
}
=>
{
if
variant_index
as
u64
==
nndiscr
{
C_struct
(
ccx
,
&
build_const_struct
(
ccx
,
&
nonnull
,
vals
),
false
)
}
else
{
let
fields
=
adt
::
compute_fields
(
ccx
,
t
,
nndiscr
as
usize
,
false
);
let
vals
=
fields
.iter
()
.map
(|
&
ty
|
{
// Always use null even if it's not the `discrfield`th
// field; see #8506.
C_null
(
type_of
::
sizing_type_of
(
ccx
,
ty
))
})
.collect
::
<
Vec
<
ValueRef
>>
();
C_struct
(
ccx
,
&
build_const_struct
(
ccx
,
&
nonnull
,
&
vals
[
..
]),
false
)
// Always use null even if it's not the `discrfield`th
// field; see #8506.
C_null
(
type_of
::
type_of
(
ccx
,
t
))
}
}
_
=>
bug!
(
"trans_const: cannot handle type {} repreented as {:#?}"
,
t
,
l
)
...
...
src/librustc_trans/mir/rvalue.rs
浏览文件 @
c977daf9
...
...
@@ -438,7 +438,7 @@ pub fn trans_rvalue_operand(&mut self,
let
content_ty
:
Ty
<
'tcx
>
=
self
.monomorphize
(
&
content_ty
);
let
llty
=
type_of
::
type_of
(
bcx
.ccx
,
content_ty
);
let
llsize
=
machine
::
llsize_of
(
bcx
.ccx
,
llty
);
let
align
=
type_of
::
align_of
(
bcx
.ccx
,
content_ty
);
let
align
=
bcx
.ccx
.align_of
(
content_ty
);
let
llalign
=
C_uint
(
bcx
.ccx
,
align
);
let
llty_ptr
=
llty
.ptr_to
();
let
box_ty
=
bcx
.tcx
()
.mk_box
(
content_ty
);
...
...
src/librustc_trans/type_of.rs
浏览文件 @
c977daf9
...
...
@@ -322,10 +322,16 @@ pub fn in_memory_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) ->
llty
}
pub
fn
align_of
<
'a
,
'tcx
>
(
cx
:
&
CrateContext
<
'a
,
'tcx
>
,
t
:
Ty
<
'tcx
>
)
->
machine
::
llalign
{
let
layout
=
cx
.layout_of
(
t
);
layout
.align
(
&
cx
.tcx
()
.data_layout
)
.abi
()
as
machine
::
llalign
impl
<
'a
,
'tcx
>
CrateContext
<
'a
,
'tcx
>
{
pub
fn
align_of
(
&
self
,
ty
:
Ty
<
'tcx
>
)
->
machine
::
llalign
{
let
layout
=
self
.layout_of
(
ty
);
layout
.align
(
&
self
.tcx
()
.data_layout
)
.abi
()
as
machine
::
llalign
}
pub
fn
size_of
(
&
self
,
ty
:
Ty
<
'tcx
>
)
->
machine
::
llsize
{
let
layout
=
self
.layout_of
(
ty
);
layout
.size
(
&
self
.tcx
()
.data_layout
)
.bytes
()
as
machine
::
llsize
}
}
fn
llvm_type_name
<
'a
,
'tcx
>
(
cx
:
&
CrateContext
<
'a
,
'tcx
>
,
ty
:
Ty
<
'tcx
>
)
->
String
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录