Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 9e27a00

Browse files
committed
Add comment
1 parent 6c6a39e commit 9e27a00

File tree

1 file changed

+8
-0
lines changed
  • library/core/src/fmt

1 file changed

+8
-0
lines changed

library/core/src/fmt/rt.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ macro_rules! argument_new {
7272
// a `fn(&T, ...)`, so the invariant is maintained.
7373
ty: ArgumentType::Placeholder {
7474
value: NonNull::<$t>::from_ref($x).cast(),
75+
// The Rust ABI considers all pointers to be equivalent, so transmuting a fn(&T) to
76+
// fn(NonNull<()>) and calling it with a NonNull<()> that points at a T is allowed.
77+
// However, the CFI sanitizer does not allow this, and triggers a crash when it
78+
// happens.
79+
//
80+
// To avoid this crash, we use a helper function when CFI is enabled. To avoid the
81+
// cost of this helper function (mainly code-size) when it is not needed, we
82+
// transmute the function pointer otherwise.
7583
#[cfg(not(any(sanitize = "cfi", sanitize = "kcfi")))]
7684
formatter: {
7785
let f: fn(&$t, &mut Formatter<'_>) -> Result = $f;

0 commit comments

Comments
 (0)