Skip to content

Commit 48d60ab

Browse files
author
Commeownist
authored
Update to nightly-2021-09-11 (#79)
* 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
1 parent 8ec7976 commit 48d60ab

14 files changed

+117
-149
lines changed

rust-toolchain

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nightly-2021-08-12
1+
nightly-2021-09-17

src/allocator.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_span::symbol::sym;
66

77
use crate::GccContext;
88

9-
pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut GccContext, kind: AllocatorKind, has_alloc_error_handler: bool) {
9+
pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut GccContext, _module_name: &str, kind: AllocatorKind, has_alloc_error_handler: bool) {
1010
let context = &mods.context;
1111
let usize =
1212
match tcx.sess.target.pointer_width {
@@ -77,6 +77,9 @@ pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut GccContext, kind: Alloc
7777
else {
7878
block.end_with_void_return(None);
7979
}
80+
81+
// TODO(@Commeownist): Check if we need to emit some extra debugging info in certain circumstances
82+
// as described in https://github.com/rust-lang/rust/commit/77a96ed5646f7c3ee8897693decc4626fe380643
8083
}
8184

8285
let types = [usize, usize];

src/archive.rs

+21-73
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@ use std::fs::File;
22
use std::path::{Path, PathBuf};
33

44
use rustc_session::Session;
5-
use rustc_codegen_ssa::back::archive::{find_library, ArchiveBuilder};
6-
use rustc_codegen_ssa::METADATA_FILENAME;
5+
use rustc_codegen_ssa::back::archive::ArchiveBuilder;
6+
77
use rustc_data_structures::temp_dir::MaybeTempDir;
88
use rustc_middle::middle::cstore::DllImport;
9-
use rustc_span::symbol::Symbol;
9+
1010

1111
struct ArchiveConfig<'a> {
1212
sess: &'a Session,
1313
dst: PathBuf,
14-
lib_search_paths: Vec<PathBuf>,
1514
use_native_ar: bool,
1615
use_gnu_style_archive: bool,
1716
}
@@ -35,11 +34,9 @@ pub struct ArArchiveBuilder<'a> {
3534

3635
impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
3736
fn new(sess: &'a Session, output: &Path, input: Option<&Path>) -> Self {
38-
use rustc_codegen_ssa::back::link::archive_search_paths;
3937
let config = ArchiveConfig {
4038
sess,
4139
dst: output.to_path_buf(),
42-
lib_search_paths: archive_search_paths(sess),
4340
use_native_ar: false,
4441
// FIXME test for linux and System V derivatives instead
4542
use_gnu_style_archive: sess.target.options.archive_format == "gnu",
@@ -94,47 +91,27 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
9491
));
9592
}
9693

97-
fn add_native_library(&mut self, name: Symbol, verbatim: bool) {
98-
let location = find_library(name, verbatim, &self.config.lib_search_paths, self.config.sess);
99-
self.add_archive(location.clone(), |_| false)
100-
.unwrap_or_else(|e| {
101-
panic!(
102-
"failed to add native library {}: {}",
103-
location.to_string_lossy(),
104-
e
105-
);
106-
});
107-
}
108-
109-
fn add_rlib(
110-
&mut self,
111-
rlib: &Path,
112-
name: &str,
113-
lto: bool,
114-
skip_objects: bool,
115-
) -> std::io::Result<()> {
116-
let obj_start = name.to_owned();
117-
118-
self.add_archive(rlib.to_owned(), move |fname: &str| {
119-
// Ignore metadata files, no matter the name.
120-
if fname == METADATA_FILENAME {
121-
return true;
122-
}
123-
124-
// Don't include Rust objects if LTO is enabled
125-
if lto && fname.starts_with(&obj_start) && fname.ends_with(".o") {
126-
return true;
127-
}
94+
fn add_archive<F>(&mut self, archive_path: &Path, mut skip: F) -> std::io::Result<()>
95+
where
96+
F: FnMut(&str) -> bool + 'static,
97+
{
98+
let mut archive = ar::Archive::new(std::fs::File::open(&archive_path)?);
99+
let archive_index = self.src_archives.len();
128100

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

135-
// ok, don't skip this
136-
return false;
137-
})
113+
self.src_archives.push((archive_path.to_owned(), archive));
114+
Ok(())
138115
}
139116

140117
fn update_symbols(&mut self) {
@@ -239,32 +216,3 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
239216
unimplemented!();
240217
}
241218
}
242-
243-
impl<'a> ArArchiveBuilder<'a> {
244-
fn add_archive<F>(&mut self, archive_path: PathBuf, mut skip: F) -> std::io::Result<()>
245-
where
246-
F: FnMut(&str) -> bool + 'static,
247-
{
248-
let mut archive = ar::Archive::new(std::fs::File::open(&archive_path)?);
249-
let archive_index = self.src_archives.len();
250-
251-
let mut i = 0;
252-
while let Some(entry) = archive.next_entry() {
253-
let entry = entry.unwrap();
254-
let file_name = String::from_utf8(entry.header().identifier().to_vec()).unwrap();
255-
if !skip(&file_name) {
256-
self.entries.push((
257-
file_name,
258-
ArchiveEntry::FromArchive {
259-
archive_index,
260-
entry_index: i,
261-
},
262-
));
263-
}
264-
i += 1;
265-
}
266-
267-
self.src_archives.push((archive_path, archive));
268-
Ok(())
269-
}
270-
}

src/asm.rs

+18-20
Original file line numberDiff line numberDiff line change
@@ -107,26 +107,10 @@ enum ConstraintOrRegister {
107107

108108

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

131115
// We return `true` even if we've failed to generate the asm
132116
// because we want to suppress the "malformed inline assembly" error
@@ -579,6 +563,10 @@ fn reg_to_gcc(reg: InlineAsmRegOrRegClass) -> ConstraintOrRegister {
579563
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::reg) => unimplemented!(),
580564
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::reg_nonzero) => unimplemented!(),
581565
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::freg) => unimplemented!(),
566+
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::cr)
567+
| InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::xer) => {
568+
unreachable!("clobber-only")
569+
},
582570
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::reg) => unimplemented!(),
583571
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::freg) => unimplemented!(),
584572
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::vreg) => unimplemented!(),
@@ -596,6 +584,8 @@ fn reg_to_gcc(reg: InlineAsmRegOrRegClass) -> ConstraintOrRegister {
596584
InlineAsmRegClass::SpirV(SpirVInlineAsmRegClass::reg) => {
597585
bug!("GCC backend does not support SPIR-V")
598586
}
587+
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::reg) => unimplemented!(),
588+
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::freg) => unimplemented!(),
599589
InlineAsmRegClass::Err => unreachable!(),
600590
}
601591
};
@@ -635,6 +625,10 @@ fn dummy_output_type<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, reg: InlineAsmRegCl
635625
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::reg) => cx.type_i32(),
636626
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::reg_nonzero) => cx.type_i32(),
637627
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::freg) => cx.type_f64(),
628+
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::cr)
629+
| InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::xer) => {
630+
unreachable!("clobber-only")
631+
},
638632
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::reg) => cx.type_i32(),
639633
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::freg) => cx.type_f32(),
640634
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::vreg) => cx.type_f32(),
@@ -651,6 +645,8 @@ fn dummy_output_type<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, reg: InlineAsmRegCl
651645
InlineAsmRegClass::SpirV(SpirVInlineAsmRegClass::reg) => {
652646
bug!("LLVM backend does not support SPIR-V")
653647
},
648+
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::reg) => cx.type_i32(),
649+
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::freg) => cx.type_f64(),
654650
InlineAsmRegClass::Err => unreachable!(),
655651
}
656652
}
@@ -765,6 +761,8 @@ fn modifier_to_gcc(arch: InlineAsmArch, reg: InlineAsmRegClass, modifier: Option
765761
InlineAsmRegClass::SpirV(SpirVInlineAsmRegClass::reg) => {
766762
bug!("LLVM backend does not support SPIR-V")
767763
},
764+
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::reg) => unimplemented!(),
765+
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::freg) => unimplemented!(),
768766
InlineAsmRegClass::Err => unreachable!(),
769767
}
770768
}

src/builder.rs

+13-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::borrow::Cow;
22
use std::cell::Cell;
33
use std::convert::TryFrom;
4-
use std::ops::{Deref, Range};
4+
use std::ops::Deref;
55

66
use gccjit::FunctionType;
77
use gccjit::{
@@ -31,16 +31,16 @@ use rustc_codegen_ssa::traits::{
3131
StaticBuilderMethods,
3232
};
3333
use rustc_middle::ty::{ParamEnv, Ty, TyCtxt};
34-
use rustc_middle::ty::layout::{HasParamEnv, HasTyCtxt, TyAndLayout};
34+
use rustc_middle::ty::layout::{HasParamEnv, HasTyCtxt, LayoutError, LayoutOfHelpers, TyAndLayout};
3535
use rustc_span::Span;
3636
use rustc_span::def_id::DefId;
3737
use rustc_target::abi::{
3838
self,
3939
Align,
4040
HasDataLayout,
41-
LayoutOf,
4241
Size,
4342
TargetDataLayout,
43+
WrappingRange,
4444
};
4545
use rustc_target::spec::{HasTargetSpec, Target};
4646

@@ -338,12 +338,12 @@ impl HasDataLayout for Builder<'_, '_, '_> {
338338
}
339339
}
340340

341-
impl<'tcx> LayoutOf for Builder<'_, '_, 'tcx> {
342-
type Ty = Ty<'tcx>;
343-
type TyAndLayout = TyAndLayout<'tcx>;
341+
impl<'tcx> LayoutOfHelpers<'tcx> for Builder<'_, '_, 'tcx> {
342+
type LayoutOfResult = TyAndLayout<'tcx>;
344343

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

@@ -818,12 +818,11 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
818818
let vr = scalar.valid_range.clone();
819819
match scalar.value {
820820
abi::Int(..) => {
821-
let range = scalar.valid_range_exclusive(bx);
822-
if range.start != range.end {
823-
bx.range_metadata(load, range);
821+
if !scalar.is_always_valid(bx) {
822+
bx.range_metadata(load, scalar.valid_range);
824823
}
825824
}
826-
abi::Pointer if vr.start() < vr.end() && !vr.contains(&0) => {
825+
abi::Pointer if vr.start < vr.end && !vr.contains(0) => {
827826
bx.nonnull_metadata(load);
828827
}
829828
_ => {}
@@ -894,7 +893,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
894893
next_bx
895894
}
896895

897-
fn range_metadata(&mut self, _load: RValue<'gcc>, _range: Range<u128>) {
896+
fn range_metadata(&mut self, _load: RValue<'gcc>, _range: WrappingRange) {
898897
// TODO(antoyo)
899898
}
900899

@@ -1378,7 +1377,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
13781377
}
13791378
}
13801379

1381-
fn to_immediate_scalar(&mut self, val: Self::Value, scalar: &abi::Scalar) -> Self::Value {
1380+
fn to_immediate_scalar(&mut self, val: Self::Value, scalar: abi::Scalar) -> Self::Value {
13821381
if scalar.is_bool() {
13831382
return self.trunc(val, self.cx().type_i1());
13841383
}

src/callee.rs

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ pub fn get_fn<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, instance: Instance<'tcx>)
1919

2020
assert!(!instance.substs.needs_infer());
2121
assert!(!instance.substs.has_escaping_bound_vars());
22-
assert!(!instance.substs.has_param_types_or_consts());
2322

2423
if let Some(&func) = cx.instances.borrow().get(&instance) {
2524
return func;

src/common.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ use rustc_codegen_ssa::traits::{
1212
};
1313
use rustc_middle::bug;
1414
use rustc_middle::mir::Mutability;
15-
use rustc_middle::ty::{layout::TyAndLayout, ScalarInt};
16-
use rustc_mir::interpret::{Allocation, GlobalAlloc, Scalar};
15+
use rustc_middle::ty::ScalarInt;
16+
use rustc_middle::ty::layout::{TyAndLayout, LayoutOf};
17+
use rustc_middle::mir::interpret::{Allocation, GlobalAlloc, Scalar};
1718
use rustc_span::Symbol;
18-
use rustc_target::abi::{self, HasDataLayout, LayoutOf, Pointer, Size};
19+
use rustc_target::abi::{self, HasDataLayout, Pointer, Size};
1920

2021
use crate::consts::const_alloc_to_gcc;
2122
use crate::context::CodegenCx;
@@ -212,7 +213,7 @@ impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
212213
None
213214
}
214215

215-
fn scalar_to_backend(&self, cv: Scalar, layout: &abi::Scalar, ty: Type<'gcc>) -> RValue<'gcc> {
216+
fn scalar_to_backend(&self, cv: Scalar, layout: abi::Scalar, ty: Type<'gcc>) -> RValue<'gcc> {
216217
let bitsize = if layout.is_bool() { 1 } else { layout.value.size(self).bits() };
217218
match cv {
218219
Scalar::Int(ScalarInt::ZST) => {

src/consts.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ use rustc_middle::{bug, span_bug};
66
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
77
use rustc_middle::mir::mono::MonoItem;
88
use rustc_middle::ty::{self, Instance, Ty};
9-
use rustc_mir::interpret::{self, Allocation, ErrorHandled, Scalar as InterpScalar, read_target_uint};
9+
use rustc_middle::ty::layout::LayoutOf;
10+
use rustc_middle::mir::interpret::{self, Allocation, ErrorHandled, Scalar as InterpScalar, read_target_uint};
1011
use rustc_span::Span;
1112
use rustc_span::def_id::DefId;
12-
use rustc_target::abi::{self, Align, HasDataLayout, LayoutOf, Primitive, Size};
13+
use rustc_target::abi::{self, Align, HasDataLayout, Primitive, Size, WrappingRange};
1314

1415
use crate::base;
1516
use crate::context::CodegenCx;
@@ -182,6 +183,10 @@ impl<'gcc, 'tcx> StaticMethods for CodegenCx<'gcc, 'tcx> {
182183
fn add_used_global(&self, _global: RValue<'gcc>) {
183184
// TODO(antoyo)
184185
}
186+
187+
fn add_compiler_used_global(&self, _global: RValue<'gcc>) {
188+
// TODO(antoyo)
189+
}
185190
}
186191

187192
impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
@@ -350,7 +355,7 @@ pub fn const_alloc_to_gcc<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, alloc: &Alloca
350355
interpret::Pointer::new(alloc_id, Size::from_bytes(ptr_offset)),
351356
&cx.tcx,
352357
),
353-
&abi::Scalar { value: Primitive::Pointer, valid_range: 0..=!0 },
358+
abi::Scalar { value: Primitive::Pointer, valid_range: WrappingRange { start: 0, end: !0 } },
354359
cx.type_i8p(),
355360
));
356361
next_offset = offset + pointer_size;

0 commit comments

Comments
 (0)