Skip to content

Commit f449f71

Browse files
committed
fix ICE when asm_const and const_refs_to_static are combined
1 parent b5723af commit f449f71

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,14 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
385385
} else if let Some(static_def_id) = constant.check_static_ptr(tcx) {
386386
let unnormalized_ty = tcx.type_of(static_def_id).instantiate_identity();
387387
let normalized_ty = self.cx.normalize(unnormalized_ty, locations);
388-
let literal_ty = constant.const_.ty().builtin_deref(true).unwrap();
388+
let literal_ty = constant.const_.ty().builtin_deref(true).unwrap_or_else(|| {
389+
span_mirbug_and_err!(
390+
self,
391+
constant,
392+
"bad static type {:?}",
393+
constant.const_.ty()
394+
)
395+
});
389396

390397
if let Err(terr) = self.cx.eq_types(
391398
literal_ty,

tests/ui/asm/const-refs-to-static.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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() {}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+

0 commit comments

Comments
 (0)