diff options
| author | bjorn3 <17426603+bjorn3@users.noreply.github.com> | 2024-03-28 11:43:35 +0000 |
|---|---|---|
| committer | bjorn3 <17426603+bjorn3@users.noreply.github.com> | 2024-03-28 11:43:35 +0000 |
| commit | 987ed345af4af535f271dea5bdfe8647dcaf44ec (patch) | |
| tree | 0d63c4050ea389378aadbbb222fdae61213498d6 /compiler/rustc_codegen_cranelift/src/global_asm.rs | |
| parent | d0e8cbbd99ccc1be12b1aa743521ed89268e59a2 (diff) | |
| parent | 09fae60a86b848a2fc0ad219ecc4e438dc1eef86 (diff) | |
| download | rust-987ed345af4af535f271dea5bdfe8647dcaf44ec.tar.gz rust-987ed345af4af535f271dea5bdfe8647dcaf44ec.zip | |
Merge commit '09fae60a86b848a2fc0ad219ecc4e438dc1eef86' into sync_cg_clif-2024-03-28
Diffstat (limited to 'compiler/rustc_codegen_cranelift/src/global_asm.rs')
| -rw-r--r-- | compiler/rustc_codegen_cranelift/src/global_asm.rs | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/compiler/rustc_codegen_cranelift/src/global_asm.rs b/compiler/rustc_codegen_cranelift/src/global_asm.rs index 44650898de8..5a0cd3990f2 100644 --- a/compiler/rustc_codegen_cranelift/src/global_asm.rs +++ b/compiler/rustc_codegen_cranelift/src/global_asm.rs @@ -8,6 +8,7 @@ use std::sync::Arc; use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece}; use rustc_hir::{InlineAsmOperand, ItemId}; +use rustc_middle::mir::interpret::ErrorHandled; use rustc_session::config::{OutputFilenames, OutputType}; use rustc_target::asm::InlineAsmArch; @@ -32,18 +33,27 @@ pub(crate) fn codegen_global_asm_item(tcx: TyCtxt<'_>, global_asm: &mut String, InlineAsmTemplatePiece::Placeholder { operand_idx, modifier: _, span: op_sp } => { match asm.operands[operand_idx].0 { InlineAsmOperand::Const { ref anon_const } => { - let const_value = - tcx.const_eval_poly(anon_const.def_id.to_def_id()).unwrap_or_else( - |_| span_bug!(op_sp, "asm const cannot be resolved"), - ); - let ty = tcx.typeck_body(anon_const.body).node_type(anon_const.hir_id); - let string = rustc_codegen_ssa::common::asm_const_to_str( - tcx, - op_sp, - const_value, - RevealAllLayoutCx(tcx).layout_of(ty), - ); - global_asm.push_str(&string); + match tcx.const_eval_poly(anon_const.def_id.to_def_id()) { + Ok(const_value) => { + let ty = tcx + .typeck_body(anon_const.body) + .node_type(anon_const.hir_id); + let string = rustc_codegen_ssa::common::asm_const_to_str( + tcx, + op_sp, + const_value, + RevealAllLayoutCx(tcx).layout_of(ty), + ); + global_asm.push_str(&string); + } + Err(ErrorHandled::Reported { .. }) => { + // An error has already been reported and compilation is + // guaranteed to fail if execution hits this path. + } + Err(ErrorHandled::TooGeneric(_)) => { + span_bug!(op_sp, "asm const cannot be resolved; too generic"); + } + } } InlineAsmOperand::SymFn { anon_const } => { if cfg!(not(feature = "inline_asm_sym")) { |
