@@ -8,6 +8,7 @@ use std::sync::Arc;
8
8
9
9
use rustc_ast:: { InlineAsmOptions , InlineAsmTemplatePiece } ;
10
10
use rustc_hir:: { InlineAsmOperand , ItemId } ;
11
+ use rustc_middle:: mir:: interpret:: ErrorHandled ;
11
12
use rustc_session:: config:: { OutputFilenames , OutputType } ;
12
13
use rustc_target:: asm:: InlineAsmArch ;
13
14
@@ -32,18 +33,27 @@ pub(crate) fn codegen_global_asm_item(tcx: TyCtxt<'_>, global_asm: &mut String,
32
33
InlineAsmTemplatePiece :: Placeholder { operand_idx, modifier : _, span : op_sp } => {
33
34
match asm. operands [ operand_idx] . 0 {
34
35
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
+ }
47
57
}
48
58
InlineAsmOperand :: SymFn { anon_const } => {
49
59
if cfg ! ( not( feature = "inline_asm_sym" ) ) {
0 commit comments