Skip to content

Commit

Permalink
fix ICE when asm_const and const_refs_to_static are combined
Browse files Browse the repository at this point in the history
  • Loading branch information
folkertdev committed Aug 23, 2024
1 parent b5723af commit f449f71
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
9 changes: 8 additions & 1 deletion compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,14 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
} else if let Some(static_def_id) = constant.check_static_ptr(tcx) {
let unnormalized_ty = tcx.type_of(static_def_id).instantiate_identity();
let normalized_ty = self.cx.normalize(unnormalized_ty, locations);
let literal_ty = constant.const_.ty().builtin_deref(true).unwrap();
let literal_ty = constant.const_.ty().builtin_deref(true).unwrap_or_else(|| {
span_mirbug_and_err!(
self,
constant,
"bad static type {:?}",
constant.const_.ty()
)
});

if let Err(terr) = self.cx.eq_types(
literal_ty,
Expand Down
21 changes: 21 additions & 0 deletions tests/ui/asm/const-refs-to-static.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//@ needs-asm-support
//@ ignore-nvptx64
//@ ignore-spirv

#![feature(const_refs_to_static)]

use std::arch::{asm, global_asm};
use std::ptr::addr_of;

static FOO: u8 = 42;

global_asm!("{}", const addr_of!(FOO));
//~^ ERROR invalid type for `const` operand

#[no_mangle]
fn inline() {
unsafe { asm!("{}", const addr_of!(FOO)) };
//~^ ERROR invalid type for `const` operand
}

fn main() {}
22 changes: 22 additions & 0 deletions tests/ui/asm/const-refs-to-static.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
error: invalid type for `const` operand
--> $DIR/const-refs-to-static.rs:12:19
|
LL | global_asm!("{}", const addr_of!(FOO));
| ^^^^^^-------------
| |
| is a `*const u8`
|
= help: `const` operands must be of an integer type

error: invalid type for `const` operand
--> $DIR/const-refs-to-static.rs:17:25
|
LL | unsafe { asm!("{}", const addr_of!(FOO)) };
| ^^^^^^-------------
| |
| is a `*const u8`
|
= help: `const` operands must be of an integer type

error: aborting due to 2 previous errors

0 comments on commit f449f71

Please sign in to comment.