Skip to content

Commit db59177

Browse files
committed
Sync from rust bc881e8
2 parents a22e15b + fadd1c5 commit db59177

File tree

9 files changed

+42
-40
lines changed

9 files changed

+42
-40
lines changed

src/allocator.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use gccjit::{FunctionType, ToRValue};
1+
use gccjit::{FunctionType, GlobalKind, ToRValue};
22
use rustc_ast::expand::allocator::{AllocatorKind, AllocatorTy, ALLOCATOR_METHODS};
33
use rustc_middle::bug;
44
use rustc_middle::ty::TyCtxt;
5+
use rustc_session::config::OomStrategy;
56
use rustc_span::symbol::sym;
67

78
use crate::GccContext;
@@ -113,4 +114,10 @@ pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut GccContext, _module_nam
113114
let _ret = context.new_call(None, callee, &args);
114115
//llvm::LLVMSetTailCall(ret, True);
115116
block.end_with_void_return(None);
117+
118+
let name = OomStrategy::SYMBOL.to_string();
119+
let global = context.new_global(None, GlobalKind::Exported, i8, name);
120+
let value = tcx.sess.opts.debugging_opts.oom.should_panic();
121+
let value = context.new_rvalue_from_int(i8, value as i32);
122+
global.global_set_initializer_rvalue(value);
116123
}

src/builder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
934934
let val_type = value.get_type();
935935
match (type_is_pointer(val_type), type_is_pointer(dest_ty)) {
936936
(false, true) => {
937-
// NOTE: Projecting a field of a pointer type will attemp a cast from a signed char to
937+
// NOTE: Projecting a field of a pointer type will attempt a cast from a signed char to
938938
// a pointer, which is not supported by gccjit.
939939
return self.cx.context.new_cast(None, self.inttoptr(value, val_type.make_pointer()), dest_ty);
940940
},
@@ -1251,8 +1251,8 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
12511251
self.cx
12521252
}
12531253

1254-
fn apply_attrs_to_cleanup_callsite(&mut self, _llret: RValue<'gcc>) {
1255-
// TODO
1254+
fn do_not_inline(&mut self, _llret: RValue<'gcc>) {
1255+
unimplemented!();
12561256
}
12571257

12581258
fn set_span(&mut self, _span: Span) {}

src/common.rs

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_codegen_ssa::traits::{
1111
use rustc_middle::mir::Mutability;
1212
use rustc_middle::ty::ScalarInt;
1313
use rustc_middle::ty::layout::{TyAndLayout, LayoutOf};
14-
use rustc_middle::mir::interpret::{Allocation, GlobalAlloc, Scalar};
14+
use rustc_middle::mir::interpret::{ConstAllocation, GlobalAlloc, Scalar};
1515
use rustc_span::Symbol;
1616
use rustc_target::abi::{self, HasDataLayout, Pointer, Size};
1717

@@ -24,18 +24,6 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
2424
bytes_in_context(self, bytes)
2525
}
2626

27-
fn const_cstr(&self, symbol: Symbol, _null_terminated: bool) -> LValue<'gcc> {
28-
// TODO(antoyo): handle null_terminated.
29-
if let Some(&value) = self.const_cstr_cache.borrow().get(&symbol) {
30-
return value;
31-
}
32-
33-
let global = self.global_string(symbol.as_str());
34-
35-
self.const_cstr_cache.borrow_mut().insert(symbol, global);
36-
global
37-
}
38-
3927
fn global_string(&self, string: &str) -> LValue<'gcc> {
4028
// TODO(antoyo): handle non-null-terminated strings.
4129
let string = self.context.new_string_literal(&*string);
@@ -134,8 +122,12 @@ impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
134122
}
135123

136124
fn const_str(&self, s: Symbol) -> (RValue<'gcc>, RValue<'gcc>) {
137-
let len = s.as_str().len();
138-
let cs = self.const_ptrcast(self.const_cstr(s, false).get_address(None),
125+
let s_str = s.as_str();
126+
let str_global = *self.const_str_cache.borrow_mut().entry(s).or_insert_with(|| {
127+
self.global_string(s_str)
128+
});
129+
let len = s_str.len();
130+
let cs = self.const_ptrcast(str_global.get_address(None),
139131
self.type_ptr_to(self.layout_of(self.tcx.types.str_).gcc_type(self, true)),
140132
);
141133
(cs, self.const_usize(len as u64))
@@ -190,6 +182,7 @@ impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
190182
match self.tcx.global_alloc(alloc_id) {
191183
GlobalAlloc::Memory(alloc) => {
192184
let init = const_alloc_to_gcc(self, alloc);
185+
let alloc = alloc.inner();
193186
let value =
194187
match alloc.mutability {
195188
Mutability::Mut => self.static_addr_of_mut(init, alloc.align, None),
@@ -222,21 +215,21 @@ impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
222215
}
223216
}
224217

225-
fn const_data_from_alloc(&self, alloc: &Allocation) -> Self::Value {
218+
fn const_data_from_alloc(&self, alloc: ConstAllocation<'tcx>) -> Self::Value {
226219
const_alloc_to_gcc(self, alloc)
227220
}
228221

229-
fn from_const_alloc(&self, layout: TyAndLayout<'tcx>, alloc: &Allocation, offset: Size) -> PlaceRef<'tcx, RValue<'gcc>> {
230-
assert_eq!(alloc.align, layout.align.abi);
222+
fn from_const_alloc(&self, layout: TyAndLayout<'tcx>, alloc: ConstAllocation<'tcx>, offset: Size) -> PlaceRef<'tcx, RValue<'gcc>> {
223+
assert_eq!(alloc.inner().align, layout.align.abi);
231224
let ty = self.type_ptr_to(layout.gcc_type(self, true));
232225
let value =
233226
if layout.size == Size::ZERO {
234-
let value = self.const_usize(alloc.align.bytes());
227+
let value = self.const_usize(alloc.inner().align.bytes());
235228
self.context.new_cast(None, value, ty)
236229
}
237230
else {
238231
let init = const_alloc_to_gcc(self, alloc);
239-
let base_addr = self.static_addr_of(init, alloc.align, None);
232+
let base_addr = self.static_addr_of(init, alloc.inner().align, None);
240233

241234
let array = self.const_bitcast(base_addr, self.type_i8p());
242235
let value = self.context.new_array_access(None, array, self.const_usize(offset.bytes())).get_address(None);

src/consts.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs}
77
use rustc_middle::mir::mono::MonoItem;
88
use rustc_middle::ty::{self, Instance, Ty};
99
use rustc_middle::ty::layout::LayoutOf;
10-
use rustc_middle::mir::interpret::{self, Allocation, ErrorHandled, Scalar as InterpScalar, read_target_uint};
10+
use rustc_middle::mir::interpret::{self, ConstAllocation, ErrorHandled, Scalar as InterpScalar, read_target_uint};
1111
use rustc_span::Span;
1212
use rustc_span::def_id::DefId;
1313
use rustc_target::abi::{self, Align, HasDataLayout, Primitive, Size, WrappingRange};
@@ -293,7 +293,8 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
293293
}
294294
}
295295

296-
pub fn const_alloc_to_gcc<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, alloc: &Allocation) -> RValue<'gcc> {
296+
pub fn const_alloc_to_gcc<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, alloc: ConstAllocation<'tcx>) -> RValue<'gcc> {
297+
let alloc = alloc.inner();
297298
let mut llvals = Vec::with_capacity(alloc.relocations().len() + 1);
298299
let dl = cx.data_layout();
299300
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
347348
cx.const_struct(&llvals, true)
348349
}
349350

350-
pub fn codegen_static_initializer<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, def_id: DefId) -> Result<(RValue<'gcc>, &'tcx Allocation), ErrorHandled> {
351+
pub fn codegen_static_initializer<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, def_id: DefId) -> Result<(RValue<'gcc>, ConstAllocation<'tcx>), ErrorHandled> {
351352
let alloc = cx.tcx.eval_static_initializer(def_id)?;
352353
Ok((const_alloc_to_gcc(cx, alloc), alloc))
353354
}

src/context.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,13 @@ pub struct CodegenCx<'gcc, 'tcx> {
8989

9090
/// Cache of emitted const globals (value -> global)
9191
pub const_globals: RefCell<FxHashMap<RValue<'gcc>, RValue<'gcc>>>,
92+
9293
/// Map from the address of a global variable (rvalue) to the global variable itself (lvalue).
9394
/// TODO(antoyo): remove when the rustc API is fixed.
9495
pub global_lvalues: RefCell<FxHashMap<RValue<'gcc>, LValue<'gcc>>>,
9596

9697
/// Cache of constant strings,
97-
pub const_cstr_cache: RefCell<FxHashMap<Symbol, LValue<'gcc>>>,
98+
pub const_str_cache: RefCell<FxHashMap<Symbol, LValue<'gcc>>>,
9899

99100
/// Cache of globals.
100101
pub globals: RefCell<FxHashMap<String, RValue<'gcc>>>,
@@ -219,7 +220,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
219220
vtables: Default::default(),
220221
const_globals: Default::default(),
221222
global_lvalues: Default::default(),
222-
const_cstr_cache: Default::default(),
223+
const_str_cache: Default::default(),
223224
globals: Default::default(),
224225
scalar_types: Default::default(),
225226
types: Default::default(),

src/debuginfo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl<'a, 'gcc, 'tcx> DebugInfoBuilderMethods for Builder<'a, 'gcc, 'tcx> {
3131
}
3232

3333
impl<'gcc, 'tcx> DebugInfoMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
34-
fn create_vtable_metadata(&self, _ty: Ty<'tcx>, _trait_ref: Option<PolyExistentialTraitRef<'tcx>>, _vtable: Self::Value) {
34+
fn create_vtable_debuginfo(&self, _ty: Ty<'tcx>, _trait_ref: Option<PolyExistentialTraitRef<'tcx>>, _vtable: Self::Value) {
3535
// TODO(antoyo)
3636
}
3737

src/intrinsic/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,20 +260,20 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
260260
use rustc_target::abi::Abi::*;
261261
let tp_ty = substs.type_at(0);
262262
let layout = self.layout_of(tp_ty).layout;
263-
let _use_integer_compare = match layout.abi {
263+
let _use_integer_compare = match layout.abi() {
264264
Scalar(_) | ScalarPair(_, _) => true,
265265
Uninhabited | Vector { .. } => false,
266266
Aggregate { .. } => {
267267
// For rusty ABIs, small aggregates are actually passed
268268
// as `RegKind::Integer` (see `FnAbi::adjust_for_abi`),
269269
// so we re-use that same threshold here.
270-
layout.size <= self.data_layout().pointer_size * 2
270+
layout.size() <= self.data_layout().pointer_size * 2
271271
}
272272
};
273273

274274
let a = args[0].immediate();
275275
let b = args[1].immediate();
276-
if layout.size.bytes() == 0 {
276+
if layout.size().bytes() == 0 {
277277
self.const_bool(true)
278278
}
279279
/*else if use_integer_compare {
@@ -289,7 +289,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
289289
let void_ptr_type = self.context.new_type::<*const ()>();
290290
let a_ptr = self.bitcast(a, void_ptr_type);
291291
let b_ptr = self.bitcast(b, void_ptr_type);
292-
let n = self.context.new_cast(None, self.const_usize(layout.size.bytes()), self.sizet_type);
292+
let n = self.context.new_cast(None, self.const_usize(layout.size().bytes()), self.sizet_type);
293293
let builtin = self.context.get_builtin_function("memcmp");
294294
let cmp = self.context.new_call(None, builtin, &[a_ptr, b_ptr, n]);
295295
self.icmp(IntPredicate::IntEQ, cmp, self.const_i32(0))

src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ use rustc_codegen_ssa::back::lto::{LtoModuleCodegen, SerializedModule, ThinModul
6060
use rustc_codegen_ssa::target_features::supported_target_features;
6161
use rustc_codegen_ssa::traits::{CodegenBackend, ExtraBackendMethods, ModuleBufferMethods, ThinBufferMethods, WriteBackendMethods};
6262
use rustc_data_structures::fx::FxHashMap;
63-
use rustc_errors::{ErrorReported, Handler};
63+
use rustc_errors::{ErrorGuaranteed, Handler};
6464
use rustc_metadata::EncodedMetadata;
6565
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
6666
use rustc_middle::ty::TyCtxt;
@@ -108,7 +108,7 @@ impl CodegenBackend for GccCodegenBackend {
108108
Box::new(res)
109109
}
110110

111-
fn join_codegen(&self, ongoing_codegen: Box<dyn Any>, sess: &Session, _outputs: &OutputFilenames) -> Result<(CodegenResults, FxHashMap<WorkProductId, WorkProduct>), ErrorReported> {
111+
fn join_codegen(&self, ongoing_codegen: Box<dyn Any>, sess: &Session, _outputs: &OutputFilenames) -> Result<(CodegenResults, FxHashMap<WorkProductId, WorkProduct>), ErrorGuaranteed> {
112112
let (codegen_results, work_products) = ongoing_codegen
113113
.downcast::<rustc_codegen_ssa::back::write::OngoingCodegen<GccCodegenBackend>>()
114114
.expect("Expected GccCodegenBackend's OngoingCodegen, found Box<Any>")
@@ -117,7 +117,7 @@ impl CodegenBackend for GccCodegenBackend {
117117
Ok((codegen_results, work_products))
118118
}
119119

120-
fn link(&self, sess: &Session, codegen_results: CodegenResults, outputs: &OutputFilenames) -> Result<(), ErrorReported> {
120+
fn link(&self, sess: &Session, codegen_results: CodegenResults, outputs: &OutputFilenames) -> Result<(), ErrorGuaranteed> {
121121
use rustc_codegen_ssa::back::link::link_binary;
122122

123123
link_binary::<crate::archive::ArArchiveBuilder<'_>>(
@@ -147,7 +147,7 @@ impl ExtraBackendMethods for GccCodegenBackend {
147147
base::compile_codegen_unit(tcx, cgu_name, *self.supports_128bit_integers.lock().expect("lock"))
148148
}
149149

150-
fn target_machine_factory(&self, _sess: &Session, _opt_level: OptLevel) -> TargetMachineFactoryFn<Self> {
150+
fn target_machine_factory(&self, _sess: &Session, _opt_level: OptLevel, _features: &[String]) -> TargetMachineFactoryFn<Self> {
151151
// TODO(antoyo): set opt level.
152152
Arc::new(|_| {
153153
Ok(())

src/type_of.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ pub fn uncached_gcc_type<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, layout: TyAndLa
5656
if let (&ty::Adt(def, _), &Variants::Single { index }) =
5757
(layout.ty.kind(), &layout.variants)
5858
{
59-
if def.is_enum() && !def.variants.is_empty() {
60-
write!(&mut name, "::{}", def.variants[index].name).unwrap();
59+
if def.is_enum() && !def.variants().is_empty() {
60+
write!(&mut name, "::{}", def.variant(index).name).unwrap();
6161
}
6262
}
6363
if let (&ty::Generator(_, _, _), &Variants::Single { index }) =

0 commit comments

Comments
 (0)