Remove #[linkage(foo)]
statics from core miri
This commit is contained in:
parent
e8ea7da201
commit
8cbfbf77f8
28
miri/lib.rs
28
miri/lib.rs
@ -239,4 +239,32 @@ fn box_alloc<'a>(
|
||||
.map(PrimVal::Ptr)
|
||||
}
|
||||
}
|
||||
|
||||
fn global_item_with_linkage<'a>(
|
||||
ecx: &mut EvalContext<'a, 'tcx, Self>,
|
||||
instance: ty::Instance<'tcx>,
|
||||
mutability: Mutability,
|
||||
) -> EvalResult<'tcx> {
|
||||
// FIXME: check that it's `#[linkage = "extern_weak"]`
|
||||
trace!("Initializing an extern global with NULL");
|
||||
let ptr_size = ecx.memory.pointer_size();
|
||||
let ptr = ecx.memory.allocate(
|
||||
ptr_size,
|
||||
ptr_size,
|
||||
MemoryKind::UninitializedStatic,
|
||||
)?;
|
||||
ecx.memory.write_ptr_sized_unsigned(ptr, PrimVal::Bytes(0))?;
|
||||
ecx.memory.mark_static_initalized(ptr.alloc_id, mutability)?;
|
||||
ecx.globals.insert(
|
||||
GlobalId {
|
||||
instance,
|
||||
promoted: None,
|
||||
},
|
||||
PtrAndAlign {
|
||||
ptr: ptr.into(),
|
||||
aligned: true,
|
||||
},
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -245,4 +245,14 @@ fn box_alloc<'a>(
|
||||
ConstEvalError::NeedsRfc("Heap allocations via `box` keyword".to_string()).into(),
|
||||
)
|
||||
}
|
||||
|
||||
fn global_item_with_linkage<'a>(
|
||||
_ecx: &mut EvalContext<'a, 'tcx, Self>,
|
||||
_instance: ty::Instance<'tcx>,
|
||||
_mutability: Mutability,
|
||||
) -> EvalResult<'tcx> {
|
||||
Err(
|
||||
ConstEvalError::NotConst("statics with `linkage` attribute".to_string()).into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
use rustc::{mir, ty};
|
||||
use syntax::codemap::Span;
|
||||
use syntax::ast::Mutability;
|
||||
|
||||
/// Methods of this trait signifies a point where CTFE evaluation would fail
|
||||
/// and some use case dependent behaviour can instead be applied
|
||||
@ -70,4 +71,11 @@ fn box_alloc<'a>(
|
||||
ecx: &mut EvalContext<'a, 'tcx, Self>,
|
||||
ty: ty::Ty<'tcx>,
|
||||
) -> EvalResult<'tcx, PrimVal>;
|
||||
|
||||
/// Called when trying to access a global declared with a `linkage` attribute
|
||||
fn global_item_with_linkage<'a>(
|
||||
ecx: &mut EvalContext<'a, 'tcx, Self>,
|
||||
instance: ty::Instance<'tcx>,
|
||||
mutability: Mutability,
|
||||
) -> EvalResult<'tcx>;
|
||||
}
|
||||
|
@ -205,23 +205,7 @@ fn global_item(
|
||||
return Ok(false);
|
||||
}
|
||||
if self.tcx.has_attr(def_id, "linkage") {
|
||||
// FIXME: check that it's `#[linkage = "extern_weak"]`
|
||||
trace!("Initializing an extern global with NULL");
|
||||
let ptr_size = self.memory.pointer_size();
|
||||
let ptr = self.memory.allocate(
|
||||
ptr_size,
|
||||
ptr_size,
|
||||
MemoryKind::UninitializedStatic,
|
||||
)?;
|
||||
self.memory.write_ptr_sized_unsigned(ptr, PrimVal::Bytes(0))?;
|
||||
self.memory.mark_static_initalized(ptr.alloc_id, mutability)?;
|
||||
self.globals.insert(
|
||||
cid,
|
||||
PtrAndAlign {
|
||||
ptr: ptr.into(),
|
||||
aligned: true,
|
||||
},
|
||||
);
|
||||
M::global_item_with_linkage(self, cid.instance, mutability)?;
|
||||
return Ok(false);
|
||||
}
|
||||
let mir = self.load_mir(instance.def)?;
|
||||
|
Loading…
Reference in New Issue
Block a user