Skip to content

Commit

Permalink
Sync from rust eb4e234
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn3 committed Oct 10, 2024
2 parents 14f656e + 2811ce7 commit 3cf701c
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 37 deletions.
6 changes: 6 additions & 0 deletions example/mini_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,12 @@ pub macro global_asm() {
/* compiler built-in */
}

#[rustc_builtin_macro]
#[rustc_macro_transparency = "semitransparent"]
pub macro naked_asm() {
/* compiler built-in */
}

pub static A_STATIC: u8 = 42;

#[lang = "panic_location"]
Expand Down
2 changes: 1 addition & 1 deletion example/mini_core_hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ global_asm! {
#[naked]
extern "C" fn naked_test() {
unsafe {
asm!("ret", options(noreturn));
naked_asm!("ret");
}
}

Expand Down
4 changes: 2 additions & 2 deletions example/std_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ fn main() {

foo(I64X2([0, 0]));

transmute_fat_pointer();
transmute_wide_pointer();

rust_call_abi();

Expand All @@ -192,7 +192,7 @@ type TwoPtrs = i64;
#[cfg(target_pointer_width = "64")]
type TwoPtrs = i128;

fn transmute_fat_pointer() -> TwoPtrs {
fn transmute_wide_pointer() -> TwoPtrs {
unsafe { transmute::<_, TwoPtrs>("true !") }
}

Expand Down
13 changes: 0 additions & 13 deletions patches/0027-stdlib-128bit-atomic-operations.patch
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,6 @@ index d9de37e..8293fce 100644
#[cfg(target_has_atomic_load_store = "ptr")]
macro_rules! atomic_int_ptr_sized {
( $($target_pointer_width:literal $align:literal)* ) => { $(
diff --git a/library/core/src/cell.rs b/library/core/src/cell.rs
index 58b9ba4..91bbd0a 100644
--- a/library/core/src/cell.rs
+++ b/library/core/src/cell.rs
@@ -2246,8 +2246,6 @@ unsafe_cell_primitive_into_inner! {
u32 "32"
i64 "64"
u64 "64"
- i128 "128"
- u128 "128"
isize "ptr"
usize "ptr"
}
--
2.26.2.7.g19db9cfb68

13 changes: 8 additions & 5 deletions src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use rustc_ast::InlineAsmOptions;
use rustc_codegen_ssa::base::is_call_from_compiler_builtins_to_upstream_monomorphization;
use rustc_index::IndexVec;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc_middle::mir::InlineAsmMacro;
use rustc_middle::ty::TypeVisitableExt;
use rustc_middle::ty::adjustment::PointerCoercion;
use rustc_middle::ty::layout::FnAbiOf;
Expand Down Expand Up @@ -57,6 +58,7 @@ pub(crate) fn codegen_fn<'tcx>(

match &mir.basic_blocks[START_BLOCK].terminator().kind {
TerminatorKind::InlineAsm {
asm_macro: InlineAsmMacro::NakedAsm,
template,
operands,
options,
Expand Down Expand Up @@ -498,6 +500,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
"tail calls are not yet supported in `rustc_codegen_cranelift` backend"
),
TerminatorKind::InlineAsm {
asm_macro: _,
template,
operands,
options,
Expand Down Expand Up @@ -713,17 +716,17 @@ fn codegen_stmt<'tcx>(
let from_ty = operand.layout().ty;
let to_ty = fx.monomorphize(to_ty);

fn is_fat_ptr<'tcx>(fx: &FunctionCx<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool {
fn is_wide_ptr<'tcx>(fx: &FunctionCx<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool {
ty.builtin_deref(true)
.is_some_and(|pointee_ty| has_ptr_meta(fx.tcx, pointee_ty))
}

if is_fat_ptr(fx, from_ty) {
if is_fat_ptr(fx, to_ty) {
// fat-ptr -> fat-ptr
if is_wide_ptr(fx, from_ty) {
if is_wide_ptr(fx, to_ty) {
// wide-ptr -> wide-ptr
lval.write_cvalue(fx, operand.cast_pointer_to(dest_layout));
} else {
// fat-ptr -> thin-ptr
// wide-ptr -> thin-ptr
let (ptr, _extra) = operand.load_scalar_pair(fx);
lval.write_cvalue(fx, CValue::by_val(ptr, dest_layout))
}
Expand Down
2 changes: 1 addition & 1 deletion src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ fn clif_pair_type_from_ty<'tcx>(
})
}

/// Is a pointer to this type a fat ptr?
/// Is a pointer to this type a wide ptr?
pub(crate) fn has_ptr_meta<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
if ty.is_sized(tcx, ParamEnv::reveal_all()) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/debuginfo/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl DebugContext {

pointer_type_id
} else {
// FIXME implement debuginfo for fat pointers
// FIXME implement debuginfo for wide pointers
self.placeholder_for_type(tcx, type_dbg, ptr_type)
}
}
Expand Down
17 changes: 3 additions & 14 deletions src/unsize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//!
//! [`PointerCoercion::Unsize`]: `rustc_middle::ty::adjustment::PointerCoercion::Unsize`
use rustc_codegen_ssa::base::validate_trivial_unsize;
use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths};

use crate::base::codegen_panic_nounwind;
Expand Down Expand Up @@ -34,20 +35,8 @@ pub(crate) fn unsized_info<'tcx>(
let old_info =
old_info.expect("unsized_info: missing old info for trait upcasting coercion");
if data_a.principal_def_id() == data_b.principal_def_id() {
// Codegen takes advantage of the additional assumption, where if the
// principal trait def id of what's being casted doesn't change,
// then we don't need to adjust the vtable at all. This
// corresponds to the fact that `dyn Tr<A>: Unsize<dyn Tr<B>>`
// requires that `A = B`; we don't allow *upcasting* objects
// between the same trait with different args. If we, for
// some reason, were to relax the `Unsize` trait, it could become
// unsound, so let's assert here that the trait refs are *equal*.
//
// We can use `assert_eq` because the binders should have been anonymized,
// and because higher-ranked equality now requires the binders are equal.
debug_assert_eq!(
data_a.principal(),
data_b.principal(),
debug_assert!(
validate_trivial_unsize(fx.tcx, data_a, data_b),
"NOP unsize vtable changed principal trait ref: {data_a} -> {data_b}"
);
return old_info;
Expand Down

0 comments on commit 3cf701c

Please sign in to comment.