Skip to content

Commit

Permalink
Update to nightly-2021-09-11 (rust-lang#79)
Browse files Browse the repository at this point in the history
* Implement `black_box` as intrinsic

Responsibility of implementing the black box is now lies on backend

* Remove some TODOs

* Update to nightly-2021-09-17

* CI: don't fail on warnings
  • Loading branch information
Commeownist committed Sep 17, 2021
1 parent 8ec7976 commit 48d60ab
Show file tree
Hide file tree
Showing 14 changed files with 117 additions and 149 deletions.
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nightly-2021-08-12
nightly-2021-09-17
5 changes: 4 additions & 1 deletion src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rustc_span::symbol::sym;

use crate::GccContext;

pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut GccContext, kind: AllocatorKind, has_alloc_error_handler: bool) {
pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut GccContext, _module_name: &str, kind: AllocatorKind, has_alloc_error_handler: bool) {
let context = &mods.context;
let usize =
match tcx.sess.target.pointer_width {
Expand Down Expand Up @@ -77,6 +77,9 @@ pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut GccContext, kind: Alloc
else {
block.end_with_void_return(None);
}

// TODO(@Commeownist): Check if we need to emit some extra debugging info in certain circumstances
// as described in https://github.com/rust-lang/rust/commit/77a96ed5646f7c3ee8897693decc4626fe380643
}

let types = [usize, usize];
Expand Down
94 changes: 21 additions & 73 deletions src/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ use std::fs::File;
use std::path::{Path, PathBuf};

use rustc_session::Session;
use rustc_codegen_ssa::back::archive::{find_library, ArchiveBuilder};
use rustc_codegen_ssa::METADATA_FILENAME;
use rustc_codegen_ssa::back::archive::ArchiveBuilder;

use rustc_data_structures::temp_dir::MaybeTempDir;
use rustc_middle::middle::cstore::DllImport;
use rustc_span::symbol::Symbol;


struct ArchiveConfig<'a> {
sess: &'a Session,
dst: PathBuf,
lib_search_paths: Vec<PathBuf>,
use_native_ar: bool,
use_gnu_style_archive: bool,
}
Expand All @@ -35,11 +34,9 @@ pub struct ArArchiveBuilder<'a> {

impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
fn new(sess: &'a Session, output: &Path, input: Option<&Path>) -> Self {
use rustc_codegen_ssa::back::link::archive_search_paths;
let config = ArchiveConfig {
sess,
dst: output.to_path_buf(),
lib_search_paths: archive_search_paths(sess),
use_native_ar: false,
// FIXME test for linux and System V derivatives instead
use_gnu_style_archive: sess.target.options.archive_format == "gnu",
Expand Down Expand Up @@ -94,47 +91,27 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
));
}

fn add_native_library(&mut self, name: Symbol, verbatim: bool) {
let location = find_library(name, verbatim, &self.config.lib_search_paths, self.config.sess);
self.add_archive(location.clone(), |_| false)
.unwrap_or_else(|e| {
panic!(
"failed to add native library {}: {}",
location.to_string_lossy(),
e
);
});
}

fn add_rlib(
&mut self,
rlib: &Path,
name: &str,
lto: bool,
skip_objects: bool,
) -> std::io::Result<()> {
let obj_start = name.to_owned();

self.add_archive(rlib.to_owned(), move |fname: &str| {
// Ignore metadata files, no matter the name.
if fname == METADATA_FILENAME {
return true;
}

// Don't include Rust objects if LTO is enabled
if lto && fname.starts_with(&obj_start) && fname.ends_with(".o") {
return true;
}
fn add_archive<F>(&mut self, archive_path: &Path, mut skip: F) -> std::io::Result<()>
where
F: FnMut(&str) -> bool + 'static,
{
let mut archive = ar::Archive::new(std::fs::File::open(&archive_path)?);
let archive_index = self.src_archives.len();

// Otherwise if this is *not* a rust object and we're skipping
// objects then skip this file
if skip_objects && (!fname.starts_with(&obj_start) || !fname.ends_with(".o")) {
return true;
let mut i = 0;
while let Some(entry) = archive.next_entry() {
let entry = entry?;
let file_name = String::from_utf8(entry.header().identifier().to_vec())
.map_err(|err| std::io::Error::new(std::io::ErrorKind::InvalidData, err))?;
if !skip(&file_name) {
self.entries
.push((file_name, ArchiveEntry::FromArchive { archive_index, entry_index: i }));
}
i += 1;
}

// ok, don't skip this
return false;
})
self.src_archives.push((archive_path.to_owned(), archive));
Ok(())
}

fn update_symbols(&mut self) {
Expand Down Expand Up @@ -239,32 +216,3 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
unimplemented!();
}
}

impl<'a> ArArchiveBuilder<'a> {
fn add_archive<F>(&mut self, archive_path: PathBuf, mut skip: F) -> std::io::Result<()>
where
F: FnMut(&str) -> bool + 'static,
{
let mut archive = ar::Archive::new(std::fs::File::open(&archive_path)?);
let archive_index = self.src_archives.len();

let mut i = 0;
while let Some(entry) = archive.next_entry() {
let entry = entry.unwrap();
let file_name = String::from_utf8(entry.header().identifier().to_vec()).unwrap();
if !skip(&file_name) {
self.entries.push((
file_name,
ArchiveEntry::FromArchive {
archive_index,
entry_index: i,
},
));
}
i += 1;
}

self.src_archives.push((archive_path, archive));
Ok(())
}
}
38 changes: 18 additions & 20 deletions src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,26 +107,10 @@ enum ConstraintOrRegister {


impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
fn codegen_llvm_inline_asm(&mut self, ia: &LlvmInlineAsmInner, outputs: Vec<PlaceRef<'tcx, RValue<'gcc>>>, inputs: Vec<RValue<'gcc>>, span: Span) -> bool {
if ia.asm.as_str().is_empty() && outputs.is_empty() {
// TODO(@Commeownist): there's one use of `llvm_asm` in rustc sysroot we can't get rid of just yet.
// Fortunately, it's used as a simple black box to make sure that inputs are not optimized away.
// Let's just emulate it.
let block = self.llbb();
let extended_asm = block.add_extended_asm(None, "");
for input in inputs {
extended_asm.add_input_operand(None, "r", input);
}
extended_asm.add_clobber("memory");
extended_asm.set_volatile_flag(true);
}
else {
// TODO(@Commeownist): switch to `struct_span_err_with_code`
// once we get this merged into rustc
self.sess().struct_span_err(span, "GCC backend does not support `llvm_asm!`")
.help("consider using the `asm!` macro instead")
.emit();
}
fn codegen_llvm_inline_asm(&mut self, _ia: &LlvmInlineAsmInner, _outputs: Vec<PlaceRef<'tcx, RValue<'gcc>>>, _inputs: Vec<RValue<'gcc>>, span: Span) -> bool {
self.sess().struct_span_err(span, "GCC backend does not support `llvm_asm!`")
.help("consider using the `asm!` macro instead")
.emit();

// We return `true` even if we've failed to generate the asm
// because we want to suppress the "malformed inline assembly" error
Expand Down Expand Up @@ -579,6 +563,10 @@ fn reg_to_gcc(reg: InlineAsmRegOrRegClass) -> ConstraintOrRegister {
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::reg) => unimplemented!(),
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::reg_nonzero) => unimplemented!(),
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::freg) => unimplemented!(),
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::cr)
| InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::xer) => {
unreachable!("clobber-only")
},
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::reg) => unimplemented!(),
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::freg) => unimplemented!(),
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::vreg) => unimplemented!(),
Expand All @@ -596,6 +584,8 @@ fn reg_to_gcc(reg: InlineAsmRegOrRegClass) -> ConstraintOrRegister {
InlineAsmRegClass::SpirV(SpirVInlineAsmRegClass::reg) => {
bug!("GCC backend does not support SPIR-V")
}
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::reg) => unimplemented!(),
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::freg) => unimplemented!(),
InlineAsmRegClass::Err => unreachable!(),
}
};
Expand Down Expand Up @@ -635,6 +625,10 @@ fn dummy_output_type<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, reg: InlineAsmRegCl
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::reg) => cx.type_i32(),
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::reg_nonzero) => cx.type_i32(),
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::freg) => cx.type_f64(),
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::cr)
| InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::xer) => {
unreachable!("clobber-only")
},
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::reg) => cx.type_i32(),
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::freg) => cx.type_f32(),
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::vreg) => cx.type_f32(),
Expand All @@ -651,6 +645,8 @@ fn dummy_output_type<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, reg: InlineAsmRegCl
InlineAsmRegClass::SpirV(SpirVInlineAsmRegClass::reg) => {
bug!("LLVM backend does not support SPIR-V")
},
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::reg) => cx.type_i32(),
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::freg) => cx.type_f64(),
InlineAsmRegClass::Err => unreachable!(),
}
}
Expand Down Expand Up @@ -765,6 +761,8 @@ fn modifier_to_gcc(arch: InlineAsmArch, reg: InlineAsmRegClass, modifier: Option
InlineAsmRegClass::SpirV(SpirVInlineAsmRegClass::reg) => {
bug!("LLVM backend does not support SPIR-V")
},
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::reg) => unimplemented!(),
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::freg) => unimplemented!(),
InlineAsmRegClass::Err => unreachable!(),
}
}
27 changes: 13 additions & 14 deletions src/builder.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::borrow::Cow;
use std::cell::Cell;
use std::convert::TryFrom;
use std::ops::{Deref, Range};
use std::ops::Deref;

use gccjit::FunctionType;
use gccjit::{
Expand Down Expand Up @@ -31,16 +31,16 @@ use rustc_codegen_ssa::traits::{
StaticBuilderMethods,
};
use rustc_middle::ty::{ParamEnv, Ty, TyCtxt};
use rustc_middle::ty::layout::{HasParamEnv, HasTyCtxt, TyAndLayout};
use rustc_middle::ty::layout::{HasParamEnv, HasTyCtxt, LayoutError, LayoutOfHelpers, TyAndLayout};
use rustc_span::Span;
use rustc_span::def_id::DefId;
use rustc_target::abi::{
self,
Align,
HasDataLayout,
LayoutOf,
Size,
TargetDataLayout,
WrappingRange,
};
use rustc_target::spec::{HasTargetSpec, Target};

Expand Down Expand Up @@ -338,12 +338,12 @@ impl HasDataLayout for Builder<'_, '_, '_> {
}
}

impl<'tcx> LayoutOf for Builder<'_, '_, 'tcx> {
type Ty = Ty<'tcx>;
type TyAndLayout = TyAndLayout<'tcx>;
impl<'tcx> LayoutOfHelpers<'tcx> for Builder<'_, '_, 'tcx> {
type LayoutOfResult = TyAndLayout<'tcx>;

fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyAndLayout {
self.cx.layout_of(ty)
#[inline]
fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! {
self.cx.handle_layout_err(err, span, ty)
}
}

Expand Down Expand Up @@ -818,12 +818,11 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
let vr = scalar.valid_range.clone();
match scalar.value {
abi::Int(..) => {
let range = scalar.valid_range_exclusive(bx);
if range.start != range.end {
bx.range_metadata(load, range);
if !scalar.is_always_valid(bx) {
bx.range_metadata(load, scalar.valid_range);
}
}
abi::Pointer if vr.start() < vr.end() && !vr.contains(&0) => {
abi::Pointer if vr.start < vr.end && !vr.contains(0) => {
bx.nonnull_metadata(load);
}
_ => {}
Expand Down Expand Up @@ -894,7 +893,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
next_bx
}

fn range_metadata(&mut self, _load: RValue<'gcc>, _range: Range<u128>) {
fn range_metadata(&mut self, _load: RValue<'gcc>, _range: WrappingRange) {
// TODO(antoyo)
}

Expand Down Expand Up @@ -1378,7 +1377,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
}
}

fn to_immediate_scalar(&mut self, val: Self::Value, scalar: &abi::Scalar) -> Self::Value {
fn to_immediate_scalar(&mut self, val: Self::Value, scalar: abi::Scalar) -> Self::Value {
if scalar.is_bool() {
return self.trunc(val, self.cx().type_i1());
}
Expand Down
1 change: 0 additions & 1 deletion src/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ pub fn get_fn<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, instance: Instance<'tcx>)

assert!(!instance.substs.needs_infer());
assert!(!instance.substs.has_escaping_bound_vars());
assert!(!instance.substs.has_param_types_or_consts());

if let Some(&func) = cx.instances.borrow().get(&instance) {
return func;
Expand Down
9 changes: 5 additions & 4 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ use rustc_codegen_ssa::traits::{
};
use rustc_middle::bug;
use rustc_middle::mir::Mutability;
use rustc_middle::ty::{layout::TyAndLayout, ScalarInt};
use rustc_mir::interpret::{Allocation, GlobalAlloc, Scalar};
use rustc_middle::ty::ScalarInt;
use rustc_middle::ty::layout::{TyAndLayout, LayoutOf};
use rustc_middle::mir::interpret::{Allocation, GlobalAlloc, Scalar};
use rustc_span::Symbol;
use rustc_target::abi::{self, HasDataLayout, LayoutOf, Pointer, Size};
use rustc_target::abi::{self, HasDataLayout, Pointer, Size};

use crate::consts::const_alloc_to_gcc;
use crate::context::CodegenCx;
Expand Down Expand Up @@ -212,7 +213,7 @@ impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
None
}

fn scalar_to_backend(&self, cv: Scalar, layout: &abi::Scalar, ty: Type<'gcc>) -> RValue<'gcc> {
fn scalar_to_backend(&self, cv: Scalar, layout: abi::Scalar, ty: Type<'gcc>) -> RValue<'gcc> {
let bitsize = if layout.is_bool() { 1 } else { layout.value.size(self).bits() };
match cv {
Scalar::Int(ScalarInt::ZST) => {
Expand Down
11 changes: 8 additions & 3 deletions src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ use rustc_middle::{bug, span_bug};
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
use rustc_middle::mir::mono::MonoItem;
use rustc_middle::ty::{self, Instance, Ty};
use rustc_mir::interpret::{self, Allocation, ErrorHandled, Scalar as InterpScalar, read_target_uint};
use rustc_middle::ty::layout::LayoutOf;
use rustc_middle::mir::interpret::{self, Allocation, ErrorHandled, Scalar as InterpScalar, read_target_uint};
use rustc_span::Span;
use rustc_span::def_id::DefId;
use rustc_target::abi::{self, Align, HasDataLayout, LayoutOf, Primitive, Size};
use rustc_target::abi::{self, Align, HasDataLayout, Primitive, Size, WrappingRange};

use crate::base;
use crate::context::CodegenCx;
Expand Down Expand Up @@ -182,6 +183,10 @@ impl<'gcc, 'tcx> StaticMethods for CodegenCx<'gcc, 'tcx> {
fn add_used_global(&self, _global: RValue<'gcc>) {
// TODO(antoyo)
}

fn add_compiler_used_global(&self, _global: RValue<'gcc>) {
// TODO(antoyo)
}
}

impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
Expand Down Expand Up @@ -350,7 +355,7 @@ pub fn const_alloc_to_gcc<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, alloc: &Alloca
interpret::Pointer::new(alloc_id, Size::from_bytes(ptr_offset)),
&cx.tcx,
),
&abi::Scalar { value: Primitive::Pointer, valid_range: 0..=!0 },
abi::Scalar { value: Primitive::Pointer, valid_range: WrappingRange { start: 0, end: !0 } },
cx.type_i8p(),
));
next_offset = offset + pointer_size;
Expand Down
Loading

0 comments on commit 48d60ab

Please sign in to comment.