Skip to content

Commit 39f7707

Browse files
compiler: comment on some call-related codegen fn in cg_ssa
Partially documents the situation due to LLVM CFI.
1 parent 04bb68a commit 39f7707

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

compiler/rustc_codegen_ssa/src/traits/builder.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,12 +555,33 @@ pub trait BuilderMethods<'a, 'tcx>:
555555
/// Called for `StorageDead`
556556
fn lifetime_end(&mut self, ptr: Self::Value, size: Size);
557557

558+
/// "Finally codegen the call"
559+
///
560+
/// ## Arguments
561+
///
562+
/// The `fn_attrs`, `fn_abi`, and `instance` arguments are Options because they are advisory.
563+
/// They relate to optional codegen enhancements like LLVM CFI, and do not affect ABI per se.
564+
/// Any ABI-related transformations should be handled by different, earlier stages of codegen.
565+
/// For instance, in the caller of `BuilderMethods::call`.
566+
///
567+
/// This means that a codegen backend which disregards `fn_attrs`, `fn_abi`, and `instance`
568+
/// should still do correct codegen, and code should not be miscompiled if they are omitted.
569+
/// It is not a miscompilation in this sense if it fails to run under CFI, other sanitizers, or
570+
/// in the context of other compiler-enhanced security features.
571+
///
572+
/// The typical case that they are None is during the codegen of intrinsics and lang-items,
573+
/// as those are "fake functions" with only a trivial ABI if any, et cetera.
574+
///
575+
/// ## Return
576+
///
577+
/// Must return the value the function will return so it can be written to the destination,
578+
/// assuming the function does not explicitly pass the destination as a pointer in `args`.
558579
fn call(
559580
&mut self,
560581
llty: Self::Type,
561582
fn_attrs: Option<&CodegenFnAttrs>,
562583
fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>,
563-
llfn: Self::Value,
584+
fn_val: Self::Value,
564585
args: &[Self::Value],
565586
funclet: Option<&Self::Funclet>,
566587
instance: Option<Instance<'tcx>>,

compiler/rustc_codegen_ssa/src/traits/intrinsic.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,22 @@ use crate::mir::operand::OperandRef;
66
use crate::mir::place::PlaceRef;
77

88
pub trait IntrinsicCallBuilderMethods<'tcx>: BackendTypes {
9+
/// Higher-level interface to emitting calls to intrinsics
10+
///
911
/// Remember to add all intrinsics here, in `compiler/rustc_hir_analysis/src/check/mod.rs`,
1012
/// and in `library/core/src/intrinsics.rs`; if you need access to any LLVM intrinsics,
1113
/// add them to `compiler/rustc_codegen_llvm/src/context.rs`.
1214
/// Returns `Err` if another instance should be called instead. This is used to invoke
1315
/// intrinsic default bodies in case an intrinsic is not implemented by the backend.
16+
///
17+
/// NOTE: allowed to call [`BuilderMethods::call`]
18+
///
19+
/// [`BuilderMethods::call`]: super::builder::BuilderMethods::call
1420
fn codegen_intrinsic_call(
1521
&mut self,
1622
instance: ty::Instance<'tcx>,
1723
args: &[OperandRef<'tcx, Self::Value>],
18-
result: PlaceRef<'tcx, Self::Value>,
24+
result_dest: PlaceRef<'tcx, Self::Value>,
1925
span: Span,
2026
) -> Result<(), ty::Instance<'tcx>>;
2127

0 commit comments

Comments
 (0)