Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion compiler/rustc_codegen_gcc/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use rustc_middle::ty::{self, ExistentialTraitRef, Instance, Ty, TyCtxt};
use rustc_session::Session;
#[cfg(feature = "master")]
use rustc_session::config::DebugInfo;
use rustc_span::{DUMMY_SP, Span, respan};
use rustc_span::{DUMMY_SP, Span, Symbol, respan};
use rustc_target::spec::{HasTargetSpec, HasX86AbiOpt, Target, TlsModel, X86Abi};

#[cfg(feature = "master")]
Expand Down Expand Up @@ -497,6 +497,10 @@ impl<'gcc, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
None
}
}

fn intrinsic_call_expects_place_always(&self, _name: Symbol) -> bool {
true
}
}

impl<'gcc, 'tcx> HasTyCtxt<'tcx> for CodegenCx<'gcc, 'tcx> {
Expand Down
34 changes: 20 additions & 14 deletions compiler/rustc_codegen_gcc/src/intrinsic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use rustc_codegen_ssa::MemFlags;
use rustc_codegen_ssa::base::wants_msvc_seh;
use rustc_codegen_ssa::common::IntPredicate;
use rustc_codegen_ssa::errors::InvalidMonomorphization;
use rustc_codegen_ssa::mir::IntrinsicResult;
use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue};
use rustc_codegen_ssa::mir::place::{PlaceRef, PlaceValue};
#[cfg(feature = "master")]
Expand Down Expand Up @@ -194,11 +195,14 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
&mut self,
instance: Instance<'tcx>,
args: &[OperandRef<'tcx, RValue<'gcc>>],
result: PlaceRef<'tcx, RValue<'gcc>>,
result_layout: ty::layout::TyAndLayout<'tcx>,
result_place: Option<PlaceValue<RValue<'gcc>>>,
span: Span,
) -> Result<(), Instance<'tcx>> {
) -> IntrinsicResult<'tcx, RValue<'gcc>> {
let tcx = self.tcx;

let result = PlaceRef { val: result_place.unwrap(), layout: result_layout };

let name = tcx.item_name(instance.def_id());
let name_str = name.as_str();
let fn_args = instance.args;
Expand Down Expand Up @@ -353,7 +357,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
args[2].immediate(),
result,
);
return Ok(());
return IntrinsicResult::WroteIntoPlace;
}
sym::breakpoint => {
unimplemented!();
Expand All @@ -375,12 +379,12 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
sym::volatile_store => {
let dst = args[0].deref(self.cx());
args[1].val.volatile_store(self, dst);
return Ok(());
return IntrinsicResult::WroteIntoPlace;
}
sym::unaligned_volatile_store => {
let dst = args[0].deref(self.cx());
args[1].val.unaligned_volatile_store(self, dst);
return Ok(());
return IntrinsicResult::WroteIntoPlace;
}
sym::prefetch_read_data
| sym::prefetch_write_data
Expand Down Expand Up @@ -448,12 +452,12 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
_ => bug!(),
},
None => {
tcx.dcx().emit_err(InvalidMonomorphization::BasicIntegerType {
let err = tcx.dcx().emit_err(InvalidMonomorphization::BasicIntegerType {
span,
name,
ty: args[0].layout.ty,
});
return Ok(());
return IntrinsicResult::Err(err);
}
}
}
Expand Down Expand Up @@ -544,7 +548,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
extended_asm.set_volatile_flag(true);

// We have copied the value to `result` already.
return Ok(());
return IntrinsicResult::WroteIntoPlace;
}

sym::ptr_mask => {
Expand All @@ -569,12 +573,15 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
span,
) {
Ok(value) => value,
Err(()) => return Ok(()),
Err(err) => return IntrinsicResult::Err(err),
}
}

// Fall back to default body
_ => return Err(Instance::new_raw(instance.def_id(), instance.args)),
_ => {
let fallback = Instance::new_raw(instance.def_id(), instance.args);
return IntrinsicResult::Fallback(fallback);
}
};

if result.layout.ty.is_bool() {
Expand All @@ -583,7 +590,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
} else if !result.layout.ty.is_unit() {
self.store_to_place(value, result.val);
}
Ok(())
IntrinsicResult::WroteIntoPlace
}

fn codegen_llvm_intrinsic_call(
Expand Down Expand Up @@ -694,13 +701,12 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
self.context.new_rvalue_from_int(self.int_type, 0)
}

fn va_start(&mut self, _va_list: RValue<'gcc>) -> RValue<'gcc> {
fn va_start(&mut self, _va_list: RValue<'gcc>) {
unimplemented!();
}

fn va_end(&mut self, _va_list: RValue<'gcc>) -> RValue<'gcc> {
fn va_end(&mut self, _va_list: RValue<'gcc>) {
// FIXME(antoyo): implement.
self.context.new_rvalue_from_int(self.int_type, 0)
}
}

Expand Down
14 changes: 7 additions & 7 deletions compiler/rustc_codegen_gcc/src/intrinsic/simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use rustc_hir as hir;
use rustc_middle::mir::BinOp;
use rustc_middle::ty::layout::HasTyCtxt;
use rustc_middle::ty::{self, Ty, Unnormalized};
use rustc_span::{Span, Symbol, sym};
use rustc_span::{ErrorGuaranteed, Span, Symbol, sym};

use crate::builder::Builder;
#[cfg(not(feature = "master"))]
Expand All @@ -32,12 +32,12 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
ret_ty: Ty<'tcx>,
llret_ty: Type<'gcc>,
span: Span,
) -> Result<RValue<'gcc>, ()> {
) -> Result<RValue<'gcc>, ErrorGuaranteed> {
// macros for error handling:
macro_rules! return_error {
($err:expr) => {{
bx.tcx.dcx().emit_err($err);
return Err(());
let err = bx.tcx.dcx().emit_err($err);
return Err(err);
}};
}
macro_rules! require {
Expand Down Expand Up @@ -809,11 +809,11 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
bx: &mut Builder<'_, 'gcc, 'tcx>,
span: Span,
args: &[OperandRef<'tcx, RValue<'gcc>>],
) -> Result<RValue<'gcc>, ()> {
) -> Result<RValue<'gcc>, ErrorGuaranteed> {
macro_rules! return_error {
($err:expr) => {{
bx.tcx.dcx().emit_err($err);
return Err(());
let err = bx.tcx.dcx().emit_err($err);
return Err(err);
}};
}
let ty::Float(ref f) = *in_elem.kind() else {
Expand Down
13 changes: 12 additions & 1 deletion compiler/rustc_codegen_llvm/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use rustc_session::Session;
use rustc_session::config::{
BranchProtection, CFGuard, CFProtection, CrateType, DebugInfo, FunctionReturn, PAuthKey, PacRet,
};
use rustc_span::{DUMMY_SP, Span, Spanned, Symbol};
use rustc_span::{DUMMY_SP, Span, Spanned, Symbol, sym};
use rustc_symbol_mangling::mangle_internal_symbol;
use rustc_target::spec::{
Arch, CfgAbi, Env, HasTargetSpec, Os, RelocModel, SmallDataThresholdSupport, Target, TlsModel,
Expand Down Expand Up @@ -937,6 +937,17 @@ impl<'ll, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
None
}
}

fn intrinsic_call_expects_place_always(&self, name: Symbol) -> bool {
matches!(
name,
sym::autodiff
| sym::catch_unwind
| sym::volatile_load
| sym::unaligned_volatile_load
| sym::black_box
)
}
}

impl<'ll> CodegenCx<'ll, '_> {
Expand Down
Loading
Loading