diff options
| author | Michael Goulet <michael@errs.io> | 2025-02-24 16:12:43 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2025-02-24 16:20:35 +0000 |
| commit | 04c00585c36e6e74dbe998d7c3b190955f757469 (patch) | |
| tree | 0a16e402709a5e959cec4dd8d37e14131beb7eda | |
| parent | bb029a1d3f819471722f32dd9fcfa2c83d4f24f4 (diff) | |
| download | rust-04c00585c36e6e74dbe998d7c3b190955f757469.tar.gz rust-04c00585c36e6e74dbe998d7c3b190955f757469.zip | |
Properly support thin ptrs that are only thin due to their param-env in asm macro
| -rw-r--r-- | compiler/rustc_hir_analysis/src/check/intrinsicck.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs | 3 | ||||
| -rw-r--r-- | tests/ui/asm/conditionally-sized-ptr.rs | 12 |
3 files changed, 16 insertions, 5 deletions
diff --git a/compiler/rustc_hir_analysis/src/check/intrinsicck.rs b/compiler/rustc_hir_analysis/src/check/intrinsicck.rs index e1727fc48a8..d62fa48bae3 100644 --- a/compiler/rustc_hir_analysis/src/check/intrinsicck.rs +++ b/compiler/rustc_hir_analysis/src/check/intrinsicck.rs @@ -33,14 +33,12 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> { pub fn new( tcx: TyCtxt<'tcx>, def_id: LocalDefId, + typing_env: ty::TypingEnv<'tcx>, get_operand_ty: impl Fn(&hir::Expr<'tcx>) -> Ty<'tcx> + 'a, ) -> Self { InlineAsmCtxt { tcx, - typing_env: ty::TypingEnv { - typing_mode: ty::TypingMode::non_body_analysis(), - param_env: ty::ParamEnv::empty(), - }, + typing_env, target_features: tcx.asm_target_features(def_id), expr_ty: Box::new(get_operand_ty), } diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index edd740d8d8f..63c1c060827 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -110,7 +110,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.tcx.erase_regions(ty) } }; - InlineAsmCtxt::new(self.tcx, enclosing_id, expr_ty).check_asm(asm); + InlineAsmCtxt::new(self.tcx, enclosing_id, self.typing_env(self.param_env), expr_ty) + .check_asm(asm); } } diff --git a/tests/ui/asm/conditionally-sized-ptr.rs b/tests/ui/asm/conditionally-sized-ptr.rs new file mode 100644 index 00000000000..8ff18fd1da1 --- /dev/null +++ b/tests/ui/asm/conditionally-sized-ptr.rs @@ -0,0 +1,12 @@ +//@ check-pass +//@ needs-asm-support + +use std::arch::asm; + +fn _f<T>(p: *mut T) { + unsafe { + asm!("/* {} */", in(reg) p); + } +} + +fn main() {} |
