Skip to content

Commit

Permalink
Auto merge of #129239 - DianQK:codegen-rustc_intrinsic, r=<try>
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? `@ghost`
  • Loading branch information
bors committed Aug 18, 2024
2 parents 334e509 + f083be2 commit 438c84c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions compiler/rustc_monomorphize/src/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,11 @@ fn should_codegen_locally<'tcx>(tcx: TyCtxtAt<'tcx>, instance: Instance<'tcx>) -
return false;
}

if tcx.has_attr(instance.def_id(), sym::rustc_intrinsic_must_be_overridden) {
// Functions with the attribute `rustc_intrinsic_must_be_overridden` never be called.
return false;
}

if !tcx.is_mir_available(def_id) {
tcx.dcx().emit_fatal(NoOptimizedMir {
span: tcx.def_span(def_id),
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 438c84c

Please sign in to comment.