summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_codegen_gcc/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--compiler/rustc_codegen_gcc/src/allocator.rs11
-rw-r--r--compiler/rustc_codegen_gcc/src/archive.rs177
-rw-r--r--compiler/rustc_codegen_gcc/src/builder.rs9
-rw-r--r--compiler/rustc_codegen_gcc/src/consts.rs31
-rw-r--r--compiler/rustc_codegen_gcc/src/context.rs9
-rw-r--r--compiler/rustc_codegen_gcc/src/debuginfo.rs57
-rw-r--r--compiler/rustc_codegen_gcc/src/declare.rs4
-rw-r--r--compiler/rustc_codegen_gcc/src/errors.rs21
-rw-r--r--compiler/rustc_codegen_gcc/src/lib.rs12
-rw-r--r--compiler/rustc_codegen_gcc/src/type_.rs44
10 files changed, 105 insertions, 270 deletions
diff --git a/compiler/rustc_codegen_gcc/src/allocator.rs b/compiler/rustc_codegen_gcc/src/allocator.rs
index 58efb81e8..e2c9ffe9c 100644
--- a/compiler/rustc_codegen_gcc/src/allocator.rs
+++ b/compiler/rustc_codegen_gcc/src/allocator.rs
@@ -7,7 +7,7 @@ use rustc_span::symbol::sym;
use crate::GccContext;
-pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut GccContext, _module_name: &str, kind: AllocatorKind, has_alloc_error_handler: bool) {
+pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut GccContext, _module_name: &str, kind: AllocatorKind, alloc_error_handler_kind: AllocatorKind) {
let context = &mods.context;
let usize =
match tcx.sess.target.pointer_width {
@@ -90,14 +90,7 @@ pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut GccContext, _module_nam
.collect();
let func = context.new_function(None, FunctionType::Exported, void, &args, name, false);
- let kind =
- if has_alloc_error_handler {
- AllocatorKind::Global
- }
- else {
- AllocatorKind::Default
- };
- let callee = kind.fn_name(sym::oom);
+ let callee = alloc_error_handler_kind.fn_name(sym::oom);
let args: Vec<_> = types.iter().enumerate()
.map(|(index, typ)| context.new_parameter(None, *typ, &format!("param{}", index)))
.collect();
diff --git a/compiler/rustc_codegen_gcc/src/archive.rs b/compiler/rustc_codegen_gcc/src/archive.rs
index f18ae7ea5..11fa074f5 100644
--- a/compiler/rustc_codegen_gcc/src/archive.rs
+++ b/compiler/rustc_codegen_gcc/src/archive.rs
@@ -1,44 +1,17 @@
-use std::fs::File;
use std::path::{Path, PathBuf};
-use crate::errors::RanlibFailure;
-
-use rustc_codegen_ssa::back::archive::{ArchiveBuilder, ArchiveBuilderBuilder};
+use rustc_codegen_ssa::back::archive::{
+ get_native_object_symbols, ArArchiveBuilder, ArchiveBuilder, ArchiveBuilderBuilder,
+};
use rustc_session::Session;
use rustc_session::cstore::DllImport;
-struct ArchiveConfig<'a> {
- sess: &'a Session,
- use_native_ar: bool,
- use_gnu_style_archive: bool,
-}
-
-#[derive(Debug)]
-enum ArchiveEntry {
- FromArchive {
- archive_index: usize,
- entry_index: usize,
- },
- File(PathBuf),
-}
-
-pub struct ArArchiveBuilderBuilder;
+pub(crate) struct ArArchiveBuilderBuilder;
impl ArchiveBuilderBuilder for ArArchiveBuilderBuilder {
fn new_archive_builder<'a>(&self, sess: &'a Session) -> Box<dyn ArchiveBuilder<'a> + 'a> {
- let config = ArchiveConfig {
- sess,
- use_native_ar: false,
- // FIXME test for linux and System V derivatives instead
- use_gnu_style_archive: sess.target.options.archive_format == "gnu",
- };
-
- Box::new(ArArchiveBuilder {
- config,
- src_archives: vec![],
- entries: vec![],
- })
+ Box::new(ArArchiveBuilder::new(sess, get_native_object_symbols))
}
fn create_dll_import_lib(
@@ -49,144 +22,6 @@ impl ArchiveBuilderBuilder for ArArchiveBuilderBuilder {
_tmpdir: &Path,
_is_direct_dependency: bool,
) -> PathBuf {
- unimplemented!();
- }
-}
-
-pub struct ArArchiveBuilder<'a> {
- config: ArchiveConfig<'a>,
- src_archives: Vec<(PathBuf, ar::Archive<File>)>,
- // Don't use `HashMap` here, as the order is important. `rust.metadata.bin` must always be at
- // the end of an archive for linkers to not get confused.
- entries: Vec<(String, ArchiveEntry)>,
-}
-
-impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
- fn add_file(&mut self, file: &Path) {
- self.entries.push((
- file.file_name().unwrap().to_str().unwrap().to_string(),
- ArchiveEntry::File(file.to_owned()),
- ));
- }
-
- fn add_archive(
- &mut self,
- archive_path: &Path,
- mut skip: Box<dyn FnMut(&str) -> bool + 'static>,
- ) -> std::io::Result<()> {
- 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?;
- 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;
- }
-
- self.src_archives.push((archive_path.to_owned(), archive));
- Ok(())
- }
-
- fn build(mut self: Box<Self>, output: &Path) -> bool {
- use std::process::Command;
-
- fn add_file_using_ar(archive: &Path, file: &Path) {
- Command::new("ar")
- .arg("r") // add or replace file
- .arg("-c") // silence created file message
- .arg(archive)
- .arg(&file)
- .status()
- .unwrap();
- }
-
- enum BuilderKind<'a> {
- Bsd(ar::Builder<File>),
- Gnu(ar::GnuBuilder<File>),
- NativeAr(&'a Path),
- }
-
- let mut builder = if self.config.use_native_ar {
- BuilderKind::NativeAr(output)
- } else if self.config.use_gnu_style_archive {
- BuilderKind::Gnu(ar::GnuBuilder::new(
- File::create(output).unwrap(),
- self.entries
- .iter()
- .map(|(name, _)| name.as_bytes().to_vec())
- .collect(),
- ))
- } else {
- BuilderKind::Bsd(ar::Builder::new(File::create(output).unwrap()))
- };
-
- let any_members = !self.entries.is_empty();
-
- // Add all files
- for (entry_name, entry) in self.entries.into_iter() {
- match entry {
- ArchiveEntry::FromArchive {
- archive_index,
- entry_index,
- } => {
- let (ref src_archive_path, ref mut src_archive) =
- self.src_archives[archive_index];
- let entry = src_archive.jump_to_entry(entry_index).unwrap();
- let header = entry.header().clone();
-
- match builder {
- BuilderKind::Bsd(ref mut builder) => {
- builder.append(&header, entry).unwrap()
- }
- BuilderKind::Gnu(ref mut builder) => {
- builder.append(&header, entry).unwrap()
- }
- BuilderKind::NativeAr(archive_file) => {
- Command::new("ar")
- .arg("x")
- .arg(src_archive_path)
- .arg(&entry_name)
- .status()
- .unwrap();
- add_file_using_ar(archive_file, Path::new(&entry_name));
- std::fs::remove_file(entry_name).unwrap();
- }
- }
- }
- ArchiveEntry::File(file) =>
- match builder {
- BuilderKind::Bsd(ref mut builder) => {
- builder
- .append_file(entry_name.as_bytes(), &mut File::open(file).expect("file for bsd builder"))
- .unwrap()
- },
- BuilderKind::Gnu(ref mut builder) => {
- builder
- .append_file(entry_name.as_bytes(), &mut File::open(&file).expect(&format!("file {:?} for gnu builder", file)))
- .unwrap()
- },
- BuilderKind::NativeAr(archive_file) => add_file_using_ar(archive_file, &file),
- },
- }
- }
-
- // Finalize archive
- std::mem::drop(builder);
-
- // Run ranlib to be able to link the archive
- let status =
- std::process::Command::new("ranlib").arg(output).status().expect("Couldn't run ranlib");
-
- if !status.success() {
- self.config.sess.emit_fatal(RanlibFailure::new(status.code()));
- }
-
- any_members
+ unimplemented!("creating dll imports is not yet supported");
}
}
diff --git a/compiler/rustc_codegen_gcc/src/builder.rs b/compiler/rustc_codegen_gcc/src/builder.rs
index a314b7cc2..782f68566 100644
--- a/compiler/rustc_codegen_gcc/src/builder.rs
+++ b/compiler/rustc_codegen_gcc/src/builder.rs
@@ -755,11 +755,11 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
OperandRef { val, layout: place.layout }
}
- fn write_operand_repeatedly(mut self, cg_elem: OperandRef<'tcx, RValue<'gcc>>, count: u64, dest: PlaceRef<'tcx, RValue<'gcc>>) -> Self {
+ fn write_operand_repeatedly(&mut self, cg_elem: OperandRef<'tcx, RValue<'gcc>>, count: u64, dest: PlaceRef<'tcx, RValue<'gcc>>) {
let zero = self.const_usize(0);
let count = self.const_usize(count);
- let start = dest.project_index(&mut self, zero).llval;
- let end = dest.project_index(&mut self, count).llval;
+ let start = dest.project_index(self, zero).llval;
+ let end = dest.project_index(self, count).llval;
let header_bb = self.append_sibling_block("repeat_loop_header");
let body_bb = self.append_sibling_block("repeat_loop_body");
@@ -778,14 +778,13 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
self.switch_to_block(body_bb);
let align = dest.align.restrict_for_offset(dest.layout.field(self.cx(), 0).size);
- cg_elem.val.store(&mut self, PlaceRef::new_sized_aligned(current_val, cg_elem.layout, align));
+ cg_elem.val.store(self, PlaceRef::new_sized_aligned(current_val, cg_elem.layout, align));
let next = self.inbounds_gep(self.backend_type(cg_elem.layout), current.to_rvalue(), &[self.const_usize(1)]);
self.llbb().add_assignment(None, current, next);
self.br(header_bb);
self.switch_to_block(next_bb);
- self
}
fn range_metadata(&mut self, _load: RValue<'gcc>, _range: WrappingRange) {
diff --git a/compiler/rustc_codegen_gcc/src/consts.rs b/compiler/rustc_codegen_gcc/src/consts.rs
index 81f533288..ea8ab7611 100644
--- a/compiler/rustc_codegen_gcc/src/consts.rs
+++ b/compiler/rustc_codegen_gcc/src/consts.rs
@@ -8,13 +8,11 @@ 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, 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};
use crate::base;
use crate::context::CodegenCx;
-use crate::errors::LinkageConstOrMutType;
use crate::type_of::LayoutGccExt;
impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
@@ -239,12 +237,12 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
}
Node::ForeignItem(&hir::ForeignItem {
- span,
+ span: _,
kind: hir::ForeignItemKind::Static(..),
..
}) => {
let fn_attrs = self.tcx.codegen_fn_attrs(def_id);
- check_and_apply_linkage(&self, &fn_attrs, ty, sym, span)
+ check_and_apply_linkage(&self, &fn_attrs, ty, sym)
}
item => bug!("get_static: expected static, found {:?}", item),
@@ -257,8 +255,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
//debug!("get_static: sym={} item_attr={:?}", sym, self.tcx.item_attrs(def_id));
let attrs = self.tcx.codegen_fn_attrs(def_id);
- let span = self.tcx.def_span(def_id);
- let global = check_and_apply_linkage(&self, &attrs, ty, sym, span);
+ let global = check_and_apply_linkage(&self, &attrs, ty, sym);
let needs_dll_storage_attr = false; // TODO(antoyo)
@@ -297,12 +294,12 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
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.provenance().len() + 1);
+ let mut llvals = Vec::with_capacity(alloc.provenance().ptrs().len() + 1);
let dl = cx.data_layout();
let pointer_size = dl.pointer_size.bytes() as usize;
let mut next_offset = 0;
- for &(offset, alloc_id) in alloc.provenance().iter() {
+ for &(offset, alloc_id) in alloc.provenance().ptrs().iter() {
let offset = offset.bytes();
assert_eq!(offset as usize as u64, offset);
let offset = offset as usize;
@@ -355,24 +352,12 @@ pub fn codegen_static_initializer<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, def_id
Ok((const_alloc_to_gcc(cx, alloc), alloc))
}
-fn check_and_apply_linkage<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, attrs: &CodegenFnAttrs, ty: Ty<'tcx>, sym: &str, span: Span) -> LValue<'gcc> {
+fn check_and_apply_linkage<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, attrs: &CodegenFnAttrs, ty: Ty<'tcx>, sym: &str) -> LValue<'gcc> {
let is_tls = attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL);
let llty = cx.layout_of(ty).gcc_type(cx, true);
- if let Some(linkage) = attrs.linkage {
- // If this is a static with a linkage specified, then we need to handle
- // it a little specially. The typesystem prevents things like &T and
- // extern "C" fn() from being non-null, so we can't just declare a
- // static and call it a day. Some linkages (like weak) will make it such
- // that the static actually has a null value.
- let llty2 =
- if let ty::RawPtr(ref mt) = ty.kind() {
- cx.layout_of(mt.ty).gcc_type(cx, true)
- }
- else {
- cx.sess().emit_fatal(LinkageConstOrMutType { span: span })
- };
+ if let Some(linkage) = attrs.import_linkage {
// Declare a symbol `foo` with the desired linkage.
- let global1 = cx.declare_global_with_linkage(&sym, llty2, base::global_linkage_to_gcc(linkage));
+ let global1 = cx.declare_global_with_linkage(&sym, cx.type_i8(), base::global_linkage_to_gcc(linkage));
// Declare an internal global `extern_with_linkage_foo` which
// is initialized with the address of `foo`. If `foo` is
diff --git a/compiler/rustc_codegen_gcc/src/context.rs b/compiler/rustc_codegen_gcc/src/context.rs
index 62a61eb85..837708aeb 100644
--- a/compiler/rustc_codegen_gcc/src/context.rs
+++ b/compiler/rustc_codegen_gcc/src/context.rs
@@ -88,9 +88,9 @@ pub struct CodegenCx<'gcc, 'tcx> {
pub vtables: RefCell<FxHashMap<(Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>), RValue<'gcc>>>,
// TODO(antoyo): improve the SSA API to not require those.
- // Mapping from function pointer type to indexes of on stack parameters.
+ /// Mapping from function pointer type to indexes of on stack parameters.
pub on_stack_params: RefCell<FxHashMap<FunctionPtrType<'gcc>, FxHashSet<usize>>>,
- // Mapping from function to indexes of on stack parameters.
+ /// Mapping from function to indexes of on stack parameters.
pub on_stack_function_params: RefCell<FxHashMap<Function<'gcc>, FxHashSet<usize>>>,
/// Cache of emitted const globals (value -> global)
@@ -425,8 +425,9 @@ impl<'gcc, 'tcx> MiscMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
}
fn declare_c_main(&self, fn_type: Self::Type) -> Option<Self::Function> {
- if self.get_declared_value("main").is_none() {
- Some(self.declare_cfn("main", fn_type))
+ let entry_name = self.sess().target.entry_name.as_ref();
+ if self.get_declared_value(entry_name).is_none() {
+ Some(self.declare_entry_fn(entry_name, fn_type, ()))
}
else {
// If the symbol already exists, it is an error: for example, the user wrote
diff --git a/compiler/rustc_codegen_gcc/src/debuginfo.rs b/compiler/rustc_codegen_gcc/src/debuginfo.rs
index 266759ed6..a81585d41 100644
--- a/compiler/rustc_codegen_gcc/src/debuginfo.rs
+++ b/compiler/rustc_codegen_gcc/src/debuginfo.rs
@@ -4,8 +4,9 @@ use rustc_codegen_ssa::traits::{DebugInfoBuilderMethods, DebugInfoMethods};
use rustc_middle::mir;
use rustc_middle::ty::{Instance, PolyExistentialTraitRef, Ty};
use rustc_span::{SourceFile, Span, Symbol};
-use rustc_target::abi::Size;
use rustc_target::abi::call::FnAbi;
+use rustc_target::abi::Size;
+use std::ops::Range;
use crate::builder::Builder;
use crate::context::CodegenCx;
@@ -13,7 +14,15 @@ use crate::context::CodegenCx;
impl<'a, 'gcc, 'tcx> DebugInfoBuilderMethods for Builder<'a, 'gcc, 'tcx> {
// FIXME(eddyb) find a common convention for all of the debuginfo-related
// names (choose between `dbg`, `debug`, `debuginfo`, `debug_info` etc.).
- fn dbg_var_addr(&mut self, _dbg_var: Self::DIVariable, _scope_metadata: Self::DIScope, _variable_alloca: Self::Value, _direct_offset: Size, _indirect_offsets: &[Size]) {
+ fn dbg_var_addr(
+ &mut self,
+ _dbg_var: Self::DIVariable,
+ _scope_metadata: Self::DIScope,
+ _variable_alloca: Self::Value,
+ _direct_offset: Size,
+ _indirect_offsets: &[Size],
+ _fragment: Option<Range<Size>>,
+ ) {
unimplemented!();
}
@@ -31,16 +40,31 @@ impl<'a, 'gcc, 'tcx> DebugInfoBuilderMethods for Builder<'a, 'gcc, 'tcx> {
}
impl<'gcc, 'tcx> DebugInfoMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
- fn create_vtable_debuginfo(&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)
}
- fn create_function_debug_context(&self, _instance: Instance<'tcx>, _fn_abi: &FnAbi<'tcx, Ty<'tcx>>, _llfn: RValue<'gcc>, _mir: &mir::Body<'tcx>) -> Option<FunctionDebugContext<Self::DIScope, Self::DILocation>> {
+ fn create_function_debug_context(
+ &self,
+ _instance: Instance<'tcx>,
+ _fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
+ _llfn: RValue<'gcc>,
+ _mir: &mir::Body<'tcx>,
+ ) -> Option<FunctionDebugContext<Self::DIScope, Self::DILocation>> {
// TODO(antoyo)
None
}
- fn extend_scope_to_file(&self, _scope_metadata: Self::DIScope, _file: &SourceFile) -> Self::DIScope {
+ fn extend_scope_to_file(
+ &self,
+ _scope_metadata: Self::DIScope,
+ _file: &SourceFile,
+ ) -> Self::DIScope {
unimplemented!();
}
@@ -48,15 +72,32 @@ impl<'gcc, 'tcx> DebugInfoMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
// TODO(antoyo)
}
- fn create_dbg_var(&self, _variable_name: Symbol, _variable_type: Ty<'tcx>, _scope_metadata: Self::DIScope, _variable_kind: VariableKind, _span: Span) -> Self::DIVariable {
+ fn create_dbg_var(
+ &self,
+ _variable_name: Symbol,
+ _variable_type: Ty<'tcx>,
+ _scope_metadata: Self::DIScope,
+ _variable_kind: VariableKind,
+ _span: Span,
+ ) -> Self::DIVariable {
unimplemented!();
}
- fn dbg_scope_fn(&self, _instance: Instance<'tcx>, _fn_abi: &FnAbi<'tcx, Ty<'tcx>>, _maybe_definition_llfn: Option<RValue<'gcc>>) -> Self::DIScope {
+ fn dbg_scope_fn(
+ &self,
+ _instance: Instance<'tcx>,
+ _fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
+ _maybe_definition_llfn: Option<RValue<'gcc>>,
+ ) -> Self::DIScope {
unimplemented!();
}
- fn dbg_loc(&self, _scope: Self::DIScope, _inlined_at: Option<Self::DILocation>, _span: Span) -> Self::DILocation {
+ fn dbg_loc(
+ &self,
+ _scope: Self::DIScope,
+ _inlined_at: Option<Self::DILocation>,
+ _span: Span,
+ ) -> Self::DILocation {
unimplemented!();
}
}
diff --git a/compiler/rustc_codegen_gcc/src/declare.rs b/compiler/rustc_codegen_gcc/src/declare.rs
index a619e2f77..eae77508c 100644
--- a/compiler/rustc_codegen_gcc/src/declare.rs
+++ b/compiler/rustc_codegen_gcc/src/declare.rs
@@ -65,13 +65,13 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
global
}
- pub fn declare_cfn(&self, name: &str, _fn_type: Type<'gcc>) -> RValue<'gcc> {
+ pub fn declare_entry_fn(&self, name: &str, _fn_type: Type<'gcc>, callconv: () /*llvm::CCallConv*/) -> RValue<'gcc> {
// TODO(antoyo): use the fn_type parameter.
let const_string = self.context.new_type::<u8>().make_pointer().make_pointer();
let return_type = self.type_i32();
let variadic = false;
self.linkage.set(FunctionType::Exported);
- let func = declare_raw_fn(self, name, () /*llvm::CCallConv*/, return_type, &[self.type_i32(), const_string], variadic);
+ let func = declare_raw_fn(self, name, callconv, return_type, &[self.type_i32(), const_string], variadic);
// NOTE: it is needed to set the current_func here as well, because get_fn() is not called
// for the main function.
*self.current_func.borrow_mut() = Some(func);
diff --git a/compiler/rustc_codegen_gcc/src/errors.rs b/compiler/rustc_codegen_gcc/src/errors.rs
index 15ad90f90..d0ba7e247 100644
--- a/compiler/rustc_codegen_gcc/src/errors.rs
+++ b/compiler/rustc_codegen_gcc/src/errors.rs
@@ -17,18 +17,6 @@ impl IntoDiagnosticArg for ExitCode {
}
#[derive(Diagnostic)]
-#[diag(codegen_gcc_ranlib_failure)]
-pub(crate) struct RanlibFailure {
- exit_code: ExitCode,
-}
-
-impl RanlibFailure {
- pub fn new(exit_code: Option<i32>) -> Self {
- RanlibFailure { exit_code: ExitCode(exit_code) }
- }
-}
-
-#[derive(Diagnostic)]
#[diag(codegen_gcc_invalid_monomorphization_basic_integer, code = "E0511")]
pub(crate) struct InvalidMonomorphizationBasicInteger<'a> {
#[primary_span]
@@ -224,13 +212,6 @@ pub(crate) struct InvalidMonomorphizationUnsupportedOperation<'a> {
}
#[derive(Diagnostic)]
-#[diag(codegen_gcc_linkage_const_or_mut_type)]
-pub(crate) struct LinkageConstOrMutType {
- #[primary_span]
- pub span: Span
-}
-
-#[derive(Diagnostic)]
#[diag(codegen_gcc_lto_not_supported)]
pub(crate) struct LTONotSupported;
@@ -238,5 +219,5 @@ pub(crate) struct LTONotSupported;
#[diag(codegen_gcc_unwinding_inline_asm)]
pub(crate) struct UnwindingInlineAsm {
#[primary_span]
- pub span: Span
+ pub span: Span,
}
diff --git a/compiler/rustc_codegen_gcc/src/lib.rs b/compiler/rustc_codegen_gcc/src/lib.rs
index accd02ab0..b9600da5c 100644
--- a/compiler/rustc_codegen_gcc/src/lib.rs
+++ b/compiler/rustc_codegen_gcc/src/lib.rs
@@ -153,11 +153,11 @@ impl CodegenBackend for GccCodegenBackend {
}
impl ExtraBackendMethods for GccCodegenBackend {
- fn codegen_allocator<'tcx>(&self, tcx: TyCtxt<'tcx>, module_name: &str, kind: AllocatorKind, has_alloc_error_handler: bool) -> Self::Module {
+ fn codegen_allocator<'tcx>(&self, tcx: TyCtxt<'tcx>, module_name: &str, kind: AllocatorKind, alloc_error_handler_kind: AllocatorKind) -> Self::Module {
let mut mods = GccContext {
context: Context::default(),
};
- unsafe { allocator::codegen(tcx, &mut mods, module_name, kind, has_alloc_error_handler); }
+ unsafe { allocator::codegen(tcx, &mut mods, module_name, kind, alloc_error_handler_kind); }
mods
}
@@ -315,10 +315,10 @@ pub fn target_features(sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
false
}
/*
- adx, aes, avx, avx2, avx512bf16, avx512bitalg, avx512bw, avx512cd, avx512dq, avx512er, avx512f, avx512gfni,
- avx512ifma, avx512pf, avx512vaes, avx512vbmi, avx512vbmi2, avx512vl, avx512vnni, avx512vp2intersect, avx512vpclmulqdq,
- avx512vpopcntdq, bmi1, bmi2, cmpxchg16b, ermsb, f16c, fma, fxsr, lzcnt, movbe, pclmulqdq, popcnt, rdrand, rdseed, rtm,
- sha, sse, sse2, sse3, sse4.1, sse4.2, sse4a, ssse3, tbm, xsave, xsavec, xsaveopt, xsaves
+ adx, aes, avx, avx2, avx512bf16, avx512bitalg, avx512bw, avx512cd, avx512dq, avx512er, avx512f, avx512ifma,
+ avx512pf, avx512vbmi, avx512vbmi2, avx512vl, avx512vnni, avx512vp2intersect, avx512vpopcntdq,
+ bmi1, bmi2, cmpxchg16b, ermsb, f16c, fma, fxsr, gfni, lzcnt, movbe, pclmulqdq, popcnt, rdrand, rdseed, rtm,
+ sha, sse, sse2, sse3, sse4.1, sse4.2, sse4a, ssse3, tbm, vaes, vpclmulqdq, xsave, xsavec, xsaveopt, xsaves
*/
//false
})
diff --git a/compiler/rustc_codegen_gcc/src/type_.rs b/compiler/rustc_codegen_gcc/src/type_.rs
index 68bdb8d4e..bdf7318ce 100644
--- a/compiler/rustc_codegen_gcc/src/type_.rs
+++ b/compiler/rustc_codegen_gcc/src/type_.rs
@@ -201,6 +201,27 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
fn val_ty(&self, value: RValue<'gcc>) -> Type<'gcc> {
value.get_type()
}
+
+ fn type_array(&self, ty: Type<'gcc>, mut len: u64) -> Type<'gcc> {
+ if let Some(struct_type) = ty.is_struct() {
+ if struct_type.get_field_count() == 0 {
+ // NOTE: since gccjit only supports i32 for the array size and libcore's tests uses a
+ // size of usize::MAX in test_binary_search, we workaround this by setting the size to
+ // zero for ZSTs.
+ // FIXME(antoyo): fix gccjit API.
+ len = 0;
+ }
+ }
+
+ // NOTE: see note above. Some other test uses usize::MAX.
+ if len == u64::MAX {
+ len = 0;
+ }
+
+ let len: i32 = len.try_into().expect("array len");
+
+ self.context.new_array_type(None, ty, len)
+ }
}
impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
@@ -227,27 +248,6 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
self.context.new_opaque_struct_type(None, name)
}
- pub fn type_array(&self, ty: Type<'gcc>, mut len: u64) -> Type<'gcc> {
- if let Some(struct_type) = ty.is_struct() {
- if struct_type.get_field_count() == 0 {
- // NOTE: since gccjit only supports i32 for the array size and libcore's tests uses a
- // size of usize::MAX in test_binary_search, we workaround this by setting the size to
- // zero for ZSTs.
- // FIXME(antoyo): fix gccjit API.
- len = 0;
- }
- }
-
- // NOTE: see note above. Some other test uses usize::MAX.
- if len == u64::MAX {
- len = 0;
- }
-
- let len: i32 = len.try_into().expect("array len");
-
- self.context.new_array_type(None, ty, len)
- }
-
pub fn type_bool(&self) -> Type<'gcc> {
self.context.new_type::<bool>()
}
@@ -277,7 +277,7 @@ pub fn struct_fields<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, layout: TyAndLayout
offset = target_offset + field.size;
prev_effective_align = effective_field_align;
}
- if !layout.is_unsized() && field_count > 0 {
+ if layout.is_sized() && field_count > 0 {
if offset > layout.size {
bug!("layout: {:#?} stride: {:?} offset: {:?}", layout, layout.size, offset);
}