about summary refs log tree commit diff
path: root/compiler/rustc_middle/src
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-04-08 22:06:24 +0200
committerGitHub <noreply@github.com>2024-04-08 22:06:24 +0200
commit0520200a9c739da59e399350e618e16c25ab5ab4 (patch)
treef1b8c1a189ef1a03636cc8bf684582d7bc5adbf4 /compiler/rustc_middle/src
parentc0ac5d84a06af703d524ba84565aedf840498d22 (diff)
parent284da5d6b44ffaf22db50f4c30f5d941a471b26c (diff)
downloadrust-0520200a9c739da59e399350e618e16c25ab5ab4.tar.gz
rust-0520200a9c739da59e399350e618e16c25ab5ab4.zip
Rollup merge of #123635 - maurer:kcfi-no-assoc, r=compiler-errors
CFI: Fix ICE in KCFI non-associated function pointers

We oddly weren't testing the more usual case of casting non-methods to function pointers. The KCFI shim insertion logic would ICE on these due to asking for an irrefutable associated item if we cast a function to a function pointer without needing a traditional shim.

r? `@compiler-errors`
Diffstat (limited to 'compiler/rustc_middle/src')
-rw-r--r--compiler/rustc_middle/src/ty/instance.rs5
1 files changed, 4 insertions, 1 deletions
diff --git a/compiler/rustc_middle/src/ty/instance.rs b/compiler/rustc_middle/src/ty/instance.rs
index 4a7720b38f8..f8f59fbeab4 100644
--- a/compiler/rustc_middle/src/ty/instance.rs
+++ b/compiler/rustc_middle/src/ty/instance.rs
@@ -520,7 +520,10 @@ impl<'tcx> Instance<'tcx> {
                 // Reify `Trait::method` implementations if KCFI is enabled
                 // FIXME(maurer) only reify it if it is a vtable-safe function
                 _ if tcx.sess.is_sanitizer_kcfi_enabled()
-                    && tcx.associated_item(def_id).trait_item_def_id.is_some() =>
+                    && tcx
+                        .opt_associated_item(def_id)
+                        .and_then(|assoc| assoc.trait_item_def_id)
+                        .is_some() =>
                 {
                     // If this function could also go in a vtable, we need to `ReifyShim` it with
                     // KCFI because it can only attach one type per function.