Skip to content

Commit 1e9d9b1

Browse files
committed
merge rustc history
2 parents f0e4083 + 14e0e0f commit 1e9d9b1

File tree

12 files changed

+362
-211
lines changed

12 files changed

+362
-211
lines changed

src/abi.rs

-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ use crate::intrinsic::ArgAbiExt;
1111
use crate::type_of::LayoutGccExt;
1212

1313
impl<'a, 'gcc, 'tcx> AbiBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
14-
fn apply_attrs_callsite(&mut self, _fn_abi: &FnAbi<'tcx, Ty<'tcx>>, _callsite: Self::Value) {
15-
// TODO(antoyo)
16-
}
17-
1814
fn get_param(&mut self, index: usize) -> Self::Value {
1915
let func = self.current_func();
2016
let param = func.get_param(index as i32);

src/archive.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use std::fs::File;
22
use std::path::{Path, PathBuf};
33

4+
use crate::errors::RanlibFailure;
5+
46
use rustc_codegen_ssa::back::archive::{ArchiveBuilder, ArchiveBuilderBuilder};
57
use rustc_session::Session;
68

@@ -181,7 +183,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
181183
std::process::Command::new("ranlib").arg(output).status().expect("Couldn't run ranlib");
182184

183185
if !status.success() {
184-
self.config.sess.fatal(&format!("Ranlib exited with code {:?}", status.code()));
186+
self.config.sess.emit_fatal(RanlibFailure::new(status.code()));
185187
}
186188

187189
any_members

src/asm.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use std::borrow::Cow;
1212

1313
use crate::builder::Builder;
1414
use crate::context::CodegenCx;
15+
use crate::errors::UnwindingInlineAsm;
1516
use crate::type_of::LayoutGccExt;
1617
use crate::callee::get_fn;
1718

@@ -109,7 +110,7 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
109110
fn codegen_inline_asm(&mut self, template: &[InlineAsmTemplatePiece], rust_operands: &[InlineAsmOperandRef<'tcx, Self>], options: InlineAsmOptions, span: &[Span], _instance: Instance<'_>, _dest_catch_funclet: Option<(Self::BasicBlock, Self::BasicBlock, Option<&Self::Funclet>)>) {
110111
if options.contains(InlineAsmOptions::MAY_UNWIND) {
111112
self.sess()
112-
.struct_span_err(span[0], "GCC backend does not support unwinding from inline asm")
113+
.create_err(UnwindingInlineAsm { span: span[0] })
113114
.emit();
114115
return;
115116
}
@@ -497,7 +498,7 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
497498
if options.contains(InlineAsmOptions::NORETURN) {
498499
let builtin_unreachable = self.context.get_builtin_function("__builtin_unreachable");
499500
let builtin_unreachable: RValue<'gcc> = unsafe { std::mem::transmute(builtin_unreachable) };
500-
self.call(self.type_void(), builtin_unreachable, &[], None);
501+
self.call(self.type_void(), None, builtin_unreachable, &[], None);
501502
}
502503

503504
// Write results to outputs.

src/builder.rs

+28-9
Original file line numberDiff line numberDiff line change
@@ -444,11 +444,23 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
444444
self.block.end_with_switch(None, value, default_block, &gcc_cases);
445445
}
446446

447-
fn invoke(&mut self, typ: Type<'gcc>, func: RValue<'gcc>, args: &[RValue<'gcc>], then: Block<'gcc>, catch: Block<'gcc>, _funclet: Option<&Funclet>) -> RValue<'gcc> {
447+
fn invoke(
448+
&mut self,
449+
typ: Type<'gcc>,
450+
fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>,
451+
func: RValue<'gcc>,
452+
args: &[RValue<'gcc>],
453+
then: Block<'gcc>,
454+
catch: Block<'gcc>,
455+
_funclet: Option<&Funclet>,
456+
) -> RValue<'gcc> {
448457
// TODO(bjorn3): Properly implement unwinding.
449-
let call_site = self.call(typ, func, args, None);
458+
let call_site = self.call(typ, None, func, args, None);
450459
let condition = self.context.new_rvalue_from_int(self.bool_type, 1);
451460
self.llbb().end_with_conditional(None, condition, then, catch);
461+
if let Some(_fn_abi) = fn_abi {
462+
// TODO(bjorn3): Apply function attributes
463+
}
452464
call_site
453465
}
454466

@@ -643,11 +655,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
643655
self.current_func().new_local(None, aligned_type, &format!("stack_var_{}", self.stack_var_count.get())).get_address(None)
644656
}
645657

646-
fn dynamic_alloca(&mut self, _ty: Type<'gcc>, _align: Align) -> RValue<'gcc> {
647-
unimplemented!();
648-
}
649-
650-
fn array_alloca(&mut self, _ty: Type<'gcc>, _len: RValue<'gcc>, _align: Align) -> RValue<'gcc> {
658+
fn byte_array_alloca(&mut self, _len: RValue<'gcc>, _align: Align) -> RValue<'gcc> {
651659
unimplemented!();
652660
}
653661

@@ -1227,16 +1235,27 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
12271235
// TODO(antoyo)
12281236
}
12291237

1230-
fn call(&mut self, _typ: Type<'gcc>, func: RValue<'gcc>, args: &[RValue<'gcc>], funclet: Option<&Funclet>) -> RValue<'gcc> {
1238+
fn call(
1239+
&mut self,
1240+
_typ: Type<'gcc>,
1241+
fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>,
1242+
func: RValue<'gcc>,
1243+
args: &[RValue<'gcc>],
1244+
funclet: Option<&Funclet>,
1245+
) -> RValue<'gcc> {
12311246
// FIXME(antoyo): remove when having a proper API.
12321247
let gcc_func = unsafe { std::mem::transmute(func) };
1233-
if self.functions.borrow().values().find(|value| **value == gcc_func).is_some() {
1248+
let call = if self.functions.borrow().values().find(|value| **value == gcc_func).is_some() {
12341249
self.function_call(func, args, funclet)
12351250
}
12361251
else {
12371252
// If it's a not function that was defined, it's a function pointer.
12381253
self.function_ptr_call(func, args, funclet)
1254+
};
1255+
if let Some(_fn_abi) = fn_abi {
1256+
// TODO(bjorn3): Apply function attributes
12391257
}
1258+
call
12401259
}
12411260

12421261
fn zext(&mut self, value: RValue<'gcc>, dest_typ: Type<'gcc>) -> RValue<'gcc> {

src/consts.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc_target::abi::{self, Align, HasDataLayout, Primitive, Size, WrappingRan
1414

1515
use crate::base;
1616
use crate::context::CodegenCx;
17+
use crate::errors::LinkageConstOrMutType;
1718
use crate::type_of::LayoutGccExt;
1819

1920
impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
@@ -368,10 +369,7 @@ fn check_and_apply_linkage<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, attrs: &Codeg
368369
cx.layout_of(mt.ty).gcc_type(cx, true)
369370
}
370371
else {
371-
cx.sess().span_fatal(
372-
span,
373-
"must have type `*const T` or `*mut T` due to `#[linkage]` attribute",
374-
)
372+
cx.sess().emit_fatal(LinkageConstOrMutType { span: span })
375373
};
376374
// Declare a symbol `foo` with the desired linkage.
377375
let global1 = cx.declare_global_with_linkage(&sym, llty2, base::global_linkage_to_gcc(linkage));

src/context.rs

+4-20
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_middle::mir::mono::CodegenUnit;
1313
use rustc_middle::ty::{self, Instance, ParamEnv, PolyExistentialTraitRef, Ty, TyCtxt};
1414
use rustc_middle::ty::layout::{FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasParamEnv, HasTyCtxt, LayoutError, TyAndLayout, LayoutOfHelpers};
1515
use rustc_session::Session;
16-
use rustc_span::Span;
16+
use rustc_span::{Span, source_map::respan};
1717
use rustc_target::abi::{call::FnAbi, HasDataLayout, PointeeInfo, Size, TargetDataLayout, VariantIdx};
1818
use rustc_target::spec::{HasTargetSpec, Target, TlsModel};
1919

@@ -293,7 +293,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
293293
self.is_native_int_type(typ) || self.is_non_native_int_type(typ) || typ.is_compatible_with(self.bool_type)
294294
}
295295

296-
pub fn sess(&self) -> &Session {
296+
pub fn sess(&self) -> &'tcx Session {
297297
&self.tcx.sess
298298
}
299299

@@ -416,10 +416,6 @@ impl<'gcc, 'tcx> MiscMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
416416
self.codegen_unit
417417
}
418418

419-
fn used_statics(&self) -> &RefCell<Vec<RValue<'gcc>>> {
420-
unimplemented!();
421-
}
422-
423419
fn set_frame_pointer_type(&self, _llfn: RValue<'gcc>) {
424420
// TODO(antoyo)
425421
}
@@ -428,10 +424,6 @@ impl<'gcc, 'tcx> MiscMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
428424
// TODO(antoyo)
429425
}
430426

431-
fn create_used_variable(&self) {
432-
unimplemented!();
433-
}
434-
435427
fn declare_c_main(&self, fn_type: Self::Type) -> Option<Self::Function> {
436428
if self.get_declared_value("main").is_none() {
437429
Some(self.declare_cfn("main", fn_type))
@@ -443,14 +435,6 @@ impl<'gcc, 'tcx> MiscMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
443435
None
444436
}
445437
}
446-
447-
fn compiler_used_statics(&self) -> &RefCell<Vec<RValue<'gcc>>> {
448-
unimplemented!()
449-
}
450-
451-
fn create_compiler_used_variable(&self) {
452-
unimplemented!()
453-
}
454438
}
455439

456440
impl<'gcc, 'tcx> HasTyCtxt<'tcx> for CodegenCx<'gcc, 'tcx> {
@@ -477,7 +461,7 @@ impl<'gcc, 'tcx> LayoutOfHelpers<'tcx> for CodegenCx<'gcc, 'tcx> {
477461
#[inline]
478462
fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! {
479463
if let LayoutError::SizeOverflow(_) = err {
480-
self.sess().span_fatal(span, &err.to_string())
464+
self.sess().emit_fatal(respan(span, err))
481465
} else {
482466
span_bug!(span, "failed to get layout for `{}`: {}", ty, err)
483467
}
@@ -495,7 +479,7 @@ impl<'gcc, 'tcx> FnAbiOfHelpers<'tcx> for CodegenCx<'gcc, 'tcx> {
495479
fn_abi_request: FnAbiRequest<'tcx>,
496480
) -> ! {
497481
if let FnAbiError::Layout(LayoutError::SizeOverflow(_)) = err {
498-
self.sess().span_fatal(span, &err.to_string())
482+
self.sess().emit_fatal(respan(span, err))
499483
} else {
500484
match fn_abi_request {
501485
FnAbiRequest::OfFnPtr { sig, extra_args } => {

0 commit comments

Comments
 (0)