File tree 3 files changed +52
-6
lines changed
compiler/rustc_mir_build/src/thir/cx
3 files changed +52
-6
lines changed Original file line number Diff line number Diff line change @@ -624,12 +624,15 @@ impl<'tcx> Cx<'tcx> {
624
624
}
625
625
}
626
626
hir:: InlineAsmOperand :: Const { ref anon_const } => {
627
- let value = mir:: Const :: identity_unevaluated (
628
- tcx,
629
- anon_const. def_id . to_def_id ( ) ,
630
- )
631
- . instantiate_identity ( )
632
- . normalize ( tcx, self . param_env ) ;
627
+ let def_id = anon_const. def_id . to_def_id ( ) ;
628
+ let const_type = tcx. type_of ( def_id) . skip_binder ( ) ;
629
+ let value = if let ty:: Error ( terr) = const_type. kind ( ) {
630
+ mir:: Const :: Ty ( const_type, ty:: Const :: new_error ( tcx, * terr) )
631
+ } else {
632
+ mir:: Const :: identity_unevaluated ( tcx, def_id)
633
+ . instantiate_identity ( )
634
+ . normalize ( tcx, self . param_env )
635
+ } ;
633
636
let span = tcx. def_span ( anon_const. def_id ) ;
634
637
635
638
InlineAsmOperand :: Const { value, span }
Original file line number Diff line number Diff line change
1
+ //@ needs-asm-support
2
+ //@ ignore-nvptx64
3
+ //@ ignore-spirv
4
+
5
+ #![ feature( const_refs_to_static) ]
6
+
7
+ use std:: arch:: { asm, global_asm} ;
8
+ use std:: ptr:: addr_of;
9
+
10
+ static FOO : u8 = 42 ;
11
+
12
+ global_asm ! ( "{}" , const addr_of!( FOO ) ) ;
13
+ //~^ ERROR invalid type for `const` operand
14
+
15
+ #[ no_mangle]
16
+ fn inline ( ) {
17
+ unsafe { asm ! ( "{}" , const addr_of!( FOO ) ) } ;
18
+ //~^ ERROR invalid type for `const` operand
19
+ }
20
+
21
+ fn main ( ) { }
Original file line number Diff line number Diff line change
1
+ error: invalid type for `const` operand
2
+ --> $DIR/const-refs-to-static.rs:12:19
3
+ |
4
+ LL | global_asm!("{}", const addr_of!(FOO));
5
+ | ^^^^^^-------------
6
+ | |
7
+ | is a `*const u8`
8
+ |
9
+ = help: `const` operands must be of an integer type
10
+
11
+ error: invalid type for `const` operand
12
+ --> $DIR/const-refs-to-static.rs:17:25
13
+ |
14
+ LL | unsafe { asm!("{}", const addr_of!(FOO)) };
15
+ | ^^^^^^-------------
16
+ | |
17
+ | is a `*const u8`
18
+ |
19
+ = help: `const` operands must be of an integer type
20
+
21
+ error: aborting due to 2 previous errors
22
+
You can’t perform that action at this time.
0 commit comments