about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlice Ryhl <aliceryhl@google.com>2025-04-12 10:49:39 +0000
committerAlice Ryhl <aliceryhl@google.com>2025-04-12 11:18:19 +0000
commit6c6a39e6bfd10bccbf6ca99479655a9ef8d87b39 (patch)
tree6ba8f677438df85acca6ff61d3803d47ff573d64
parent17d412439ad883bc52730cad194088246d557752 (diff)
downloadrust-6c6a39e6bfd10bccbf6ca99479655a9ef8d87b39.tar.gz
rust-6c6a39e6bfd10bccbf6ca99479655a9ef8d87b39.zip
cfg(kcfi)
-rw-r--r--library/core/src/fmt/mod.rs2
-rw-r--r--library/core/src/fmt/rt.rs7
-rw-r--r--tests/coverage/closure.cov-map18
3 files changed, 18 insertions, 9 deletions
diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs
index 580f95eddce..7ca390941bc 100644
--- a/library/core/src/fmt/mod.rs
+++ b/library/core/src/fmt/mod.rs
@@ -7,7 +7,7 @@ use crate::char::{EscapeDebugExtArgs, MAX_LEN_UTF8};
 use crate::marker::PhantomData;
 use crate::num::fmt as numfmt;
 use crate::ops::Deref;
-use crate::{iter, result, str};
+use crate::{iter, mem, result, str};
 
 mod builders;
 #[cfg(not(no_fp_fmt_parse))]
diff --git a/library/core/src/fmt/rt.rs b/library/core/src/fmt/rt.rs
index 702aa7e3436..c36feff0b62 100644
--- a/library/core/src/fmt/rt.rs
+++ b/library/core/src/fmt/rt.rs
@@ -72,6 +72,13 @@ macro_rules! argument_new {
             // a `fn(&T, ...)`, so the invariant is maintained.
             ty: ArgumentType::Placeholder {
                 value: NonNull::<$t>::from_ref($x).cast(),
+                #[cfg(not(any(sanitize = "cfi", sanitize = "kcfi")))]
+                formatter: {
+                    let f: fn(&$t, &mut Formatter<'_>) -> Result = $f;
+                    // SAFETY: This is only called with `value`, which has the right type.
+                    unsafe { mem::transmute(f) }
+                },
+                #[cfg(any(sanitize = "cfi", sanitize = "kcfi"))]
                 formatter: |ptr: NonNull<()>, fmt: &mut Formatter<'_>| {
                     let func = $f;
                     // SAFETY: This is the same type as the `value` field.
diff --git a/tests/coverage/closure.cov-map b/tests/coverage/closure.cov-map
index 640f9895684..2d784ba09b6 100644
--- a/tests/coverage/closure.cov-map
+++ b/tests/coverage/closure.cov-map
@@ -140,17 +140,19 @@ Number of file 0 mappings: 6
 - Code(Counter(0)) at (prev + 2, 9) to (start + 0, 10)
 Highest counter ID seen: c1
 
-Function name: closure::main::{closure#18} (unused)
-Raw bytes (24): 0x[01, 01, 00, 04, 00, 19, 0d, 02, 1c, 00, 02, 1d, 02, 12, 00, 02, 11, 00, 12, 00, 01, 11, 01, 0e]
+Function name: closure::main::{closure#18}
+Raw bytes (26): 0x[01, 01, 01, 01, 05, 04, 01, 19, 0d, 02, 1c, 05, 02, 1d, 02, 12, 02, 02, 11, 00, 12, 01, 01, 11, 01, 0e]
 Number of files: 1
 - file 0 => global file 1
-Number of expressions: 0
+Number of expressions: 1
+- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
 Number of file 0 mappings: 4
-- Code(Zero) at (prev + 25, 13) to (start + 2, 28)
-- Code(Zero) at (prev + 2, 29) to (start + 2, 18)
-- Code(Zero) at (prev + 2, 17) to (start + 0, 18)
-- Code(Zero) at (prev + 1, 17) to (start + 1, 14)
-Highest counter ID seen: (none)
+- Code(Counter(0)) at (prev + 25, 13) to (start + 2, 28)
+- Code(Counter(1)) at (prev + 2, 29) to (start + 2, 18)
+- Code(Expression(0, Sub)) at (prev + 2, 17) to (start + 0, 18)
+    = (c0 - c1)
+- Code(Counter(0)) at (prev + 1, 17) to (start + 1, 14)
+Highest counter ID seen: c1
 
 Function name: closure::main::{closure#19}
 Raw bytes (26): 0x[01, 01, 01, 01, 05, 04, 01, 43, 0d, 02, 1c, 05, 02, 1d, 02, 12, 02, 02, 11, 00, 12, 01, 01, 11, 01, 0e]