Skip to content

Commit

Permalink
Auto merge of #129239 - DianQK:codegen-rustc_intrinsic, r=saethlin
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Aug 20, 2024
2 parents a971212 + 4508800 commit 4d5b3b1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion compiler/rustc_monomorphize/src/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
14 changes: 14 additions & 0 deletions tests/codegen/intrinsics/rustc_intrinsic_must_be_overridden.rs
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 4d5b3b1

Please sign in to comment.