Skip to content

Commit 6c6a39e

Browse files
committed
cfg(kcfi)
1 parent 17d4124 commit 6c6a39e

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

Diff for: library/core/src/fmt/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::char::{EscapeDebugExtArgs, MAX_LEN_UTF8};
77
use crate::marker::PhantomData;
88
use crate::num::fmt as numfmt;
99
use crate::ops::Deref;
10-
use crate::{iter, result, str};
10+
use crate::{iter, mem, result, str};
1111

1212
mod builders;
1313
#[cfg(not(no_fp_fmt_parse))]

Diff for: library/core/src/fmt/rt.rs

+7
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ 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+
#[cfg(not(any(sanitize = "cfi", sanitize = "kcfi")))]
76+
formatter: {
77+
let f: fn(&$t, &mut Formatter<'_>) -> Result = $f;
78+
// SAFETY: This is only called with `value`, which has the right type.
79+
unsafe { mem::transmute(f) }
80+
},
81+
#[cfg(any(sanitize = "cfi", sanitize = "kcfi"))]
7582
formatter: |ptr: NonNull<()>, fmt: &mut Formatter<'_>| {
7683
let func = $f;
7784
// SAFETY: This is the same type as the `value` field.

Diff for: tests/coverage/closure.cov-map

+10-8
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,19 @@ Number of file 0 mappings: 6
140140
- Code(Counter(0)) at (prev + 2, 9) to (start + 0, 10)
141141
Highest counter ID seen: c1
142142

143-
Function name: closure::main::{closure#18} (unused)
144-
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]
143+
Function name: closure::main::{closure#18}
144+
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]
145145
Number of files: 1
146146
- file 0 => global file 1
147-
Number of expressions: 0
147+
Number of expressions: 1
148+
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
148149
Number of file 0 mappings: 4
149-
- Code(Zero) at (prev + 25, 13) to (start + 2, 28)
150-
- Code(Zero) at (prev + 2, 29) to (start + 2, 18)
151-
- Code(Zero) at (prev + 2, 17) to (start + 0, 18)
152-
- Code(Zero) at (prev + 1, 17) to (start + 1, 14)
153-
Highest counter ID seen: (none)
150+
- Code(Counter(0)) at (prev + 25, 13) to (start + 2, 28)
151+
- Code(Counter(1)) at (prev + 2, 29) to (start + 2, 18)
152+
- Code(Expression(0, Sub)) at (prev + 2, 17) to (start + 0, 18)
153+
= (c0 - c1)
154+
- Code(Counter(0)) at (prev + 1, 17) to (start + 1, 14)
155+
Highest counter ID seen: c1
154156

155157
Function name: closure::main::{closure#19}
156158
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]

0 commit comments

Comments
 (0)