From 6ff147b2050bc99f2bca7707e29052e7e4737912 Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Tue, 6 Feb 2024 14:32:00 -0500 Subject: [PATCH 01/17] Add "algebraic" versions of the fast-math intrinsics --- src/builder.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/builder.rs b/src/builder.rs index 42e61b3ccb5..5f1e4538376 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -705,6 +705,31 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> { self.frem(lhs, rhs) } + fn fadd_algebraic(&mut self, lhs: RValue<'gcc>, rhs: RValue<'gcc>) -> RValue<'gcc> { + // NOTE: it seems like we cannot enable fast-mode for a single operation in GCC. + lhs + rhs + } + + fn fsub_algebraic(&mut self, lhs: RValue<'gcc>, rhs: RValue<'gcc>) -> RValue<'gcc> { + // NOTE: it seems like we cannot enable fast-mode for a single operation in GCC. + lhs - rhs + } + + fn fmul_algebraic(&mut self, lhs: RValue<'gcc>, rhs: RValue<'gcc>) -> RValue<'gcc> { + // NOTE: it seems like we cannot enable fast-mode for a single operation in GCC. + lhs * rhs + } + + fn fdiv_algebraic(&mut self, lhs: RValue<'gcc>, rhs: RValue<'gcc>) -> RValue<'gcc> { + // NOTE: it seems like we cannot enable fast-mode for a single operation in GCC. + lhs / rhs + } + + fn frem_algebraic(&mut self, lhs: RValue<'gcc>, rhs: RValue<'gcc>) -> RValue<'gcc> { + // NOTE: it seems like we cannot enable fast-mode for a single operation in GCC. + self.frem(lhs, rhs) + } + fn checked_binop(&mut self, oop: OverflowOp, typ: Ty<'_>, lhs: Self::Value, rhs: Self::Value) -> (Self::Value, Self::Value) { self.gcc_checked_binop(oop, typ, lhs, rhs) } From a9b5c0832fc3e7e12916ef827f9de27d968a491a Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 18 Feb 2024 23:10:34 +0100 Subject: [PATCH 02/17] make simd_reduce_{mul,add}_unordered use only the 'reassoc' flag, not all fast-math flags --- src/builder.rs | 4 ++-- src/intrinsic/simd.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/builder.rs b/src/builder.rs index 5f1e4538376..7e2139866f4 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -1752,7 +1752,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> { self.vector_reduce(src, |a, b, context| context.new_binary_op(None, op, a.get_type(), a, b)) } - pub fn vector_reduce_fadd_fast(&mut self, _acc: RValue<'gcc>, _src: RValue<'gcc>) -> RValue<'gcc> { + pub fn vector_reduce_fadd_reassoc(&mut self, _acc: RValue<'gcc>, _src: RValue<'gcc>) -> RValue<'gcc> { unimplemented!(); } @@ -1772,7 +1772,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> { unimplemented!(); } - pub fn vector_reduce_fmul_fast(&mut self, _acc: RValue<'gcc>, _src: RValue<'gcc>) -> RValue<'gcc> { + pub fn vector_reduce_fmul_reassoc(&mut self, _acc: RValue<'gcc>, _src: RValue<'gcc>) -> RValue<'gcc> { unimplemented!(); } diff --git a/src/intrinsic/simd.rs b/src/intrinsic/simd.rs index 9fa978cd2ef..dedd4653858 100644 --- a/src/intrinsic/simd.rs +++ b/src/intrinsic/simd.rs @@ -989,14 +989,14 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>( arith_red!( simd_reduce_add_unordered: BinaryOp::Plus, - vector_reduce_fadd_fast, + vector_reduce_fadd_reassoc, false, add, 0.0 // TODO: Use this argument. ); arith_red!( simd_reduce_mul_unordered: BinaryOp::Mult, - vector_reduce_fmul_fast, + vector_reduce_fmul_reassoc, false, mul, 1.0 From 0abd3b76b7b20076981fcc002ca43de63f836ee8 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 18 Feb 2024 09:36:36 +0100 Subject: [PATCH 03/17] remove simd_reduce_{min,max}_nanless --- src/intrinsic/simd.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/intrinsic/simd.rs b/src/intrinsic/simd.rs index dedd4653858..d8091724d86 100644 --- a/src/intrinsic/simd.rs +++ b/src/intrinsic/simd.rs @@ -1041,9 +1041,6 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>( minmax_red!(simd_reduce_min: vector_reduce_min, vector_reduce_fmin); minmax_red!(simd_reduce_max: vector_reduce_max, vector_reduce_fmax); - // TODO(sadlerap): revisit these intrinsics to generate more optimal reductions - minmax_red!(simd_reduce_min_nanless: vector_reduce_min, vector_reduce_fmin); - minmax_red!(simd_reduce_max_nanless: vector_reduce_max, vector_reduce_fmax); macro_rules! bitwise_red { ($name:ident : $op:expr, $boolean:expr) => { From a06a87b37dfc4aa9e0043d72b16df8051f92e98c Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 25 Feb 2024 18:51:22 +0100 Subject: [PATCH 04/17] rename 'try' intrinsic to 'catch_unwind' --- src/intrinsic/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/intrinsic/mod.rs b/src/intrinsic/mod.rs index f162ef831b7..d43f5d74757 100644 --- a/src/intrinsic/mod.rs +++ b/src/intrinsic/mod.rs @@ -21,7 +21,7 @@ use rustc_middle::ty::{self, Instance, Ty}; use rustc_middle::ty::layout::LayoutOf; #[cfg(feature="master")] use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt}; -use rustc_span::{Span, Symbol, symbol::kw, sym}; +use rustc_span::{Span, Symbol, sym}; use rustc_target::abi::HasDataLayout; use rustc_target::abi::call::{ArgAbi, FnAbi, PassMode}; use rustc_target::spec::PanicStrategy; @@ -129,7 +129,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> { let res = self.context.new_call(None, builtin, &[a]); self.icmp(IntPredicate::IntEQ, res, self.const_i32(0)) } - kw::Try => { + sym::catch_unwind => { try_intrinsic( self, args[0].immediate(), From 7f34119c1a6ec425f549e12f1490555acda74c65 Mon Sep 17 00:00:00 2001 From: 823984418 <823984418@qq.com> Date: Mon, 26 Feb 2024 22:37:04 +0800 Subject: [PATCH 05/17] remove useless lifetime of ArchiveBuilder --- src/archive.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/archive.rs b/src/archive.rs index 11fa074f5ac..73ff0c37b66 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -10,7 +10,7 @@ use rustc_session::cstore::DllImport; pub(crate) struct ArArchiveBuilderBuilder; impl ArchiveBuilderBuilder for ArArchiveBuilderBuilder { - fn new_archive_builder<'a>(&self, sess: &'a Session) -> Box + 'a> { + fn new_archive_builder<'a>(&self, sess: &'a Session) -> Box { Box::new(ArArchiveBuilder::new(sess, get_native_object_symbols)) } From 7d086c72f72ca64e57c52110eef6ae50eab484fd Mon Sep 17 00:00:00 2001 From: Erik Desjardins Date: Fri, 23 Feb 2024 23:23:35 -0500 Subject: [PATCH 06/17] always use gep inbounds i8 (ptradd) for field offsets --- src/type_of.rs | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/src/type_of.rs b/src/type_of.rs index 25149b80201..e327051ca1d 100644 --- a/src/type_of.rs +++ b/src/type_of.rs @@ -151,7 +151,6 @@ pub trait LayoutGccExt<'tcx> { fn immediate_gcc_type<'gcc>(&self, cx: &CodegenCx<'gcc, 'tcx>) -> Type<'gcc>; fn scalar_gcc_type_at<'gcc>(&self, cx: &CodegenCx<'gcc, 'tcx>, scalar: &abi::Scalar, offset: Size) -> Type<'gcc>; fn scalar_pair_element_gcc_type<'gcc>(&self, cx: &CodegenCx<'gcc, 'tcx>, index: usize) -> Type<'gcc>; - fn gcc_field_index(&self, index: usize) -> u64; fn pointee_info_at<'gcc>(&self, cx: &CodegenCx<'gcc, 'tcx>, offset: Size) -> Option; } @@ -304,24 +303,6 @@ impl<'tcx> LayoutGccExt<'tcx> for TyAndLayout<'tcx> { self.scalar_gcc_type_at(cx, scalar, offset) } - fn gcc_field_index(&self, index: usize) -> u64 { - match self.abi { - Abi::Scalar(_) | Abi::ScalarPair(..) => { - bug!("TyAndLayout::gcc_field_index({:?}): not applicable", self) - } - _ => {} - } - match self.fields { - FieldsShape::Primitive | FieldsShape::Union(_) => { - bug!("TyAndLayout::gcc_field_index({:?}): not applicable", self) - } - - FieldsShape::Array { .. } => index as u64, - - FieldsShape::Arbitrary { .. } => 1 + (self.fields.memory_index(index) as u64) * 2, - } - } - fn pointee_info_at<'a>(&self, cx: &CodegenCx<'a, 'tcx>, offset: Size) -> Option { if let Some(&pointee) = cx.pointee_infos.borrow().get(&(self.ty, offset)) { return pointee; @@ -351,10 +332,6 @@ impl<'gcc, 'tcx> LayoutTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> { layout.is_gcc_scalar_pair() } - fn backend_field_index(&self, layout: TyAndLayout<'tcx>, index: usize) -> u64 { - layout.gcc_field_index(index) - } - fn scalar_pair_element_backend_type(&self, layout: TyAndLayout<'tcx>, index: usize, _immediate: bool) -> Type<'gcc> { layout.scalar_pair_element_gcc_type(self, index) } From 19a648218feee406b7ed50c8ef722adba71f4029 Mon Sep 17 00:00:00 2001 From: Erik Desjardins Date: Sat, 24 Feb 2024 01:46:30 -0500 Subject: [PATCH 07/17] remove struct_gep, use manual layout calculations for va_arg --- src/builder.rs | 38 +++++++++----------------------------- 1 file changed, 9 insertions(+), 29 deletions(-) diff --git a/src/builder.rs b/src/builder.rs index 7e2139866f4..bae0cc3655d 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -834,10 +834,17 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> { } else if let abi::Abi::ScalarPair(ref a, ref b) = place.layout.abi { let b_offset = a.size(self).align_to(b.align(self).abi); - let pair_type = place.layout.gcc_type(self); let mut load = |i, scalar: &abi::Scalar, align| { - let llptr = self.struct_gep(pair_type, place.llval, i as u64); + let llptr = if i == 0 { + place.llval + } else { + self.inbounds_gep( + self.type_i8(), + place.llval, + &[self.const_usize(b_offset.bytes())], + ) + }; let llty = place.layout.scalar_pair_element_gcc_type(self, i); let load = self.load(llty, llptr, align); scalar_load_metadata(self, load, scalar); @@ -971,33 +978,6 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> { result.get_address(None) } - fn struct_gep(&mut self, value_type: Type<'gcc>, ptr: RValue<'gcc>, idx: u64) -> RValue<'gcc> { - // FIXME(antoyo): it would be better if the API only called this on struct, not on arrays. - assert_eq!(idx as usize as u64, idx); - let value = ptr.dereference(None).to_rvalue(); - - if value_type.dyncast_array().is_some() { - let index = self.context.new_rvalue_from_long(self.u64_type, i64::try_from(idx).expect("i64::try_from")); - let element = self.context.new_array_access(None, value, index); - element.get_address(None) - } - else if let Some(vector_type) = value_type.dyncast_vector() { - let array_type = vector_type.get_element_type().make_pointer(); - let array = self.bitcast(ptr, array_type); - let index = self.context.new_rvalue_from_long(self.u64_type, i64::try_from(idx).expect("i64::try_from")); - let element = self.context.new_array_access(None, array, index); - element.get_address(None) - } - else if let Some(struct_type) = value_type.is_struct() { - // NOTE: due to opaque pointers now being used, we need to bitcast here. - let ptr = self.bitcast_if_needed(ptr, value_type.make_pointer()); - ptr.dereference_field(None, struct_type.get_field(idx as i32)).get_address(None) - } - else { - panic!("Unexpected type {:?}", value_type); - } - } - /* Casts */ fn trunc(&mut self, value: RValue<'gcc>, dest_ty: Type<'gcc>) -> RValue<'gcc> { // TODO(antoyo): check that it indeed truncate the value. From 70346fe2a455c754d93994922cbfaa9393c0002b Mon Sep 17 00:00:00 2001 From: Erik Desjardins Date: Sat, 24 Feb 2024 02:01:41 -0500 Subject: [PATCH 08/17] introduce and use ptradd/inbounds_ptradd instead of gep --- src/builder.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/builder.rs b/src/builder.rs index bae0cc3655d..71a0a4c2e96 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -839,11 +839,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> { let llptr = if i == 0 { place.llval } else { - self.inbounds_gep( - self.type_i8(), - place.llval, - &[self.const_usize(b_offset.bytes())], - ) + self.inbounds_ptradd(place.llval, self.const_usize(b_offset.bytes())) }; let llty = place.layout.scalar_pair_element_gcc_type(self, i); let load = self.load(llty, llptr, align); From 7005ef96993d04d1440c310d116fc5373478e361 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 23 Feb 2024 10:20:45 +1100 Subject: [PATCH 09/17] Rename `DiagnosticBuilder` as `Diag`. Much better! Note that this involves renaming (and updating the value of) `DIAGNOSTIC_BUILDER` in clippy. --- src/errors.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/errors.rs b/src/errors.rs index 79eb4406b8a..fd03c5bf37a 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,6 +1,5 @@ use rustc_errors::{ - DiagCtxt, DiagnosticArgValue, DiagnosticBuilder, EmissionGuarantee, IntoDiagnostic, - IntoDiagnosticArg, Level, + DiagCtxt, DiagnosticArgValue, Diag, EmissionGuarantee, IntoDiagnostic, IntoDiagnosticArg, Level, }; use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_span::Span; @@ -112,12 +111,8 @@ pub(crate) struct TargetFeatureDisableOrEnable<'a> { pub(crate) struct MissingFeatures; impl IntoDiagnostic<'_, G> for TargetFeatureDisableOrEnable<'_> { - fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> { - let mut diag = DiagnosticBuilder::new( - dcx, - level, - fluent::codegen_gcc_target_feature_disable_or_enable - ); + fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> Diag<'_, G> { + let mut diag = Diag::new(dcx, level, fluent::codegen_gcc_target_feature_disable_or_enable); if let Some(span) = self.span { diag.span(span); }; From 427d6176c5856b0edeb33c46633c8d8acf97affb Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 23 Feb 2024 14:37:48 +1100 Subject: [PATCH 10/17] Rename `DiagnosticArg{,Map,Name,Value}` as `DiagArg{,Map,Name,Value}`. --- src/errors.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/errors.rs b/src/errors.rs index fd03c5bf37a..988a7e1033e 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,5 +1,5 @@ use rustc_errors::{ - DiagCtxt, DiagnosticArgValue, Diag, EmissionGuarantee, IntoDiagnostic, IntoDiagnosticArg, Level, + DiagCtxt, DiagArgValue, Diag, EmissionGuarantee, IntoDiagnostic, IntoDiagnosticArg, Level, }; use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_span::Span; @@ -34,11 +34,11 @@ pub(crate) enum PossibleFeature<'a> { struct ExitCode(Option); impl IntoDiagnosticArg for ExitCode { - fn into_diagnostic_arg(self) -> DiagnosticArgValue { + fn into_diagnostic_arg(self) -> DiagArgValue { let ExitCode(exit_code) = self; match exit_code { Some(t) => t.into_diagnostic_arg(), - None => DiagnosticArgValue::Str(Cow::Borrowed("")), + None => DiagArgValue::Str(Cow::Borrowed("")), } } } From 8dd96baddff3903a695a20d0e12ed92b3d2e435c Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Wed, 28 Feb 2024 03:44:23 -0500 Subject: [PATCH 11/17] Add `f16` and `f128` to `rustc_type_ir::FloatTy` and `rustc_abi::Primitive` Make changes necessary to support these types in the compiler. --- src/type_.rs | 10 ++++++++++ src/type_of.rs | 4 +++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/type_.rs b/src/type_.rs index 7a89fe81d38..7e5aa1c1766 100644 --- a/src/type_.rs +++ b/src/type_.rs @@ -83,8 +83,10 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> { pub fn type_float_from_ty(&self, t: ty::FloatTy) -> Type<'gcc> { match t { + ty::FloatTy::F16 => self.type_f16(), ty::FloatTy::F32 => self.type_f32(), ty::FloatTy::F64 => self.type_f64(), + ty::FloatTy::F128 => self.type_f128(), } } } @@ -118,6 +120,10 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> { self.isize_type } + fn type_f16(&self) -> Type<'gcc> { + unimplemented!("f16_f128") + } + fn type_f32(&self) -> Type<'gcc> { self.float_type } @@ -125,6 +131,10 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> { fn type_f64(&self) -> Type<'gcc> { self.double_type } + + fn type_f128(&self) -> Type<'gcc> { + unimplemented!("f16_f128") + } fn type_func(&self, params: &[Type<'gcc>], return_type: Type<'gcc>) -> Type<'gcc> { self.context.new_function_pointer_type(None, return_type, params, false) diff --git a/src/type_of.rs b/src/type_of.rs index 25149b80201..62136d24a2c 100644 --- a/src/type_of.rs +++ b/src/type_of.rs @@ -6,7 +6,7 @@ use rustc_middle::bug; use rustc_middle::ty::{self, Ty, TypeVisitableExt}; use rustc_middle::ty::layout::{LayoutOf, TyAndLayout}; use rustc_middle::ty::print::with_no_trimmed_paths; -use rustc_target::abi::{self, Abi, Align, F32, F64, FieldsShape, Int, Integer, Pointer, PointeeInfo, Size, TyAbiInterface, Variants}; +use rustc_target::abi::{self, Abi, Align, F16, F128, F32, F64, FieldsShape, Int, Integer, Pointer, PointeeInfo, Size, TyAbiInterface, Variants}; use rustc_target::abi::call::{CastTarget, FnAbi, Reg}; use crate::abi::{FnAbiGcc, FnAbiGccExt, GccType}; @@ -257,8 +257,10 @@ impl<'tcx> LayoutGccExt<'tcx> for TyAndLayout<'tcx> { match scalar.primitive() { Int(i, true) => cx.type_from_integer(i), Int(i, false) => cx.type_from_unsigned_integer(i), + F16 => cx.type_f16(), F32 => cx.type_f32(), F64 => cx.type_f64(), + F128 => cx.type_f128(), Pointer(address_space) => { // If we know the alignment, pick something better than i8. let pointee = From b76515708b5aab54fc69c50babc03ab92daaff08 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Tue, 5 Mar 2024 08:23:27 -0500 Subject: [PATCH 12/17] Workaround for linker error about missing -lLLVM-18-rust-1.78.0-nightly --- build.rs | 6 ++++++ deps/libLLVM-18-rust-1.78.0-nightly.so | 1 + 2 files changed, 7 insertions(+) create mode 100644 build.rs create mode 100644 deps/libLLVM-18-rust-1.78.0-nightly.so diff --git a/build.rs b/build.rs new file mode 100644 index 00000000000..b93c17793bf --- /dev/null +++ b/build.rs @@ -0,0 +1,6 @@ +// TODO: remove this file and deps/libLLVM-18-rust-1.78.0-nightly.so when +// https://github.com/rust-lang/rust/pull/121967 is merged. +fn main() { + println!("cargo:rerun-if-changed=deps/libLLVM-18-rust-1.78.0-nightly.so"); + println!("cargo:rustc-link-search=deps"); +} diff --git a/deps/libLLVM-18-rust-1.78.0-nightly.so b/deps/libLLVM-18-rust-1.78.0-nightly.so new file mode 100644 index 00000000000..c44ca790b4f --- /dev/null +++ b/deps/libLLVM-18-rust-1.78.0-nightly.so @@ -0,0 +1 @@ +INPUT(libLLVM.so.18.1-rust-1.78.0-nightly) From cd75da1f2ce67cf0ee10a4189b13c321f9c6ae4e Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Tue, 5 Mar 2024 08:33:42 -0500 Subject: [PATCH 13/17] Fix formatting --- src/builder.rs | 22 ++++++++---- src/errors.rs | 4 +-- src/intrinsic/mod.rs | 82 +++++++++++++++++++++++--------------------- src/type_.rs | 4 +-- src/type_of.rs | 31 ++++++++++++++--- 5 files changed, 87 insertions(+), 56 deletions(-) diff --git a/src/builder.rs b/src/builder.rs index 25eb987d625..f5cda81f6ab 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -1018,19 +1018,21 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> { let llty = place.layout.scalar_pair_element_gcc_type(self, i); let load = self.load(llty, llptr, align); scalar_load_metadata(self, load, scalar); - if scalar.is_bool() { self.trunc(load, self.type_i1()) } else { load } + if scalar.is_bool() { + self.trunc(load, self.type_i1()) + } else { + load + } }; OperandValue::Pair( load(0, a, place.align), load(1, b, place.align.restrict_for_offset(b_offset)), ) - } - else { + } else { OperandValue::Ref(place.llval, None, place.align) }; - OperandRef { val, layout: place.layout } } @@ -2075,7 +2077,11 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> { self.vector_reduce(src, |a, b, context| context.new_binary_op(loc, op, a.get_type(), a, b)) } - pub fn vector_reduce_fadd_reassoc(&mut self, _acc: RValue<'gcc>, _src: RValue<'gcc>) -> RValue<'gcc> { + pub fn vector_reduce_fadd_reassoc( + &mut self, + _acc: RValue<'gcc>, + _src: RValue<'gcc>, + ) -> RValue<'gcc> { unimplemented!(); } @@ -2102,7 +2108,11 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> { unimplemented!(); } - pub fn vector_reduce_fmul_reassoc(&mut self, _acc: RValue<'gcc>, _src: RValue<'gcc>) -> RValue<'gcc> { + pub fn vector_reduce_fmul_reassoc( + &mut self, + _acc: RValue<'gcc>, + _src: RValue<'gcc>, + ) -> RValue<'gcc> { unimplemented!(); } diff --git a/src/errors.rs b/src/errors.rs index 1d3e09d3f9c..f963a153fba 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,6 +1,4 @@ -use rustc_errors::{ - DiagCtxt, Diag, EmissionGuarantee, IntoDiagnostic, Level, -}; +use rustc_errors::{Diag, DiagCtxt, EmissionGuarantee, IntoDiagnostic, Level}; use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_span::Span; diff --git a/src/intrinsic/mod.rs b/src/intrinsic/mod.rs index 24d4650e9c2..a6c8b72e851 100644 --- a/src/intrinsic/mod.rs +++ b/src/intrinsic/mod.rs @@ -22,10 +22,10 @@ use rustc_middle::bug; use rustc_middle::ty::layout::LayoutOf; #[cfg(feature = "master")] use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt}; -use rustc_span::{Span, Symbol, sym}; -use rustc_target::abi::HasDataLayout; use rustc_middle::ty::{self, Instance, Ty}; +use rustc_span::{sym, Span, Symbol}; use rustc_target::abi::call::{ArgAbi, FnAbi, PassMode}; +use rustc_target::abi::HasDataLayout; #[cfg(feature = "master")] use rustc_target::spec::abi::Abi; use rustc_target::spec::PanicStrategy; @@ -122,44 +122,46 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> { let result = PlaceRef::new_sized(llresult, fn_abi.ret.layout); let simple = get_simple_intrinsic(self, name); - let llval = - match name { - _ if simple.is_some() => { - // FIXME(antoyo): remove this cast when the API supports function. - let func = unsafe { std::mem::transmute(simple.expect("simple")) }; - self.call(self.type_void(), None, None, func, &args.iter().map(|arg| arg.immediate()).collect::>(), None) - }, - sym::likely => { - self.expect(args[0].immediate(), true) - } - sym::unlikely => { - self.expect(args[0].immediate(), false) - } - sym::is_val_statically_known => { - let a = args[0].immediate(); - let builtin = self.context.get_builtin_function("__builtin_constant_p"); - let res = self.context.new_call(None, builtin, &[a]); - self.icmp(IntPredicate::IntEQ, res, self.const_i32(0)) - } - sym::catch_unwind => { - try_intrinsic( - self, - args[0].immediate(), - args[1].immediate(), - args[2].immediate(), - llresult, - ); - return Ok(()); - } - sym::breakpoint => { - unimplemented!(); - } - sym::va_copy => { - unimplemented!(); - } - sym::va_arg => { - unimplemented!(); - } + let llval = match name { + _ if simple.is_some() => { + // FIXME(antoyo): remove this cast when the API supports function. + let func = unsafe { std::mem::transmute(simple.expect("simple")) }; + self.call( + self.type_void(), + None, + None, + func, + &args.iter().map(|arg| arg.immediate()).collect::>(), + None, + ) + } + sym::likely => self.expect(args[0].immediate(), true), + sym::unlikely => self.expect(args[0].immediate(), false), + sym::is_val_statically_known => { + let a = args[0].immediate(); + let builtin = self.context.get_builtin_function("__builtin_constant_p"); + let res = self.context.new_call(None, builtin, &[a]); + self.icmp(IntPredicate::IntEQ, res, self.const_i32(0)) + } + sym::catch_unwind => { + try_intrinsic( + self, + args[0].immediate(), + args[1].immediate(), + args[2].immediate(), + llresult, + ); + return Ok(()); + } + sym::breakpoint => { + unimplemented!(); + } + sym::va_copy => { + unimplemented!(); + } + sym::va_arg => { + unimplemented!(); + } sym::volatile_load | sym::unaligned_volatile_load => { let tp_ty = fn_args.type_at(0); diff --git a/src/type_.rs b/src/type_.rs index df091bfde77..8fe3328ec55 100644 --- a/src/type_.rs +++ b/src/type_.rs @@ -123,7 +123,7 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> { fn type_f16(&self) -> Type<'gcc> { unimplemented!("f16_f128") } - + fn type_f32(&self) -> Type<'gcc> { self.float_type } @@ -131,7 +131,7 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> { fn type_f64(&self) -> Type<'gcc> { self.double_type } - + fn type_f128(&self) -> Type<'gcc> { unimplemented!("f16_f128") } diff --git a/src/type_of.rs b/src/type_of.rs index 27344a1b83d..8f9bfbbd18f 100644 --- a/src/type_of.rs +++ b/src/type_of.rs @@ -5,9 +5,12 @@ use gccjit::{Struct, Type}; use rustc_middle::bug; use rustc_middle::ty::layout::{LayoutOf, TyAndLayout}; use rustc_middle::ty::print::with_no_trimmed_paths; -use rustc_target::abi::{self, Abi, Align, F16, F128, F32, F64, FieldsShape, Int, Integer, Pointer, PointeeInfo, Size, TyAbiInterface, Variants}; use rustc_middle::ty::{self, Ty, TypeVisitableExt}; use rustc_target::abi::call::{CastTarget, FnAbi, Reg}; +use rustc_target::abi::{ + self, Abi, Align, FieldsShape, Int, Integer, PointeeInfo, Pointer, Size, TyAbiInterface, + Variants, F128, F16, F32, F64, +}; use crate::abi::{FnAbiGcc, FnAbiGccExt, GccType}; use crate::context::CodegenCx; @@ -157,9 +160,22 @@ pub trait LayoutGccExt<'tcx> { fn is_gcc_scalar_pair(&self) -> bool; fn gcc_type<'gcc>(&self, cx: &CodegenCx<'gcc, 'tcx>) -> Type<'gcc>; fn immediate_gcc_type<'gcc>(&self, cx: &CodegenCx<'gcc, 'tcx>) -> Type<'gcc>; - fn scalar_gcc_type_at<'gcc>(&self, cx: &CodegenCx<'gcc, 'tcx>, scalar: &abi::Scalar, offset: Size) -> Type<'gcc>; - fn scalar_pair_element_gcc_type<'gcc>(&self, cx: &CodegenCx<'gcc, 'tcx>, index: usize) -> Type<'gcc>; - fn pointee_info_at<'gcc>(&self, cx: &CodegenCx<'gcc, 'tcx>, offset: Size) -> Option; + fn scalar_gcc_type_at<'gcc>( + &self, + cx: &CodegenCx<'gcc, 'tcx>, + scalar: &abi::Scalar, + offset: Size, + ) -> Type<'gcc>; + fn scalar_pair_element_gcc_type<'gcc>( + &self, + cx: &CodegenCx<'gcc, 'tcx>, + index: usize, + ) -> Type<'gcc>; + fn pointee_info_at<'gcc>( + &self, + cx: &CodegenCx<'gcc, 'tcx>, + offset: Size, + ) -> Option; } impl<'tcx> LayoutGccExt<'tcx> for TyAndLayout<'tcx> { @@ -341,7 +357,12 @@ impl<'gcc, 'tcx> LayoutTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> { layout.is_gcc_scalar_pair() } - fn scalar_pair_element_backend_type(&self, layout: TyAndLayout<'tcx>, index: usize, _immediate: bool) -> Type<'gcc> { + fn scalar_pair_element_backend_type( + &self, + layout: TyAndLayout<'tcx>, + index: usize, + _immediate: bool, + ) -> Type<'gcc> { layout.scalar_pair_element_gcc_type(self, index) } From 499d3c229d2516b7ce9f5930ea15339467693580 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Tue, 5 Mar 2024 08:42:30 -0500 Subject: [PATCH 14/17] Fix CI --- build_system/src/test.rs | 1 + tests/failing-non-lto-tests.txt | 2 +- tests/failing-ui-tests.txt | 1 - 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build_system/src/test.rs b/build_system/src/test.rs index 470bb2431d5..4f9791dde48 100644 --- a/build_system/src/test.rs +++ b/build_system/src/test.rs @@ -912,6 +912,7 @@ fn should_remove_test(file_path: &Path) -> Result { } if [ "// error-pattern:", + "// @error-pattern:", "// build-fail", "// run-fail", "-Cllvm-args", diff --git a/tests/failing-non-lto-tests.txt b/tests/failing-non-lto-tests.txt index 4fd60f2b8e4..384dfdc26fb 100644 --- a/tests/failing-non-lto-tests.txt +++ b/tests/failing-non-lto-tests.txt @@ -5,7 +5,7 @@ tests/ui/lto/lto-many-codegen-units.rs tests/ui/lto/issue-100772.rs tests/ui/lto/lto-rustc-loads-linker-plugin.rs tests/ui/panic-runtime/lto-unwind.rs -tests/ui/sanitize/issue-111184-coroutine-witness.rs +tests/ui/sanitizer/issue-111184-cfi-coroutine-witness.rs tests/ui/sepcomp/sepcomp-lib-lto.rs tests/ui/lto/lto-opt-level-s.rs tests/ui/lto/lto-opt-level-z.rs diff --git a/tests/failing-ui-tests.txt b/tests/failing-ui-tests.txt index e504021bf2a..b9ad7ef33cf 100644 --- a/tests/failing-ui-tests.txt +++ b/tests/failing-ui-tests.txt @@ -76,7 +76,6 @@ tests/ui/linkage-attr/linkage-detect-extern-generated-name-collision.rs tests/ui/numbers-arithmetic/divide-by-zero.rs tests/ui/numbers-arithmetic/mod-zero.rs tests/ui/numbers-arithmetic/overflowing-neg-nonzero.rs -tests/ui/numbers-arithmetic/overflowing-neg.rs tests/ui/optimization-remark.rs tests/ui/panic-handler/panic-handler-std.rs tests/ui/panic-runtime/abort-link-to-unwind-dylib.rs From 42a0d63238a511fa913fbe7291903fa739c105b2 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 5 Mar 2024 15:47:58 +0100 Subject: [PATCH 15/17] Ignore rand tests warnings --- build_system/src/test.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/build_system/src/test.rs b/build_system/src/test.rs index 4f9791dde48..36d72512dfd 100644 --- a/build_system/src/test.rs +++ b/build_system/src/test.rs @@ -771,11 +771,19 @@ fn extended_rand_tests(env: &Env, args: &TestArg) -> Result<(), String> { println!("Not using GCC master branch. Skipping `extended_rand_tests`."); return Ok(()); } + let mut env = env.clone(); + // newer aho_corasick versions throw a deprecation warning + let rustflags = format!( + "{} --cap-lints warn", + env.get("RUSTFLAGS").cloned().unwrap_or_default() + ); + env.insert("RUSTFLAGS".to_string(), rustflags); + let path = Path::new(crate::BUILD_DIR).join("rand"); - run_cargo_command(&[&"clean"], Some(&path), env, args)?; + run_cargo_command(&[&"clean"], Some(&path), &env, args)?; // FIXME: create a function "display_if_not_quiet" or something along the line. println!("[TEST] rust-random/rand"); - run_cargo_command(&[&"test", &"--workspace"], Some(&path), env, args)?; + run_cargo_command(&[&"test", &"--workspace"], Some(&path), &env, args)?; Ok(()) } From 86a2bb760c729fe620a45f35fb55e89abeacfc40 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Tue, 5 Mar 2024 10:25:02 -0500 Subject: [PATCH 16/17] Fix CI --- build_system/src/test.rs | 9 +++++---- tests/failing-lto-tests.txt | 5 ----- tests/failing-ui-tests.txt | 33 --------------------------------- 3 files changed, 5 insertions(+), 42 deletions(-) diff --git a/build_system/src/test.rs b/build_system/src/test.rs index 36d72512dfd..a4db2fdebef 100644 --- a/build_system/src/test.rs +++ b/build_system/src/test.rs @@ -919,10 +919,9 @@ fn should_remove_test(file_path: &Path) -> Result { continue; } if [ - "// error-pattern:", - "// @error-pattern:", - "// build-fail", - "// run-fail", + "//@ error-pattern:", + "//@ build-fail", + "//@ run-fail", "-Cllvm-args", "//~", "thread", @@ -1016,6 +1015,8 @@ where // Tests generating errors. remove_file(&rust_path.join("tests/ui/consts/issue-94675.rs"))?; remove_file(&rust_path.join("tests/ui/mir/mir_heavy_promoted.rs"))?; + remove_file(&rust_path.join("tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop-fail.rs"))?; + remove_file(&rust_path.join("tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop.rs"))?; walk_dir(rust_path.join("tests/ui"), dir_handling, file_handling)?; diff --git a/tests/failing-lto-tests.txt b/tests/failing-lto-tests.txt index 8de45ae0f28..6e1ed99c6f7 100644 --- a/tests/failing-lto-tests.txt +++ b/tests/failing-lto-tests.txt @@ -21,7 +21,6 @@ tests/ui/fmt/format-args-capture-issue-106408.rs tests/ui/fmt/indoc-issue-106408.rs tests/ui/hygiene/issue-77523-def-site-async-await.rs tests/ui/inherent-impls-overlap-check/no-overlap.rs -tests/ui/annotate-snippet/multispan.rs tests/ui/enum-discriminant/issue-46519.rs tests/ui/issues/issue-45731.rs tests/ui/lint/test-allow-dead-extern-static-no-warning.rs @@ -29,9 +28,5 @@ tests/ui/macros/macro-comma-behavior-rpass.rs tests/ui/macros/rfc-2011-nicer-assert-messages/assert-with-custom-errors-does-not-create-unnecessary-code.rs tests/ui/macros/rfc-2011-nicer-assert-messages/feature-gate-generic_assert.rs tests/ui/macros/stringify.rs -tests/ui/panics/test-panic.rs -tests/ui/panics/test-should-fail-bad-message.rs -tests/ui/panics/test-should-panic-bad-message.rs -tests/ui/panics/test-should-panic-no-message.rs tests/ui/reexport-test-harness-main.rs tests/ui/rfcs/rfc-1937-termination-trait/termination-trait-in-test.rs diff --git a/tests/failing-ui-tests.txt b/tests/failing-ui-tests.txt index b9ad7ef33cf..d13562f8bb0 100644 --- a/tests/failing-ui-tests.txt +++ b/tests/failing-ui-tests.txt @@ -69,41 +69,8 @@ tests/ui/async-await/deep-futures-are-freeze.rs tests/ui/closures/capture-unsized-by-ref.rs tests/ui/coroutine/resume-after-return.rs tests/ui/macros/rfc-2011-nicer-assert-messages/all-expr-kinds.rs -tests/ui/limits/issue-17913.rs -tests/ui/limits/issue-55878.rs -tests/ui/linkage-attr/common-linkage-non-zero-init.rs -tests/ui/linkage-attr/linkage-detect-extern-generated-name-collision.rs -tests/ui/numbers-arithmetic/divide-by-zero.rs -tests/ui/numbers-arithmetic/mod-zero.rs -tests/ui/numbers-arithmetic/overflowing-neg-nonzero.rs -tests/ui/optimization-remark.rs -tests/ui/panic-handler/panic-handler-std.rs -tests/ui/panic-runtime/abort-link-to-unwind-dylib.rs -tests/ui/panic-runtime/need-unwind-got-abort.rs -tests/ui/panics/issue-47429-short-backtraces.rs -tests/ui/panics/panic-in-cleanup.rs -tests/ui/panics/panic-in-ffi.rs -tests/ui/panics/runtime-switch.rs -tests/ui/panics/short-ice-remove-middle-frames-2.rs -tests/ui/panics/short-ice-remove-middle-frames.rs -tests/ui/precondition-checks/out-of-bounds-get-unchecked.rs tests/ui/simd/masked-load-store.rs tests/ui/simd/repr_packed.rs -tests/ui/type_length_limit.rs tests/ui/async-await/in-trait/dont-project-to-specializable-projection.rs -tests/ui/async-await/issues/issue-65419/issue-65419-coroutine-resume-after-completion.rs -tests/ui/c-variadic/issue-86053-1.rs -tests/ui/const-ptr/out_of_bounds_read.rs -tests/ui/consts/const_unsafe_unreachable_ub.rs -tests/ui/consts/miri_unleashed/drop.rs -tests/ui/consts/timeout.rs tests/ui/consts/try-operator.rs -tests/ui/coroutine/coroutine-resume-after-panic.rs tests/ui/coroutine/unwind-abort-mix.rs -tests/ui/duplicate/dupe-symbols-7.rs -tests/ui/duplicate/dupe-symbols-8.rs -tests/ui/hygiene/panic-location.rs -tests/ui/invalid/issue-114435-layout-type-err.rs -tests/ui/invalid-compile-flags/invalid-llvm-passes.rs -tests/ui/lto/issue-105637.rs -tests/ui/lto/lto-duplicate-symbols.rs From 3b4c58d7f570f2db6a35e5a3d90167cfada02dd3 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Tue, 5 Mar 2024 12:50:14 -0500 Subject: [PATCH 17/17] Fix rand tests --- build_system/src/prepare.rs | 26 +++++++++++++++++++ .../crates/0001-Remove-deny-warnings.patch | 24 +++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 patches/crates/0001-Remove-deny-warnings.patch diff --git a/build_system/src/prepare.rs b/build_system/src/prepare.rs index 4ea334ad8b9..821c793c7e5 100644 --- a/build_system/src/prepare.rs +++ b/build_system/src/prepare.rs @@ -131,6 +131,30 @@ fn prepare_libcore( )?; } println!("Successfully prepared libcore for building"); + + Ok(()) +} + +// TODO: remove when we can ignore warnings in rustdoc tests. +fn prepare_rand() -> Result<(), String> { + // Apply patch for the rand crate. + let file_path = "patches/crates/0001-Remove-deny-warnings.patch"; + let rand_dir = Path::new("build/rand"); + println!("[GIT] apply `{}`", file_path); + let path = Path::new("../..").join(file_path); + run_command_with_output(&[&"git", &"apply", &path], Some(rand_dir))?; + run_command_with_output(&[&"git", &"add", &"-A"], Some(rand_dir))?; + run_command_with_output( + &[ + &"git", + &"commit", + &"--no-gpg-sign", + &"-m", + &format!("Patch {}", path.display()), + ], + Some(rand_dir), + )?; + Ok(()) } @@ -241,6 +265,8 @@ pub fn run() -> Result<(), String> { for (repo_url, checkout_commit, cb) in to_clone { clone_and_setup(repo_url, checkout_commit, *cb)?; } + + prepare_rand()?; } println!("Successfully ran `prepare`"); diff --git a/patches/crates/0001-Remove-deny-warnings.patch b/patches/crates/0001-Remove-deny-warnings.patch new file mode 100644 index 00000000000..66ea1df4e13 --- /dev/null +++ b/patches/crates/0001-Remove-deny-warnings.patch @@ -0,0 +1,24 @@ +From f4a31d2c57cdbd578b778ab70eb2a0cfb248652c Mon Sep 17 00:00:00 2001 +From: Antoni Boucher +Date: Tue, 5 Mar 2024 12:39:44 -0500 +Subject: [PATCH] Remove #[deny(warnings)] + +--- + src/lib.rs | 1 - + 1 file changed, 1 deletion(-) + +diff --git a/src/lib.rs b/src/lib.rs +index 8ade2881d5..e26c595e38 100644 +--- a/src/lib.rs ++++ b/src/lib.rs +@@ -47,7 +47,6 @@ + )] + #![deny(missing_docs)] + #![deny(missing_debug_implementations)] +-#![doc(test(attr(allow(unused_variables), deny(warnings))))] + #![no_std] + #![cfg_attr(feature = "simd_support", feature(stdsimd, portable_simd))] + #![cfg_attr(doc_cfg, feature(doc_cfg))] +-- +2.44.0 +