about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-08-20 14:15:50 +0000
committerbors <bors@rust-lang.org>2024-08-20 14:15:50 +0000
commit4d5b3b196284aded6ae99d12bcf149ffdc8ef379 (patch)
tree6da9e130fa9191ca8919b7f6f4cc3fb9c96ee718
parenta971212545766fdfe0dd68e5d968133f79944a19 (diff)
parent4508800d20006375fbd0b8f5b5fd41a6ad8d7ae4 (diff)
downloadrust-4d5b3b196284aded6ae99d12bcf149ffdc8ef379.tar.gz
rust-4d5b3b196284aded6ae99d12bcf149ffdc8ef379.zip
Auto merge of #129239 - DianQK:codegen-rustc_intrinsic, r=saethlin
Don't generate functions with the `rustc_intrinsic_must_be_overridden` attribute

Functions with the attribute `rustc_intrinsic_must_be_overridden` never be called.

r? compiler
-rw-r--r--compiler/rustc_monomorphize/src/collector.rs4
-rw-r--r--tests/codegen/intrinsics/rustc_intrinsic_must_be_overridden.rs14
2 files changed, 17 insertions, 1 deletions
diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs
index 0ae635f9b73..9f449868f03 100644
--- a/compiler/rustc_monomorphize/src/collector.rs
+++ b/compiler/rustc_monomorphize/src/collector.rs
@@ -888,7 +888,9 @@ fn visit_instance_use<'tcx>(
             if tcx.should_codegen_locally(panic_instance) {
                 output.push(create_fn_mono_item(tcx, panic_instance, source));
             }
-        } else if tcx.has_attr(def_id, sym::rustc_intrinsic) {
+        } else if tcx.has_attr(def_id, sym::rustc_intrinsic)
+            && !tcx.has_attr(def_id, sym::rustc_intrinsic_must_be_overridden)
+        {
             // Codegen the fallback body of intrinsics with fallback bodies
             let instance = ty::Instance::new(def_id, instance.args);
             if tcx.should_codegen_locally(instance) {
diff --git a/tests/codegen/intrinsics/rustc_intrinsic_must_be_overridden.rs b/tests/codegen/intrinsics/rustc_intrinsic_must_be_overridden.rs
new file mode 100644
index 00000000000..b41e441d309
--- /dev/null
+++ b/tests/codegen/intrinsics/rustc_intrinsic_must_be_overridden.rs
@@ -0,0 +1,14 @@
+//@ revisions: OPT0 OPT1
+//@ [OPT0] compile-flags: -Copt-level=0
+//@ [OPT1] compile-flags: -Copt-level=1
+//@ compile-flags: -Cno-prepopulate-passes
+
+#![crate_type = "lib"]
+#![feature(core_intrinsics)]
+
+// CHECK-NOT: core::intrinsics::size_of_val
+
+#[no_mangle]
+pub unsafe fn size_of_val(ptr: *const i32) -> usize {
+    core::intrinsics::size_of_val(ptr)
+}