diff options
| author | bjorn3 <bjorn3@users.noreply.github.com> | 2022-03-26 12:52:21 +0100 |
|---|---|---|
| committer | bjorn3 <bjorn3@users.noreply.github.com> | 2022-03-26 12:52:21 +0100 |
| commit | db591778ac3c93285fec6a5b7332b218131ccf94 (patch) | |
| tree | a5477feceee139e69723c076bb440af6b5172d36 | |
| parent | a22e15b954d2be638ab0b15cee6e93cf301dc159 (diff) | |
| parent | fadd1c536a1cc7b2b605abc8e8482fb15363b3a7 (diff) | |
| download | rust-db591778ac3c93285fec6a5b7332b218131ccf94.tar.gz rust-db591778ac3c93285fec6a5b7332b218131ccf94.zip | |
Sync from rust bc881e83d1cced71046e844fa55c0b0e9f9af382
| -rw-r--r-- | src/allocator.rs | 9 | ||||
| -rw-r--r-- | src/builder.rs | 6 | ||||
| -rw-r--r-- | src/common.rs | 33 | ||||
| -rw-r--r-- | src/consts.rs | 7 | ||||
| -rw-r--r-- | src/context.rs | 5 | ||||
| -rw-r--r-- | src/debuginfo.rs | 2 | ||||
| -rw-r--r-- | src/intrinsic/mod.rs | 8 | ||||
| -rw-r--r-- | src/lib.rs | 8 | ||||
| -rw-r--r-- | src/type_of.rs | 4 |
9 files changed, 42 insertions, 40 deletions
diff --git a/src/allocator.rs b/src/allocator.rs index 6378a31202c..c761e5aabd1 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -1,7 +1,8 @@ -use gccjit::{FunctionType, ToRValue}; +use gccjit::{FunctionType, GlobalKind, ToRValue}; use rustc_ast::expand::allocator::{AllocatorKind, AllocatorTy, ALLOCATOR_METHODS}; use rustc_middle::bug; use rustc_middle::ty::TyCtxt; +use rustc_session::config::OomStrategy; use rustc_span::symbol::sym; use crate::GccContext; @@ -113,4 +114,10 @@ pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut GccContext, _module_nam let _ret = context.new_call(None, callee, &args); //llvm::LLVMSetTailCall(ret, True); block.end_with_void_return(None); + + let name = OomStrategy::SYMBOL.to_string(); + let global = context.new_global(None, GlobalKind::Exported, i8, name); + let value = tcx.sess.opts.debugging_opts.oom.should_panic(); + let value = context.new_rvalue_from_int(i8, value as i32); + global.global_set_initializer_rvalue(value); } diff --git a/src/builder.rs b/src/builder.rs index 4aa9b5341fe..94b1e2ce13a 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -934,7 +934,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> { let val_type = value.get_type(); match (type_is_pointer(val_type), type_is_pointer(dest_ty)) { (false, true) => { - // NOTE: Projecting a field of a pointer type will attemp a cast from a signed char to + // NOTE: Projecting a field of a pointer type will attempt a cast from a signed char to // a pointer, which is not supported by gccjit. return self.cx.context.new_cast(None, self.inttoptr(value, val_type.make_pointer()), dest_ty); }, @@ -1251,8 +1251,8 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> { self.cx } - fn apply_attrs_to_cleanup_callsite(&mut self, _llret: RValue<'gcc>) { - // TODO + fn do_not_inline(&mut self, _llret: RValue<'gcc>) { + unimplemented!(); } fn set_span(&mut self, _span: Span) {} diff --git a/src/common.rs b/src/common.rs index e36e5bb2382..61709dd92de 100644 --- a/src/common.rs +++ b/src/common.rs @@ -11,7 +11,7 @@ use rustc_codegen_ssa::traits::{ use rustc_middle::mir::Mutability; use rustc_middle::ty::ScalarInt; use rustc_middle::ty::layout::{TyAndLayout, LayoutOf}; -use rustc_middle::mir::interpret::{Allocation, GlobalAlloc, Scalar}; +use rustc_middle::mir::interpret::{ConstAllocation, GlobalAlloc, Scalar}; use rustc_span::Symbol; use rustc_target::abi::{self, HasDataLayout, Pointer, Size}; @@ -24,18 +24,6 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> { bytes_in_context(self, bytes) } - fn const_cstr(&self, symbol: Symbol, _null_terminated: bool) -> LValue<'gcc> { - // TODO(antoyo): handle null_terminated. - if let Some(&value) = self.const_cstr_cache.borrow().get(&symbol) { - return value; - } - - let global = self.global_string(symbol.as_str()); - - self.const_cstr_cache.borrow_mut().insert(symbol, global); - global - } - fn global_string(&self, string: &str) -> LValue<'gcc> { // TODO(antoyo): handle non-null-terminated strings. let string = self.context.new_string_literal(&*string); @@ -134,8 +122,12 @@ impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> { } fn const_str(&self, s: Symbol) -> (RValue<'gcc>, RValue<'gcc>) { - let len = s.as_str().len(); - let cs = self.const_ptrcast(self.const_cstr(s, false).get_address(None), + let s_str = s.as_str(); + let str_global = *self.const_str_cache.borrow_mut().entry(s).or_insert_with(|| { + self.global_string(s_str) + }); + let len = s_str.len(); + let cs = self.const_ptrcast(str_global.get_address(None), self.type_ptr_to(self.layout_of(self.tcx.types.str_).gcc_type(self, true)), ); (cs, self.const_usize(len as u64)) @@ -190,6 +182,7 @@ impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> { match self.tcx.global_alloc(alloc_id) { GlobalAlloc::Memory(alloc) => { let init = const_alloc_to_gcc(self, alloc); + let alloc = alloc.inner(); let value = match alloc.mutability { Mutability::Mut => self.static_addr_of_mut(init, alloc.align, None), @@ -222,21 +215,21 @@ impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> { } } - fn const_data_from_alloc(&self, alloc: &Allocation) -> Self::Value { + fn const_data_from_alloc(&self, alloc: ConstAllocation<'tcx>) -> Self::Value { const_alloc_to_gcc(self, alloc) } - fn from_const_alloc(&self, layout: TyAndLayout<'tcx>, alloc: &Allocation, offset: Size) -> PlaceRef<'tcx, RValue<'gcc>> { - assert_eq!(alloc.align, layout.align.abi); + fn from_const_alloc(&self, layout: TyAndLayout<'tcx>, alloc: ConstAllocation<'tcx>, offset: Size) -> PlaceRef<'tcx, RValue<'gcc>> { + assert_eq!(alloc.inner().align, layout.align.abi); let ty = self.type_ptr_to(layout.gcc_type(self, true)); let value = if layout.size == Size::ZERO { - let value = self.const_usize(alloc.align.bytes()); + let value = self.const_usize(alloc.inner().align.bytes()); self.context.new_cast(None, value, ty) } else { let init = const_alloc_to_gcc(self, alloc); - let base_addr = self.static_addr_of(init, alloc.align, None); + let base_addr = self.static_addr_of(init, alloc.inner().align, None); let array = self.const_bitcast(base_addr, self.type_i8p()); let value = self.context.new_array_access(None, array, self.const_usize(offset.bytes())).get_address(None); diff --git a/src/consts.rs b/src/consts.rs index 598bcdc31b6..de52f3ea225 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -7,7 +7,7 @@ use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs} use rustc_middle::mir::mono::MonoItem; use rustc_middle::ty::{self, Instance, Ty}; use rustc_middle::ty::layout::LayoutOf; -use rustc_middle::mir::interpret::{self, Allocation, ErrorHandled, Scalar as InterpScalar, read_target_uint}; +use rustc_middle::mir::interpret::{self, ConstAllocation, ErrorHandled, Scalar as InterpScalar, read_target_uint}; use rustc_span::Span; use rustc_span::def_id::DefId; use rustc_target::abi::{self, Align, HasDataLayout, Primitive, Size, WrappingRange}; @@ -293,7 +293,8 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> { } } -pub fn const_alloc_to_gcc<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, alloc: &Allocation) -> RValue<'gcc> { +pub fn const_alloc_to_gcc<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, alloc: ConstAllocation<'tcx>) -> RValue<'gcc> { + let alloc = alloc.inner(); let mut llvals = Vec::with_capacity(alloc.relocations().len() + 1); let dl = cx.data_layout(); let pointer_size = dl.pointer_size.bytes() as usize; @@ -347,7 +348,7 @@ pub fn const_alloc_to_gcc<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, alloc: &Alloca cx.const_struct(&llvals, true) } -pub fn codegen_static_initializer<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, def_id: DefId) -> Result<(RValue<'gcc>, &'tcx Allocation), ErrorHandled> { +pub fn codegen_static_initializer<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, def_id: DefId) -> Result<(RValue<'gcc>, ConstAllocation<'tcx>), ErrorHandled> { let alloc = cx.tcx.eval_static_initializer(def_id)?; Ok((const_alloc_to_gcc(cx, alloc), alloc)) } diff --git a/src/context.rs b/src/context.rs index d411ccdb821..5e5b9e7e9b1 100644 --- a/src/context.rs +++ b/src/context.rs @@ -89,12 +89,13 @@ pub struct CodegenCx<'gcc, 'tcx> { /// Cache of emitted const globals (value -> global) pub const_globals: RefCell<FxHashMap<RValue<'gcc>, RValue<'gcc>>>, + /// Map from the address of a global variable (rvalue) to the global variable itself (lvalue). /// TODO(antoyo): remove when the rustc API is fixed. pub global_lvalues: RefCell<FxHashMap<RValue<'gcc>, LValue<'gcc>>>, /// Cache of constant strings, - pub const_cstr_cache: RefCell<FxHashMap<Symbol, LValue<'gcc>>>, + pub const_str_cache: RefCell<FxHashMap<Symbol, LValue<'gcc>>>, /// Cache of globals. pub globals: RefCell<FxHashMap<String, RValue<'gcc>>>, @@ -219,7 +220,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> { vtables: Default::default(), const_globals: Default::default(), global_lvalues: Default::default(), - const_cstr_cache: Default::default(), + const_str_cache: Default::default(), globals: Default::default(), scalar_types: Default::default(), types: Default::default(), diff --git a/src/debuginfo.rs b/src/debuginfo.rs index 31959fa19c5..266759ed6cf 100644 --- a/src/debuginfo.rs +++ b/src/debuginfo.rs @@ -31,7 +31,7 @@ impl<'a, 'gcc, 'tcx> DebugInfoBuilderMethods for Builder<'a, 'gcc, 'tcx> { } impl<'gcc, 'tcx> DebugInfoMethods<'tcx> for CodegenCx<'gcc, 'tcx> { - fn create_vtable_metadata(&self, _ty: Ty<'tcx>, _trait_ref: Option<PolyExistentialTraitRef<'tcx>>, _vtable: Self::Value) { + fn create_vtable_debuginfo(&self, _ty: Ty<'tcx>, _trait_ref: Option<PolyExistentialTraitRef<'tcx>>, _vtable: Self::Value) { // TODO(antoyo) } diff --git a/src/intrinsic/mod.rs b/src/intrinsic/mod.rs index d4b1dd5ca16..08e584a46f3 100644 --- a/src/intrinsic/mod.rs +++ b/src/intrinsic/mod.rs @@ -260,20 +260,20 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> { use rustc_target::abi::Abi::*; let tp_ty = substs.type_at(0); let layout = self.layout_of(tp_ty).layout; - let _use_integer_compare = match layout.abi { + let _use_integer_compare = match layout.abi() { Scalar(_) | ScalarPair(_, _) => true, Uninhabited | Vector { .. } => false, Aggregate { .. } => { // For rusty ABIs, small aggregates are actually passed // as `RegKind::Integer` (see `FnAbi::adjust_for_abi`), // so we re-use that same threshold here. - layout.size <= self.data_layout().pointer_size * 2 + layout.size() <= self.data_layout().pointer_size * 2 } }; let a = args[0].immediate(); let b = args[1].immediate(); - if layout.size.bytes() == 0 { + if layout.size().bytes() == 0 { self.const_bool(true) } /*else if use_integer_compare { @@ -289,7 +289,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> { let void_ptr_type = self.context.new_type::<*const ()>(); let a_ptr = self.bitcast(a, void_ptr_type); let b_ptr = self.bitcast(b, void_ptr_type); - let n = self.context.new_cast(None, self.const_usize(layout.size.bytes()), self.sizet_type); + let n = self.context.new_cast(None, self.const_usize(layout.size().bytes()), self.sizet_type); let builtin = self.context.get_builtin_function("memcmp"); let cmp = self.context.new_call(None, builtin, &[a_ptr, b_ptr, n]); self.icmp(IntPredicate::IntEQ, cmp, self.const_i32(0)) diff --git a/src/lib.rs b/src/lib.rs index ca283e1380c..8e197ea31a8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -60,7 +60,7 @@ use rustc_codegen_ssa::back::lto::{LtoModuleCodegen, SerializedModule, ThinModul use rustc_codegen_ssa::target_features::supported_target_features; use rustc_codegen_ssa::traits::{CodegenBackend, ExtraBackendMethods, ModuleBufferMethods, ThinBufferMethods, WriteBackendMethods}; use rustc_data_structures::fx::FxHashMap; -use rustc_errors::{ErrorReported, Handler}; +use rustc_errors::{ErrorGuaranteed, Handler}; use rustc_metadata::EncodedMetadata; use rustc_middle::dep_graph::{WorkProduct, WorkProductId}; use rustc_middle::ty::TyCtxt; @@ -108,7 +108,7 @@ impl CodegenBackend for GccCodegenBackend { Box::new(res) } - fn join_codegen(&self, ongoing_codegen: Box<dyn Any>, sess: &Session, _outputs: &OutputFilenames) -> Result<(CodegenResults, FxHashMap<WorkProductId, WorkProduct>), ErrorReported> { + fn join_codegen(&self, ongoing_codegen: Box<dyn Any>, sess: &Session, _outputs: &OutputFilenames) -> Result<(CodegenResults, FxHashMap<WorkProductId, WorkProduct>), ErrorGuaranteed> { let (codegen_results, work_products) = ongoing_codegen .downcast::<rustc_codegen_ssa::back::write::OngoingCodegen<GccCodegenBackend>>() .expect("Expected GccCodegenBackend's OngoingCodegen, found Box<Any>") @@ -117,7 +117,7 @@ impl CodegenBackend for GccCodegenBackend { Ok((codegen_results, work_products)) } - fn link(&self, sess: &Session, codegen_results: CodegenResults, outputs: &OutputFilenames) -> Result<(), ErrorReported> { + fn link(&self, sess: &Session, codegen_results: CodegenResults, outputs: &OutputFilenames) -> Result<(), ErrorGuaranteed> { use rustc_codegen_ssa::back::link::link_binary; link_binary::<crate::archive::ArArchiveBuilder<'_>>( @@ -147,7 +147,7 @@ impl ExtraBackendMethods for GccCodegenBackend { base::compile_codegen_unit(tcx, cgu_name, *self.supports_128bit_integers.lock().expect("lock")) } - fn target_machine_factory(&self, _sess: &Session, _opt_level: OptLevel) -> TargetMachineFactoryFn<Self> { + fn target_machine_factory(&self, _sess: &Session, _opt_level: OptLevel, _features: &[String]) -> TargetMachineFactoryFn<Self> { // TODO(antoyo): set opt level. Arc::new(|_| { Ok(()) diff --git a/src/type_of.rs b/src/type_of.rs index 76a98adbf3c..ed8f0445ca3 100644 --- a/src/type_of.rs +++ b/src/type_of.rs @@ -56,8 +56,8 @@ pub fn uncached_gcc_type<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, layout: TyAndLa if let (&ty::Adt(def, _), &Variants::Single { index }) = (layout.ty.kind(), &layout.variants) { - if def.is_enum() && !def.variants.is_empty() { - write!(&mut name, "::{}", def.variants[index].name).unwrap(); + if def.is_enum() && !def.variants().is_empty() { + write!(&mut name, "::{}", def.variant(index).name).unwrap(); } } if let (&ty::Generator(_, _, _), &Variants::Single { index }) = |
