Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
68cfe93
Add comments to randomize-layout implementation documenting guarantee…
zachs18 Jun 15, 2026
bec5d88
Add zero-variant enums to randomize-layout comments and tests.
zachs18 Jun 15, 2026
715a616
move batch
zedddie Jul 9, 2026
dd8996d
bless batch
zedddie Jul 9, 2026
b1bddeb
move batch
zedddie Jul 10, 2026
b23c2ee
bless batch
zedddie Jul 10, 2026
c703f8a
doc: document wasm import symbol mangling
kn1g78 Jul 11, 2026
c100aca
doc: clarify wasm import symbol mangling
kn1g78 Jul 13, 2026
f266337
doc: describe wasm import conflict behavior
kn1g78 Jul 13, 2026
032d959
ensure to check that the overview is current
tshepang Jul 15, 2026
a61a054
use sentence case for titles
tshepang Jul 15, 2026
6201540
Merge pull request #2928 from rust-lang/tshepang/sentence-case
tshepang Jul 15, 2026
821701a
fix rustup update command for autodiff
ZuseZ4 Jul 15, 2026
1912059
Merge pull request #2929 from rust-lang/rustup-enzyme-update2
ZuseZ4 Jul 15, 2026
905a7e0
Track placeholder assumptions for created universes
Dnreikronos Jul 16, 2026
8211f90
Add coverage for placeholder assumption ICE
Dnreikronos Jul 16, 2026
4f1921c
use sentence case for titles
tshepang Jul 16, 2026
1a180c0
reflow
tshepang Jul 16, 2026
340f705
Merge pull request #2930 from rust-lang/tshepang/sentence-case
tshepang Jul 16, 2026
74c230e
ci: Enable autodiff tests on x86_64 linux
sgasho Jul 10, 2026
9e298de
add `difference` method to `range_set`
folkertdev Jul 17, 2026
4c5cd66
add LLVM baseline test
folkertdev Jul 17, 2026
749d84c
the tag is not padding
folkertdev Jul 17, 2026
26fdd3f
refactor
folkertdev Jul 17, 2026
377748d
move batch
zedddie Jul 17, 2026
a2730fa
replace codeview.pdf with link to archived webpage
Walnut356 Jul 18, 2026
0fe4afc
clear the variant-dependent padding
folkertdev Jul 17, 2026
2d0b4b3
typo
tshepang Jul 18, 2026
37a4a74
Merge pull request #2931 from Walnut356/codeview
tshepang Jul 18, 2026
6d6092c
bless batch
zedddie Jul 17, 2026
fb119e0
Clarify what to do when you break a subtree build
panstromek Jul 18, 2026
4ee71fe
docs: add autodiff CI job document
sgasho Jul 19, 2026
2851cef
move batch
zedddie Jul 19, 2026
2e1df4d
Merge pull request #2932 from panstromek/patch-1
tshepang Jul 20, 2026
4e53ac1
Add allow_list checking for eii implementation attributes
chenyukang Jul 14, 2026
7726456
extraneous word
tshepang Jul 20, 2026
216b07a
deserves own sentence
tshepang Jul 20, 2026
a9d6ac1
Add test cases for a hoisting miscompilation
dianqk Jul 20, 2026
a22fed7
early_otherwise: Don't hoist dereferences when the otherwise branch i…
dianqk Jul 20, 2026
6c5df71
update thir output
tshepang Jul 20, 2026
4809e4c
sembr src/hir-typeck/summary.md
tshepang Jul 20, 2026
775b479
unusual use of colon
tshepang Jul 20, 2026
ef6ce22
sembr src/debuginfo/intro.md
tshepang Jul 20, 2026
c0c2829
reflow
tshepang Jul 20, 2026
53e1b93
sembr src/debuginfo/rust-codegen.md
tshepang Jul 20, 2026
ff8c0c5
reflow
tshepang Jul 20, 2026
5fab7f9
Prepare for merging from rust-lang/rust
invalid-email-address Jul 20, 2026
5355f97
Merge ref '9e71b3bc704e' from rust-lang/rust
invalid-email-address Jul 20, 2026
890741b
lighter markup
tshepang Jul 20, 2026
d6be727
use sentence case for titles
tshepang Jul 20, 2026
147ffe4
fix section title
tshepang Jul 20, 2026
1064b07
it will happen when it does
tshepang Jul 20, 2026
6af6107
use sentence case for titles
tshepang Jul 20, 2026
df163d8
sembr src/debuginfo/debugger-internals.md
tshepang Jul 20, 2026
3b999ca
bless batch
zedddie Jul 19, 2026
7ff730b
run `tests/assembly-llvm/asm/aarch64-types.rs` for `aarch64_be`
folkertdev Jul 21, 2026
f68af89
rdg: Move Autodiff CI job below performance testing
sgasho Jul 21, 2026
2bb8a3b
Delete autodiff.sh and move the test command to the Dockerfile
sgasho Jul 21, 2026
9715950
Merge pull request #2934 from rust-lang/rustc-pull
tshepang Jul 22, 2026
4233b3b
Collect constants within `global_asm!` in collector
nbdd0121 Mar 12, 2025
f44536c
Add FnDef/Closure -> FnPtr coercion for inline asm const operand
nbdd0121 Dec 5, 2025
bf74b6c
Give global_asm symbol names
nbdd0121 Dec 15, 2025
b44bea2
Delay stringification of const to backend
nbdd0121 Dec 18, 2025
ca40339
Unify handling of asm const and sym using CTFE
nbdd0121 Dec 18, 2025
4c39d62
Unify handling of `GlobalAlloc` inside backend
nbdd0121 Dec 19, 2025
338d560
Handle pointers with offset for asm const
nbdd0121 Dec 18, 2025
6deaed5
Support codegen of asm const pointers without provenance
nbdd0121 Dec 18, 2025
1fd34e4
Give codegen units symbol names that backend can use
nbdd0121 Jun 10, 2026
c95d35e
Generate unique symbol names if const pointers refer to promoted static
nbdd0121 Dec 19, 2025
5ed79ae
Implement asm_const_ptr feature
nbdd0121 Oct 24, 2024
0e139d3
Add test if asm const are MIR inlined and monomorphized twice
nbdd0121 Apr 22, 2026
6860c6b
Drop redundant canonical universe assumptions
Dnreikronos Jul 22, 2026
9ffb8f7
Expand invalid-const-operand test case to cover &str and &CStr
nbdd0121 Jul 22, 2026
b1342c9
constify vec![1, 2, 3] macro arm functions
Lars-Schumann Jul 22, 2026
f9d9939
make `DocLinkResMap` an `FxIndexMap`
jprochazk Jul 22, 2026
f468568
reflow
tshepang Jul 23, 2026
31f2f15
sembr src/debuginfo/lldb-internals.md
tshepang Jul 23, 2026
225b77c
reflow
tshepang Jul 23, 2026
7b10686
sembr src/debuginfo/debugger-visualizers.md
tshepang Jul 23, 2026
7000c2a
reflow
tshepang Jul 23, 2026
b0f5d97
sembr src/debuginfo/gdb-internals.md
tshepang Jul 23, 2026
ca59dd7
sembr src/debuginfo/llvm-codegen.md
tshepang Jul 23, 2026
1bb944b
Prepare for merging from rust-lang/rust
invalid-email-address Jul 23, 2026
2ebc7ef
Merge pull request #2940 from rust-lang/tshepang/misc
tshepang Jul 23, 2026
bd101bb
Merge ref '390279b302ca' from rust-lang/rust
invalid-email-address Jul 23, 2026
de87ba1
Merge pull request #2941 from rust-lang/rustc-pull
tshepang Jul 23, 2026
e9ad00c
Remove 'static requirement on try_as_dyn
oli-obk Dec 16, 2025
b111aec
Add helper trait that restricts lifetimes and extra predicates to ens…
oli-obk Jan 13, 2026
e948729
the fixme is outdated as we eagerly normalize outside of the trait so…
chenyukang Jul 23, 2026
5a367ee
Rollup merge of #138618 - nbdd0121:asm_const_ptr, r=bjorn3
jhpratt Jul 23, 2026
f9f3fee
Rollup merge of #150161 - oli-obk:try_as_dyn_non_static, r=BoxyUwU
jhpratt Jul 23, 2026
e3d7c62
Rollup merge of #158362 - Dnreikronos:trait_solver/placeholder_univer…
jhpratt Jul 23, 2026
7faf223
Rollup merge of #159173 - chenyukang:yukang-fix-159015-no-mangle-eii,…
jhpratt Jul 23, 2026
c7e7522
Rollup merge of #159466 - folkertdev:clear-variant-dependent-padding,…
jhpratt Jul 23, 2026
927ee60
Rollup merge of #159718 - jprochazk:doc-link-res-index-map, r=petroch…
jhpratt Jul 23, 2026
aeee548
Rollup merge of #155795 - Lars-Schumann:const-vec-macro, r=oli-obk
jhpratt Jul 23, 2026
a6c4abe
Rollup merge of #157776 - sgasho:linux_autodiff_tests_ci, r=ZuseZ4
jhpratt Jul 23, 2026
f5d810d
Rollup merge of #157905 - zachs18:randomize-layout-zst-note, r=davidtwco
jhpratt Jul 23, 2026
81e71aa
Rollup merge of #159041 - zedddie:gsoc-batch-22-meow, r=Kivooeo
jhpratt Jul 23, 2026
620b710
Rollup merge of #159108 - zedddie:gsoc-batch-23-meow, r=Kivooeo
jhpratt Jul 23, 2026
fed7ef7
Rollup merge of #159138 - kn1g78:doc-wasm-symbol-mangling, r=davidtwco
jhpratt Jul 23, 2026
9c6bdbb
Rollup merge of #159531 - zedddie:gsoc-batch-28-meow, r=Kivooeo
jhpratt Jul 23, 2026
dcb88f1
Rollup merge of #159608 - dianqk:hoist-in-early-else, r=davidtwco
jhpratt Jul 23, 2026
b6eaabf
Rollup merge of #159612 - zedddie:gsoc-batch-29-meow, r=Teapot4195
jhpratt Jul 23, 2026
4a74f06
Rollup merge of #159653 - folkertdev:aarch64_be-asm-types, r=davidtwco
jhpratt Jul 23, 2026
8977f85
Rollup merge of #159759 - tshepang:rdg-sync, r=tshepang
jhpratt Jul 23, 2026
2dad3cc
Rollup merge of #159761 - chenyukang:yukang-remove-outdated-comment-i…
jhpratt Jul 23, 2026
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
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4509,6 +4509,7 @@ dependencies = [
"rustc_middle",
"rustc_session",
"rustc_span",
"rustc_symbol_mangling",
"rustc_target",
"serde",
"serde_json",
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_abi/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,11 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
// If `-Z randomize-layout` was enabled for the type definition we can shuffle
// the field ordering to try and catch some code making assumptions about layouts
// we don't guarantee.
// In the future, we might do more than shuffle field order (e.g. introduce extra padding),
// but never for `repr(Rust)` structs with only zero-sized fields, single-variant
// `repr(Rust)` enums with only zero-sized fields, or zero-variant `repr(Rust)` enums,
// which must remain zero-sized as per T-lang decisions in
// https://github.com/rust-lang/reference/pull/2262 and https://github.com/rust-lang/reference/pull/2293
if repr.can_randomize_type_layout() && cfg!(feature = "randomize") {
#[cfg(feature = "randomize")]
{
Expand Down
123 changes: 93 additions & 30 deletions compiler/rustc_abi/src/layout/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,35 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
found
}

/// Whether this type/layout has any padding that is dependent on a variant, i.e. has bytes that
/// are padding for some, but not all, valid values of this type.
pub fn has_variant_dependent_padding<C>(&self, cx: &C) -> bool
where
Ty: TyAbiInterface<'a, C> + Copy,
{
match self.variants {
Variants::Multiple { .. } => true,
Variants::Empty => false,
Variants::Single { .. } => match &self.fields {
FieldsShape::Primitive | FieldsShape::Union(_) => false,
FieldsShape::Array { count, .. } => {
*count > 0 && self.field(cx, 0).has_variant_dependent_padding(cx)
}
FieldsShape::Arbitrary { offsets, .. } => {
(0..offsets.len()).any(|i| self.field(cx, i).has_variant_dependent_padding(cx))
}
},
}
}

/// The ranges of bytes that are always ignored by the representation relation of this type.
///
/// In other words, for any sequence of bytes, if we reset the these padding bytes to uninit,
/// then these two sequences of bytes represent the same value (or they are both invalid).
/// This is the "guaranteed" padding. There may be more bytes that are padding for some
/// but not all variants of this type; those are not included.
/// (E.g. `Option<i8>` has no guaranteed padding so the empty range set is returned, but its `None` value still has padding).
pub fn padding_ranges<C>(&self, cx: &C) -> Vec<Range<Size>>
pub fn variant_independent_padding_ranges<C>(&self, cx: &C) -> Vec<Range<Size>>
where
Ty: TyAbiInterface<'a, C> + Copy,
{
Expand All @@ -316,6 +337,45 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
uninit_ranges
}

/// The ranges of bytes that are ignored by the representation relation of this variant.
///
/// The result does not include variant-independent padding.
pub fn variant_dependent_padding_ranges<C>(
&self,
cx: &C,
variant_index: VariantIdx,
) -> Vec<Range<Size>>
where
Ty: TyAbiInterface<'a, C> + Copy,
{
let Variants::Multiple { .. } = self.variants else {
return Vec::new();
};

// Bytes that are data in some variant.
let mut any = RangeSet::new();
self.add_data_ranges(cx, Size::ZERO, &mut any);

// Bytes that are data in this variant.
let mut this = RangeSet::new();

// The variants do not contain e.g. the discriminant or coroutine upvars.
let FieldsShape::Arbitrary { offsets, in_memory_order: _ } = &self.fields else {
unreachable!("a multi-variant layout should have `Arbitrary` fields")
};

// So add them explicitly.
for (field, &offset) in offsets.iter_enumerated() {
let field = self.field(cx, field.as_usize());
field.add_data_ranges(cx, offset, &mut this);
}

self.for_variant(cx, variant_index).add_data_ranges(cx, Size::ZERO, &mut this);

// Padding specific to this variant: data in some variant, but not in this one.
any.difference(&this).0.iter().map(|&(offset, size)| offset..offset + size).collect()
}

/// Extend `out` with all ranges of bytes that *may* carry relevant data for values of this type.
/// For enums and unions there are offsets that are initialized for some
/// variants but not for others; those offset *will* get added to `out`.
Expand All @@ -327,39 +387,42 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
return;
}

match &self.variants {
Variants::Empty => { /* done */ }
Variants::Single { index: _ } => match &self.fields {
FieldsShape::Primitive => {
out.add_range(base_offset, self.size);
}
&FieldsShape::Union(field_count) => {
for field in 0..field_count.get() {
let field = self.field(cx, field);
field.add_data_ranges(cx, base_offset, out);
}
// Visit the fields of this value. For enum values the fields include the discriminant.
match &self.fields {
FieldsShape::Primitive => {
out.add_range(base_offset, self.size);
}
&FieldsShape::Union(field_count) => {
for field in 0..field_count.get() {
let field = self.field(cx, field);
field.add_data_ranges(cx, base_offset, out);
}
&FieldsShape::Array { stride, count } => {
let elem = self.field(cx, 0);

// For scalars we know there is no padding between the elements,
// so the entire array is a single big data range.
if elem.backend_repr.is_scalar() {
out.add_range(base_offset, elem.size * count);
} else {
// FIXME: this is really inefficient for large arrays.
for idx in 0..count {
elem.add_data_ranges(cx, base_offset + idx * stride, out);
}
}
&FieldsShape::Array { stride, count } => {
let elem = self.field(cx, 0);

// For scalars we know there is no padding between the elements,
// so the entire array is a single big data range.
if elem.backend_repr.is_scalar() {
out.add_range(base_offset, elem.size * count);
} else {
// FIXME: this is really inefficient for large arrays.
for idx in 0..count {
elem.add_data_ranges(cx, base_offset + idx * stride, out);
}
}
FieldsShape::Arbitrary { offsets, in_memory_order: _ } => {
for (field, &offset) in offsets.iter_enumerated() {
let field = self.field(cx, field.as_usize());
field.add_data_ranges(cx, base_offset + offset, out);
}
}
FieldsShape::Arbitrary { offsets, in_memory_order: _ } => {
for (field, &offset) in offsets.iter_enumerated() {
let field = self.field(cx, field.as_usize());
field.add_data_ranges(cx, base_offset + offset, out);
}
},
}
}

// Visit the fields of each variant.
match &self.variants {
Variants::Empty | Variants::Single { index: _ } => { /* done */ }
Variants::Multiple { variants, .. } => {
for variant in variants.indices() {
let variant = self.for_variant(cx, variant);
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ bitflags! {
/// If true, the type's crate has opted into layout randomization.
/// Other flags can still inhibit reordering and thus randomization.
/// The seed stored in `ReprOptions.field_shuffle_seed`.
///
/// `repr(Rust)` structs with only zero-sized fields, single-variant `repr(Rust)` enums with only
/// zero-sized fields, and zero-variant `repr(Rust)` enums must remain zero-sized as per
/// T-lang decisions in https://github.com/rust-lang/reference/pull/2262 and https://github.com/rust-lang/reference/pull/2293
const RANDOMIZE_LAYOUT = 1 << 4;
/// If true, the type is always passed indirectly by non-Rustic ABIs.
/// See [`TyAndLayout::pass_indirectly_in_non_rustic_abis`] for details.
Expand Down
46 changes: 45 additions & 1 deletion compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,48 @@ impl<'a> AstValidator<'a> {
self.visit_vis(vis);
self.visit_ident(ident);
}

// Check EII implementation attributes against an allowlist.
fn check_eii_impl_attrs(&self, attrs: &[Attribute], eii_impls: &[EiiImpl]) {
if eii_impls.is_empty() {
return;
}

let allowed_attrs: &[Symbol] = &[
sym::allow,
sym::warn,
sym::deny,
sym::forbid,
sym::expect,
sym::doc,
sym::inline,
sym::cold,
sym::optimize,
sym::coverage,
sym::sanitize,
sym::must_use,
sym::deprecated,
];

for attr in attrs {
let AttrKind::Normal(normal) = &attr.kind else {
continue;
};
if attr.has_any_name(allowed_attrs) {
continue;
}

let attr_name = pprust::path_to_string(&normal.item.path);
for eii_impl in eii_impls {
self.dcx().emit_err(diagnostics::EiiImplAttributeNotSupported {
attr_span: attr.span,
attr_name: &attr_name,
eii_span: eii_impl.span,
eii_name: pprust::path_to_string(&eii_impl.eii_macro_path),
});
}
}
}
}

/// Checks that generic parameters are in the correct order,
Expand Down Expand Up @@ -1391,6 +1433,7 @@ impl Visitor<'_> for AstValidator<'_> {
for EiiImpl { eii_macro_path, .. } in eii_impls {
self.visit_path(eii_macro_path);
}
self.check_eii_impl_attrs(&item.attrs, eii_impls);

let is_intrinsic = item.attrs.iter().any(|a| a.has_name(sym::rustc_intrinsic));
if body.is_none() && !is_intrinsic && !self.is_sdylib_interface {
Expand Down Expand Up @@ -1566,8 +1609,9 @@ impl Visitor<'_> for AstValidator<'_> {

visit::walk_item(self, item);
}
ItemKind::Static(StaticItem { expr, safety, .. }) => {
ItemKind::Static(StaticItem { expr, safety, eii_impls, .. }) => {
self.check_item_safety(item.span, *safety);
self.check_eii_impl_attrs(&item.attrs, eii_impls);
if matches!(safety, Safety::Unsafe(_)) {
self.dcx().emit_err(diagnostics::UnsafeStatic { span: item.span });
}
Expand Down
11 changes: 11 additions & 0 deletions compiler/rustc_ast_passes/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,17 @@ pub(crate) struct FnParamForbiddenAttr {
pub span: Span,
}

#[derive(Diagnostic)]
#[diag("`#[{$eii_name}]` is not allowed to have `#[{$attr_name}]`")]
pub(crate) struct EiiImplAttributeNotSupported<'a> {
#[primary_span]
pub attr_span: Span,
pub attr_name: &'a str,
pub eii_name: String,
#[label("`#[{$eii_name}]` is not allowed to have `#[{$attr_name}]`")]
pub eii_span: Span,
}

#[derive(Diagnostic)]
#[diag("`self` parameter is only allowed in associated functions")]
#[note("associated functions are those in `impl` or `trait` definitions")]
Expand Down
70 changes: 50 additions & 20 deletions compiler/rustc_codegen_cranelift/src/global_asm.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
//! The AOT driver uses [`cranelift_object`] to write object files suitable for linking into a
//! standalone executable.

use std::fmt::Write as _;
use std::io::Write;
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};

use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
use rustc_codegen_ssa::traits::{AsmCodegenMethods, GlobalAsmOperandRef};
use rustc_middle::mir::interpret::{GlobalAlloc, PointerArithmetic, Scalar as ConstScalar};
use rustc_middle::ty::TyCtxt;
use rustc_middle::ty::layout::{
FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasTyCtxt, HasTypingEnv, LayoutError, LayoutOfHelpers,
Expand Down Expand Up @@ -107,29 +109,57 @@ fn codegen_global_asm_inner<'tcx>(
InlineAsmTemplatePiece::Placeholder { operand_idx, modifier: _, span } => {
use rustc_codegen_ssa::back::symbol_export::escape_symbol_name;
match operands[operand_idx] {
GlobalAsmOperandRef::Const { ref string } => {
global_asm.push_str(string);
}
GlobalAsmOperandRef::SymFn { instance } => {
if cfg!(not(feature = "inline_asm_sym")) {
tcx.dcx().span_err(
span,
"asm! and global_asm! sym operands are not yet supported",
);
}
GlobalAsmOperandRef::Const { value, ty } => {
match value {
ConstScalar::Int(int) => {
let string = rustc_codegen_ssa::common::asm_const_to_str(
tcx,
span,
int,
FullyMonomorphizedLayoutCx(tcx).layout_of(ty),
);
global_asm.push_str(&string);
}

let symbol = tcx.symbol_name(instance);
let symbol_name = if tcx.sess.target.is_like_darwin {
format!("_{}", symbol.name)
} else {
symbol.name.to_owned()
};
ConstScalar::Ptr(ptr, _) => {
if cfg!(not(feature = "inline_asm_sym")) {
tcx.dcx().span_err(
span,
"asm! and global_asm! sym operands are not yet supported",
);
}

// FIXME handle the case where the function was made private to the
// current codegen unit
global_asm.push_str(&escape_symbol_name(tcx, &symbol_name, span));
let (prov, offset) = ptr.prov_and_relative_offset();
let global_alloc = tcx.global_alloc(prov.alloc_id());
let symbol = match global_alloc {
GlobalAlloc::Function { instance } => {
// FIXME handle the case where the function was made private to the
// current codegen unit
tcx.symbol_name(instance)
}
GlobalAlloc::Static(def_id) => {
let instance = Instance::mono(tcx, def_id);
tcx.symbol_name(instance)
}
GlobalAlloc::Memory(_)
| GlobalAlloc::VTable(..)
| GlobalAlloc::TypeId { .. } => unreachable!(),
};
let symbol_name = if tcx.sess.target.is_like_darwin {
format!("_{}", symbol.name)
} else {
symbol.name.to_owned()
};
global_asm.push_str(&escape_symbol_name(tcx, &symbol_name, span));

if offset != Size::ZERO {
let offset = tcx.sign_extend_to_target_isize(offset.bytes());
write!(global_asm, "{offset:+}").unwrap();
}
}
}
}
GlobalAsmOperandRef::SymStatic { def_id } => {
GlobalAsmOperandRef::SymThreadLocalStatic { def_id } => {
if cfg!(not(feature = "inline_asm_sym")) {
tcx.dcx().span_err(
span,
Expand Down
10 changes: 9 additions & 1 deletion compiler/rustc_codegen_cranelift/src/inline_asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,18 @@ pub(crate) fn codegen_inline_asm_terminator<'tcx>(
}
InlineAsmOperand::Const { ref value } => {
let (const_value, ty) = crate::constant::eval_mir_constant(fx, value);
let mir::ConstValue::Scalar(scalar) = const_value else {
span_bug!(
span,
"expected Scalar for promoted asm const, but got {:#?}",
const_value
)
};

let value = rustc_codegen_ssa::common::asm_const_to_str(
fx.tcx,
span,
const_value,
scalar.assert_scalar_int(),
fx.layout_of(ty),
);
CInlineAsmOperand::Const { value }
Expand Down
Loading
Loading