Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
18 changes: 6 additions & 12 deletions compiler/rustc_builtin_macros/src/deriving/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -986,16 +986,6 @@ impl<'a> MethodDef<'a> {
f(cx, span, &substructure)
}

fn get_ret_ty(
&self,
cx: &ExtCtxt<'_>,
trait_: &TraitDef<'_>,
generics: &Generics,
type_ident: Ident,
) -> Box<ast::Ty> {
self.ret_ty.to_ty(cx, trait_.span, type_ident, generics)
}

fn is_static(&self) -> bool {
!self.explicit_self
}
Expand Down Expand Up @@ -1068,10 +1058,14 @@ impl<'a> MethodDef<'a> {
self_arg.into_iter().chain(nonself_args).collect()
};

let ret_type = self.get_ret_ty(cx, trait_, generics, type_ident);
let ret_type = if let Ty::Unit = &self.ret_ty {
ast::FnRetTy::Default(span)
} else {
ast::FnRetTy::Ty(self.ret_ty.to_ty(cx, span, type_ident, generics))
};

let method_ident = Ident::new(self.name, span);
let fn_decl = cx.fn_decl(args, ast::FnRetTy::Ty(ret_type));
let fn_decl = cx.fn_decl(args, ret_type);
let body_block = body.into_block(cx, span);

let trait_lo_sp = span.shrink_to_lo();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
From aacbac292e8b470c8be0e284f3005192f94a0481 Mon Sep 17 00:00:00 2001
From: xonx <119700621+xonx4l@users.noreply.github.com>
Date: Tue, 13 Jan 2026 17:20:06 +0000
Subject: [PATCH] Disable f16 math tests for cranelift

---
coretests/tests/floats/mod.rs | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/coretests/tests/floats/mod.rs b/coretests/tests/floats/mod.rs
index 58892b3daa6..dc3da4a3311 100644
--- a/coretests/tests/floats/mod.rs
+++ b/coretests/tests/floats/mod.rs
@@ -1536,7 +1536,7 @@ fn s_nan() -> Float {
name: powf,
attrs: {
const: #[cfg(false)],
- f16: #[cfg(any(miri, target_has_reliable_f16_math))],
+ f16: #[cfg(false)], // FIXME(rust-lang/rustc_codegen_cranelift#1622)
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
},
test<Float> {
@@ -1559,7 +1559,7 @@ fn s_nan() -> Float {
name: exp,
attrs: {
const: #[cfg(false)],
- f16: #[cfg(any(miri, target_has_reliable_f16_math))],
+ f16: #[cfg(false)], // FIXME(rust-lang/rustc_codegen_cranelift#1622)
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
},
test<Float> {
@@ -1580,7 +1580,7 @@ fn s_nan() -> Float {
name: exp2,
attrs: {
const: #[cfg(false)],
- f16: #[cfg(any(miri, target_has_reliable_f16_math))],
+ f16: #[cfg(false)], // FIXME(rust-lang/rustc_codegen_cranelift#1622)
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
},
test<Float> {
@@ -1600,7 +1600,7 @@ fn s_nan() -> Float {
name: ln,
attrs: {
const: #[cfg(false)],
- f16: #[cfg(any(miri, target_has_reliable_f16_math))],
+ f16: #[cfg(false)], // FIXME(rust-lang/rustc_codegen_cranelift#1622)
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
},
test<Float> {
@@ -1622,7 +1622,7 @@ fn s_nan() -> Float {
name: log,
attrs: {
const: #[cfg(false)],
- f16: #[cfg(any(miri, target_has_reliable_f16_math))],
+ f16: #[cfg(false)], // FIXME(rust-lang/rustc_codegen_cranelift#1622)
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
},
test<Float> {
@@ -1647,7 +1647,7 @@ fn s_nan() -> Float {
name: log2,
attrs: {
const: #[cfg(false)],
- f16: #[cfg(any(miri, target_has_reliable_f16_math))],
+ f16: #[cfg(false)], // FIXME(rust-lang/rustc_codegen_cranelift#1622)
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
},
test<Float> {
@@ -1670,7 +1670,7 @@ fn s_nan() -> Float {
name: log10,
attrs: {
const: #[cfg(false)],
- f16: #[cfg(any(miri, target_has_reliable_f16_math))],
+ f16: #[cfg(false)], // FIXME(rust-lang/rustc_codegen_cranelift#1622)
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
},
test<Float> {
@@ -1694,7 +1694,7 @@ fn s_nan() -> Float {
name: asinh,
attrs: {
const: #[cfg(false)],
- f16: #[cfg(any(miri, target_has_reliable_f16_math))],
+ f16: #[cfg(false)], // FIXME(rust-lang/rustc_codegen_cranelift#1622)
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
},
test<Float> {
@@ -1725,7 +1725,7 @@ fn s_nan() -> Float {
name: acosh,
attrs: {
const: #[cfg(false)],
- f16: #[cfg(any(miri, target_has_reliable_f16_math))],
+ f16: #[cfg(false)], // FIXME(rust-lang/rustc_codegen_cranelift#1622)
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
},
test<Float> {
@@ -1752,7 +1752,7 @@ fn s_nan() -> Float {
name: atanh,
attrs: {
const: #[cfg(false)],
- f16: #[cfg(any(miri, target_has_reliable_f16_math))],
+ f16: #[cfg(false)], // FIXME(rust-lang/rustc_codegen_cranelift#1622)
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
},
test<Float> {
@@ -1778,7 +1778,7 @@ fn s_nan() -> Float {
name: gamma,
attrs: {
const: #[cfg(false)],
- f16: #[cfg(any(miri, target_has_reliable_f16_math))],
+ f16: #[cfg(false)], // FIXME(rust-lang/rustc_codegen_cranelift#1622)
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
},
test<Float> {
@@ -1804,7 +1804,7 @@ fn s_nan() -> Float {
name: ln_gamma,
attrs: {
const: #[cfg(false)],
- f16: #[cfg(any(miri, target_has_reliable_f16_math))],
+ f16: #[cfg(false)], // FIXME(rust-lang/rustc_codegen_cranelift#1622)
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
},
test<Float> {
@@ -1942,7 +1942,7 @@ fn s_nan() -> Float {
attrs: {
// FIXME(f16_f128): add math tests when available
const: #[cfg(false)],
- f16: #[cfg(any(miri, target_has_reliable_f16_math))],
+ f16: #[cfg(false)], // FIXME(rust-lang/rustc_codegen_cranelift#1622)
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
},
test<Float> {
--
2.50.1

27 changes: 14 additions & 13 deletions compiler/rustc_codegen_llvm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1397,12 +1397,12 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
fn call(
&mut self,
llty: &'ll Type,
fn_call_attrs: Option<&CodegenFnAttrs>,
caller_attrs: Option<&CodegenFnAttrs>,
fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>,
llfn: &'ll Value,
args: &[&'ll Value],
funclet: Option<&Funclet<'ll>>,
instance: Option<Instance<'tcx>>,
callee_instance: Option<Instance<'tcx>>,
) -> &'ll Value {
debug!("call {:?} with args ({:?})", llfn, args);

Expand All @@ -1414,10 +1414,10 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
}

// Emit CFI pointer type membership test
self.cfi_type_test(fn_call_attrs, fn_abi, instance, llfn);
self.cfi_type_test(caller_attrs, fn_abi, callee_instance, llfn);

// Emit KCFI operand bundle
let kcfi_bundle = self.kcfi_operand_bundle(fn_call_attrs, fn_abi, instance, llfn);
let kcfi_bundle = self.kcfi_operand_bundle(caller_attrs, fn_abi, callee_instance, llfn);
if let Some(kcfi_bundle) = kcfi_bundle.as_ref().map(|b| b.as_ref()) {
bundles.push(kcfi_bundle);
}
Expand All @@ -1435,17 +1435,17 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
)
};

if let Some(instance) = instance {
if let Some(callee_instance) = callee_instance {
// Attributes on the function definition being called
let fn_defn_attrs = self.cx.tcx.codegen_fn_attrs(instance.def_id());
if let Some(fn_call_attrs) = fn_call_attrs
let callee_attrs = self.cx.tcx.codegen_fn_attrs(callee_instance.def_id());
if let Some(caller_attrs) = caller_attrs
// If there is an inline attribute and a target feature that matches
// we will add the attribute to the callsite otherwise we'll omit
// this and not add the attribute to prevent soundness issues.
&& let Some(inlining_rule) = attributes::inline_attr(&self.cx, self.cx.tcx, instance)
&& let Some(inlining_rule) = attributes::inline_attr(&self.cx, self.cx.tcx, callee_instance)
&& self.cx.tcx.is_target_feature_call_safe(
&fn_defn_attrs.target_features,
&fn_call_attrs.target_features.iter().cloned().chain(
&callee_attrs.target_features,
&caller_attrs.target_features.iter().cloned().chain(
self.cx.tcx.sess.target_features.iter().map(|feat| TargetFeature {
name: *feat,
kind: TargetFeatureKind::Implied,
Expand All @@ -1470,14 +1470,15 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
fn tail_call(
&mut self,
llty: Self::Type,
fn_attrs: Option<&CodegenFnAttrs>,
caller_attrs: Option<&CodegenFnAttrs>,
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
llfn: Self::Value,
args: &[Self::Value],
funclet: Option<&Self::Funclet>,
instance: Option<Instance<'tcx>>,
callee_instance: Option<Instance<'tcx>>,
) {
let call = self.call(llty, fn_attrs, Some(fn_abi), llfn, args, funclet, instance);
let call =
self.call(llty, caller_attrs, Some(fn_abi), llfn, args, funclet, callee_instance);
llvm::LLVMSetTailCallKind(call, llvm::TailCallKind::MustTail);

match &fn_abi.ret.mode {
Expand Down
19 changes: 13 additions & 6 deletions compiler/rustc_codegen_ssa/src/mir/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,12 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
// do an invoke, otherwise do a call.
let fn_ty = bx.fn_decl_backend_type(fn_abi);

let fn_attrs = if bx.tcx().def_kind(fx.instance.def_id()).has_codegen_attrs() {
let caller_attrs = if bx.tcx().def_kind(fx.instance.def_id()).has_codegen_attrs() {
Some(bx.tcx().codegen_instance_attrs(fx.instance.def))
} else {
None
};
let fn_attrs = fn_attrs.as_deref();
let caller_attrs = caller_attrs.as_deref();

if !fn_abi.can_unwind {
unwind = mir::UnwindAction::Unreachable;
Expand Down Expand Up @@ -233,7 +233,7 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
};

if kind == CallKind::Tail {
bx.tail_call(fn_ty, fn_attrs, fn_abi, fn_ptr, llargs, self.funclet(fx), instance);
bx.tail_call(fn_ty, caller_attrs, fn_abi, fn_ptr, llargs, self.funclet(fx), instance);
return MergingSucc::False;
}

Expand All @@ -245,7 +245,7 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
};
let invokeret = bx.invoke(
fn_ty,
fn_attrs,
caller_attrs,
Some(fn_abi),
fn_ptr,
llargs,
Expand All @@ -268,8 +268,15 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
}
MergingSucc::False
} else {
let llret =
bx.call(fn_ty, fn_attrs, Some(fn_abi), fn_ptr, llargs, self.funclet(fx), instance);
let llret = bx.call(
fn_ty,
caller_attrs,
Some(fn_abi),
fn_ptr,
llargs,
self.funclet(fx),
instance,
);
if fx.mir[self.bb].is_cleanup {
bx.apply_attrs_to_cleanup_callsite(llret);
}
Expand Down
19 changes: 11 additions & 8 deletions compiler/rustc_codegen_ssa/src/traits/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,10 +600,13 @@ pub trait BuilderMethods<'a, 'tcx>:
///
/// ## Arguments
///
/// The `fn_attrs`, `fn_abi`, and `instance` arguments are Options because they are advisory.
/// They relate to optional codegen enhancements like LLVM CFI, and do not affect ABI per se.
/// Any ABI-related transformations should be handled by different, earlier stages of codegen.
/// For instance, in the caller of `BuilderMethods::call`.
/// `caller_attrs` are the attributes of the surrounding caller; they have nothing to do with
/// the callee.
///
/// The `caller_attrs`, `fn_abi`, and `callee_instance` arguments are Options because they are
/// advisory. They relate to optional codegen enhancements like LLVM CFI, and do not affect ABI
/// per se. Any ABI-related transformations should be handled by different, earlier stages of
/// codegen. For instance, in the caller of `BuilderMethods::call`.
///
/// This means that a codegen backend which disregards `fn_attrs`, `fn_abi`, and `instance`
/// should still do correct codegen, and code should not be miscompiled if they are omitted.
Expand All @@ -620,23 +623,23 @@ pub trait BuilderMethods<'a, 'tcx>:
fn call(
&mut self,
llty: Self::Type,
fn_attrs: Option<&CodegenFnAttrs>,
caller_attrs: Option<&CodegenFnAttrs>,
fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>,
fn_val: Self::Value,
args: &[Self::Value],
funclet: Option<&Self::Funclet>,
instance: Option<Instance<'tcx>>,
callee_instance: Option<Instance<'tcx>>,
) -> Self::Value;

fn tail_call(
&mut self,
llty: Self::Type,
fn_attrs: Option<&CodegenFnAttrs>,
caller_attrs: Option<&CodegenFnAttrs>,
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
llfn: Self::Value,
args: &[Self::Value],
funclet: Option<&Self::Funclet>,
instance: Option<Instance<'tcx>>,
callee_instance: Option<Instance<'tcx>>,
);

fn zext(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
Expand Down
29 changes: 14 additions & 15 deletions compiler/rustc_const_eval/src/check_consts/qualifs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,17 +343,18 @@ where

// Check the qualifs of the value of `const` items.
let uneval = match constant.const_ {
Const::Ty(_, ct)
if matches!(
ct.kind(),
ty::ConstKind::Param(_) | ty::ConstKind::Error(_) | ty::ConstKind::Value(_)
) =>
{
None
}
Const::Ty(_, c) => {
bug!("expected ConstKind::Param or ConstKind::Value here, found {:?}", c)
}
Const::Ty(_, ct) => match ct.kind() {
ty::ConstKind::Param(_) | ty::ConstKind::Error(_) => None,
// Unevaluated consts in MIR bodies don't have associated MIR (e.g. `#[type_const]`).
ty::ConstKind::Unevaluated(_) => None,
// FIXME(mgca): Investigate whether using `None` for `ConstKind::Value` is overly
// strict, and if instead we should be doing some kind of value-based analysis.
ty::ConstKind::Value(_) => None,
_ => bug!(
"expected ConstKind::Param, ConstKind::Value, ConstKind::Unevaluated, or ConstKind::Error here, found {:?}",
ct
),
},
Const::Unevaluated(uv, _) => Some(uv),
Const::Val(..) => None,
};
Expand All @@ -364,10 +365,8 @@ where
// check performed after the promotion. Verify that with an assertion.
assert!(promoted.is_none() || Q::ALLOW_PROMOTED);

// Don't peak inside trait associated constants, also `#[type_const] const` items
// don't have bodies so there's nothing to look at
if promoted.is_none() && cx.tcx.trait_of_assoc(def).is_none() && !cx.tcx.is_type_const(def)
{
// Don't peak inside trait associated constants.
if promoted.is_none() && cx.tcx.trait_of_assoc(def).is_none() {
let qualifs = cx.tcx.at(constant.span).mir_const_qualif(def);

if !Q::in_qualifs(&qualifs) {
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,12 @@ LLVMRustCreateAttrNoValue(LLVMContextRef C, LLVMRustAttributeKind RustAttr) {
*unwrap(C), CaptureInfo(CaptureComponents::Address |
CaptureComponents::ReadProvenance)));
}
#endif
#if LLVM_VERSION_GE(23, 0)
if (RustAttr == LLVMRustAttributeKind::DeadOnReturn) {
return wrap(Attribute::getWithDeadOnReturnInfo(*unwrap(C),
llvm::DeadOnReturnInfo()));
}
#endif
return wrap(Attribute::get(*unwrap(C), fromRust(RustAttr)));
}
Expand Down
Loading
Loading