fix Rvalue::ty for ThreadLocalRef
This commit is contained in:
parent
c1766c6372
commit
153e843c49
5 changed files with 19 additions and 14 deletions
|
@ -1007,13 +1007,13 @@ impl<'tcx> LocalDecl<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `Some` if this is a reference to a static item that is used to
|
/// Returns `Some` if this is a reference to a static item that is used to
|
||||||
/// access that static
|
/// access that static.
|
||||||
pub fn is_ref_to_static(&self) -> bool {
|
pub fn is_ref_to_static(&self) -> bool {
|
||||||
matches!(self.local_info, Some(box LocalInfo::StaticRef { .. }))
|
matches!(self.local_info, Some(box LocalInfo::StaticRef { .. }))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `Some` if this is a reference to a static item that is used to
|
/// Returns `Some` if this is a reference to a thread-local static item that is used to
|
||||||
/// access that static
|
/// access that static.
|
||||||
pub fn is_ref_to_thread_local(&self) -> bool {
|
pub fn is_ref_to_thread_local(&self) -> bool {
|
||||||
match self.local_info {
|
match self.local_info {
|
||||||
Some(box LocalInfo::StaticRef { is_thread_local, .. }) => is_thread_local,
|
Some(box LocalInfo::StaticRef { is_thread_local, .. }) => is_thread_local,
|
||||||
|
|
|
@ -152,10 +152,14 @@ impl<'tcx> Rvalue<'tcx> {
|
||||||
tcx.mk_ty(ty::Array(operand.ty(local_decls, tcx), count))
|
tcx.mk_ty(ty::Array(operand.ty(local_decls, tcx), count))
|
||||||
}
|
}
|
||||||
Rvalue::ThreadLocalRef(did) => {
|
Rvalue::ThreadLocalRef(did) => {
|
||||||
|
let static_ty = tcx.type_of(did);
|
||||||
if tcx.is_mutable_static(did) {
|
if tcx.is_mutable_static(did) {
|
||||||
tcx.mk_mut_ptr(tcx.type_of(did))
|
tcx.mk_mut_ptr(static_ty)
|
||||||
|
} else if tcx.is_foreign_item(did) {
|
||||||
|
tcx.mk_imm_ptr(static_ty)
|
||||||
} else {
|
} else {
|
||||||
tcx.mk_imm_ref(tcx.lifetimes.re_static, tcx.type_of(did))
|
// FIXME: These things don't *really* have 'static lifetime.
|
||||||
|
tcx.mk_imm_ref(tcx.lifetimes.re_static, static_ty)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Rvalue::Ref(reg, bk, ref place) => {
|
Rvalue::Ref(reg, bk, ref place) => {
|
||||||
|
|
|
@ -530,6 +530,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
let static_ty = self.normalize_erasing_regions(ty::ParamEnv::empty(), self.type_of(def_id));
|
let static_ty = self.normalize_erasing_regions(ty::ParamEnv::empty(), self.type_of(def_id));
|
||||||
|
|
||||||
// Make sure that accesses to unsafe statics end up using raw pointers.
|
// Make sure that accesses to unsafe statics end up using raw pointers.
|
||||||
|
// For thread-locals, this needs to be kept in sync with `Rvalue::ty`.
|
||||||
if self.is_mutable_static(def_id) {
|
if self.is_mutable_static(def_id) {
|
||||||
self.mk_mut_ptr(static_ty)
|
self.mk_mut_ptr(static_ty)
|
||||||
} else if self.is_foreign_item(def_id) {
|
} else if self.is_foreign_item(def_id) {
|
||||||
|
|
|
@ -4,17 +4,17 @@ promoted[0] in FOO: &[&i32; 1] = {
|
||||||
let mut _0: &[&i32; 1]; // return place in scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:46
|
let mut _0: &[&i32; 1]; // return place in scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:46
|
||||||
let mut _1: [&i32; 1]; // in scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:46
|
let mut _1: [&i32; 1]; // in scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:46
|
||||||
let mut _2: &i32; // in scope 0 at $DIR/const-promotion-extern-static.rs:13:32: 13:45
|
let mut _2: &i32; // in scope 0 at $DIR/const-promotion-extern-static.rs:13:32: 13:45
|
||||||
let mut _3: &i32; // in scope 0 at $DIR/const-promotion-extern-static.rs:13:42: 13:43
|
let mut _3: *const i32; // in scope 0 at $DIR/const-promotion-extern-static.rs:13:42: 13:43
|
||||||
|
|
||||||
bb0: {
|
bb0: {
|
||||||
_3 = const {alloc2: &i32}; // scope 0 at $DIR/const-promotion-extern-static.rs:13:42: 13:43
|
_3 = const {alloc2: *const i32}; // scope 0 at $DIR/const-promotion-extern-static.rs:13:42: 13:43
|
||||||
// ty::Const
|
// ty::Const
|
||||||
// + ty: &i32
|
// + ty: *const i32
|
||||||
// + val: Value(Scalar(alloc2))
|
// + val: Value(Scalar(alloc2))
|
||||||
// mir::Constant
|
// mir::Constant
|
||||||
// + span: $DIR/const-promotion-extern-static.rs:13:42: 13:43
|
// + span: $DIR/const-promotion-extern-static.rs:13:42: 13:43
|
||||||
// + literal: Const { ty: &i32, val: Value(Scalar(alloc2)) }
|
// + literal: Const { ty: *const i32, val: Value(Scalar(alloc2)) }
|
||||||
_2 = _3; // scope 0 at $DIR/const-promotion-extern-static.rs:13:41: 13:43
|
_2 = &(*_3); // scope 0 at $DIR/const-promotion-extern-static.rs:13:41: 13:43
|
||||||
_1 = [move _2]; // scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:46
|
_1 = [move _2]; // scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:46
|
||||||
_0 = &_1; // scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:46
|
_0 = &_1; // scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:46
|
||||||
return; // scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:46
|
return; // scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:46
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
let mut _2: &[&i32; 1]; // in scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:46
|
let mut _2: &[&i32; 1]; // in scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:46
|
||||||
let _3: [&i32; 1]; // in scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:46
|
let _3: [&i32; 1]; // in scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:46
|
||||||
let mut _4: &i32; // in scope 0 at $DIR/const-promotion-extern-static.rs:13:32: 13:45
|
let mut _4: &i32; // in scope 0 at $DIR/const-promotion-extern-static.rs:13:32: 13:45
|
||||||
let _5: &i32; // in scope 0 at $DIR/const-promotion-extern-static.rs:13:42: 13:43
|
let _5: *const i32; // in scope 0 at $DIR/const-promotion-extern-static.rs:13:42: 13:43
|
||||||
+ let mut _6: &[&i32; 1]; // in scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:46
|
+ let mut _6: &[&i32; 1]; // in scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:46
|
||||||
scope 1 {
|
scope 1 {
|
||||||
}
|
}
|
||||||
|
@ -18,16 +18,16 @@
|
||||||
- StorageLive(_3); // scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:46
|
- StorageLive(_3); // scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:46
|
||||||
- StorageLive(_4); // scope 0 at $DIR/const-promotion-extern-static.rs:13:32: 13:45
|
- StorageLive(_4); // scope 0 at $DIR/const-promotion-extern-static.rs:13:32: 13:45
|
||||||
- StorageLive(_5); // scope 1 at $DIR/const-promotion-extern-static.rs:13:42: 13:43
|
- StorageLive(_5); // scope 1 at $DIR/const-promotion-extern-static.rs:13:42: 13:43
|
||||||
- _5 = const {alloc2: &i32}; // scope 1 at $DIR/const-promotion-extern-static.rs:13:42: 13:43
|
- _5 = const {alloc2: *const i32}; // scope 1 at $DIR/const-promotion-extern-static.rs:13:42: 13:43
|
||||||
+ _6 = const FOO::promoted[0]; // scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:46
|
+ _6 = const FOO::promoted[0]; // scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:46
|
||||||
// ty::Const
|
// ty::Const
|
||||||
- // + ty: &i32
|
- // + ty: *const i32
|
||||||
- // + val: Value(Scalar(alloc2))
|
- // + val: Value(Scalar(alloc2))
|
||||||
+ // + ty: &[&i32; 1]
|
+ // + ty: &[&i32; 1]
|
||||||
+ // + val: Unevaluated(WithOptConstParam { did: DefId(0:7 ~ const_promotion_extern_static[317d]::FOO), const_param_did: None }, [], Some(promoted[0]))
|
+ // + val: Unevaluated(WithOptConstParam { did: DefId(0:7 ~ const_promotion_extern_static[317d]::FOO), const_param_did: None }, [], Some(promoted[0]))
|
||||||
// mir::Constant
|
// mir::Constant
|
||||||
- // + span: $DIR/const-promotion-extern-static.rs:13:42: 13:43
|
- // + span: $DIR/const-promotion-extern-static.rs:13:42: 13:43
|
||||||
- // + literal: Const { ty: &i32, val: Value(Scalar(alloc2)) }
|
- // + literal: Const { ty: *const i32, val: Value(Scalar(alloc2)) }
|
||||||
- _4 = &(*_5); // scope 1 at $DIR/const-promotion-extern-static.rs:13:41: 13:43
|
- _4 = &(*_5); // scope 1 at $DIR/const-promotion-extern-static.rs:13:41: 13:43
|
||||||
- _3 = [move _4]; // scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:46
|
- _3 = [move _4]; // scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:46
|
||||||
- _2 = &_3; // scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:46
|
- _2 = &_3; // scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:46
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue