@@ -8,6 +8,7 @@ use std::sync::Arc;
88
99use rustc_ast:: { InlineAsmOptions , InlineAsmTemplatePiece } ;
1010use rustc_hir:: { InlineAsmOperand , ItemId } ;
11+ use rustc_middle:: mir:: interpret:: ErrorHandled ;
1112use rustc_session:: config:: { OutputFilenames , OutputType } ;
1213use rustc_target:: asm:: InlineAsmArch ;
1314
@@ -32,18 +33,27 @@ pub(crate) fn codegen_global_asm_item(tcx: TyCtxt<'_>, global_asm: &mut String,
3233 InlineAsmTemplatePiece :: Placeholder { operand_idx, modifier : _, span : op_sp } => {
3334 match asm. operands [ operand_idx] . 0 {
3435 InlineAsmOperand :: Const { ref anon_const } => {
35- let const_value =
36- tcx. const_eval_poly ( anon_const. def_id . to_def_id ( ) ) . unwrap_or_else (
37- |_| span_bug ! ( op_sp, "asm const cannot be resolved" ) ,
38- ) ;
39- let ty = tcx. typeck_body ( anon_const. body ) . node_type ( anon_const. hir_id ) ;
40- let string = rustc_codegen_ssa:: common:: asm_const_to_str (
41- tcx,
42- op_sp,
43- const_value,
44- RevealAllLayoutCx ( tcx) . layout_of ( ty) ,
45- ) ;
46- global_asm. push_str ( & string) ;
36+ match tcx. const_eval_poly ( anon_const. def_id . to_def_id ( ) ) {
37+ Ok ( const_value) => {
38+ let ty = tcx
39+ . typeck_body ( anon_const. body )
40+ . node_type ( anon_const. hir_id ) ;
41+ let string = rustc_codegen_ssa:: common:: asm_const_to_str (
42+ tcx,
43+ op_sp,
44+ const_value,
45+ RevealAllLayoutCx ( tcx) . layout_of ( ty) ,
46+ ) ;
47+ global_asm. push_str ( & string) ;
48+ }
49+ Err ( ErrorHandled :: Reported { .. } ) => {
50+ // An error has already been reported and compilation is
51+ // guaranteed to fail if execution hits this path.
52+ }
53+ Err ( ErrorHandled :: TooGeneric ( _) ) => {
54+ span_bug ! ( op_sp, "asm const cannot be resolved; too generic" ) ;
55+ }
56+ }
4757 }
4858 InlineAsmOperand :: SymFn { anon_const } => {
4959 if cfg ! ( not( feature = "inline_asm_sym" ) ) {
0 commit comments