Skip to content

Commit 8bd4bbe

Browse files
committed
tweak int2ptr diagnostics
1 parent aaaed51 commit 8bd4bbe

File tree

6 files changed

+34
-27
lines changed

6 files changed

+34
-27
lines changed

src/diagnostics.rs

+17-8
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub enum TerminationInfo {
2121
help: Option<String>,
2222
history: Option<TagHistory>,
2323
},
24+
Int2PtrWithStrictProvenance,
2425
Deadlock,
2526
MultipleSymbolDefinitions {
2627
link_name: Symbol,
@@ -42,6 +43,11 @@ impl fmt::Display for TerminationInfo {
4243
Exit(code) => write!(f, "the evaluated program completed with exit code {}", code),
4344
Abort(msg) => write!(f, "{}", msg),
4445
UnsupportedInIsolation(msg) => write!(f, "{}", msg),
46+
Int2PtrWithStrictProvenance =>
47+
write!(
48+
f,
49+
"integer-to-pointer casts and `ptr::from_exposed_addr` are not supported with `-Zmiri-strict-provenance`"
50+
),
4551
StackedBorrowsUb { msg, .. } => write!(f, "{}", msg),
4652
Deadlock => write!(f, "the evaluated program deadlocked"),
4753
MultipleSymbolDefinitions { link_name, .. } =>
@@ -148,7 +154,8 @@ pub fn report_error<'tcx, 'mir>(
148154
let title = match info {
149155
Exit(code) => return Some(*code),
150156
Abort(_) => Some("abnormal termination"),
151-
UnsupportedInIsolation(_) => Some("unsupported operation"),
157+
UnsupportedInIsolation(_) | Int2PtrWithStrictProvenance =>
158+
Some("unsupported operation"),
152159
StackedBorrowsUb { .. } => Some("Undefined Behavior"),
153160
Deadlock => Some("deadlock"),
154161
MultipleSymbolDefinitions { .. } | SymbolShimClashing { .. } => None,
@@ -177,7 +184,7 @@ pub fn report_error<'tcx, 'mir>(
177184
}
178185
if let Some((protecting_tag, protecting_tag_span, protection_span)) = protected {
179186
helps.push((Some(*protecting_tag_span), format!("{:?} was protected due to {:?} which was created here", tag, protecting_tag)));
180-
helps.push((Some(*protection_span), "this protector is live for this call".to_string()));
187+
helps.push((Some(*protection_span), format!("this protector is live for this call")));
181188
}
182189
}
183190
None => {}
@@ -191,6 +198,8 @@ pub fn report_error<'tcx, 'mir>(
191198
],
192199
SymbolShimClashing { link_name, span } =>
193200
vec![(Some(*span), format!("the `{}` symbol is defined here", link_name))],
201+
Int2PtrWithStrictProvenance =>
202+
vec![(None, format!("use Strict Provenance APIs (https://doc.rust-lang.org/nightly/std/ptr/index.html#strict-provenance, https://crates.io/crates/sptr) instead"))],
194203
_ => vec![],
195204
};
196205
(title, helps)
@@ -471,12 +480,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
471480
let helps = match e {
472481
Int2Ptr { details: true } =>
473482
vec![
474-
(None, format!("this program is using integer-to-pointer casts or (equivalently) `from_exposed_addr`,")),
475-
(None, format!("which means that Miri might miss pointer bugs in this program")),
476-
(None, format!("see https://doc.rust-lang.org/nightly/std/ptr/fn.from_exposed_addr.html for more details on that operation")),
477-
(None, format!("to ensure that Miri does not miss bugs in your program, use `with_addr` (https://doc.rust-lang.org/nightly/std/ptr/index.html#strict-provenance) instead")),
478-
(None, format!("you can then pass the `-Zmiri-strict-provenance` flag to Miri, to ensure you are not relying on `from_exposed_addr` semantics")),
479-
(None, format!("alternatively, the `-Zmiri-permissive-provenance` flag disables this warning")),
483+
(None, format!("This program is using integer-to-pointer casts or (equivalently) `ptr::from_exposed_addr`,")),
484+
(None, format!("which means that Miri might miss pointer bugs in this program.")),
485+
(None, format!("See https://doc.rust-lang.org/nightly/std/ptr/fn.from_exposed_addr.html for more details on that operation.")),
486+
(None, format!("To ensure that Miri does not miss bugs in your program, use Strict Provenance APIs (https://doc.rust-lang.org/nightly/std/ptr/index.html#strict-provenance, https://crates.io/crates/sptr) instead.")),
487+
(None, format!("You can then pass the `-Zmiri-strict-provenance` flag to Miri, to ensure you are not relying on `from_exposed_addr` semantics.")),
488+
(None, format!("Alternatively, the `-Zmiri-permissive-provenance` flag disables this warning.")),
480489
],
481490
_ => vec![],
482491
};

src/intptrcast.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,7 @@ impl<'mir, 'tcx> GlobalStateInner {
146146
});
147147
}
148148
ProvenanceMode::Strict => {
149-
throw_unsup_format!(
150-
"integer-to-pointer casts and `from_exposed_addr` are not supported with `-Zmiri-strict-provenance`; use `with_addr` instead"
151-
)
149+
throw_machine_stop!(TerminationInfo::Int2PtrWithStrictProvenance);
152150
}
153151
ProvenanceMode::Permissive => {}
154152
}

tests/fail/provenance/strict_provenance_cast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
fn main() {
44
let addr = &0 as *const i32 as usize;
5-
let _ptr = addr as *const i32; //~ ERROR integer-to-pointer casts and `from_exposed_addr` are not supported
5+
let _ptr = addr as *const i32; //~ ERROR integer-to-pointer casts and `ptr::from_exposed_addr` are not supported
66
}

tests/fail/provenance/strict_provenance_cast.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error: unsupported operation: integer-to-pointer casts and `from_exposed_addr` are not supported with `-Zmiri-strict-provenance`; use `with_addr` instead
1+
error: unsupported operation: integer-to-pointer casts and `ptr::from_exposed_addr` are not supported with `-Zmiri-strict-provenance`
22
--> $DIR/strict_provenance_cast.rs:LL:CC
33
|
44
LL | let _ptr = addr as *const i32;
5-
| ^^^^^^^^^^^^^^^^^^ integer-to-pointer casts and `from_exposed_addr` are not supported with `-Zmiri-strict-provenance`; use `with_addr` instead
5+
| ^^^^^^^^^^^^^^^^^^ integer-to-pointer casts and `ptr::from_exposed_addr` are not supported with `-Zmiri-strict-provenance`
66
|
7-
= help: this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support
7+
= help: use Strict Provenance APIs (https://doc.rust-lang.org/nightly/std/ptr/index.html#strict-provenance, https://crates.io/crates/sptr) instead
88

99
= note: inside `main` at $DIR/strict_provenance_cast.rs:LL:CC
1010

tests/pass/box.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ warning: integer-to-pointer cast
44
LL | let r2 = ((r as usize) + 0) as *mut i32;
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ integer-to-pointer cast
66
|
7-
= help: this program is using integer-to-pointer casts or (equivalently) `from_exposed_addr`,
8-
= help: which means that Miri might miss pointer bugs in this program
9-
= help: see https://doc.rust-lang.org/nightly/std/ptr/fn.from_exposed_addr.html for more details on that operation
10-
= help: to ensure that Miri does not miss bugs in your program, use `with_addr` (https://doc.rust-lang.org/nightly/std/ptr/index.html#strict-provenance) instead
11-
= help: you can then pass the `-Zmiri-strict-provenance` flag to Miri, to ensure you are not relying on `from_exposed_addr` semantics
12-
= help: alternatively, the `-Zmiri-permissive-provenance` flag disables this warning
7+
= help: This program is using integer-to-pointer casts or (equivalently) `ptr::from_exposed_addr`,
8+
= help: which means that Miri might miss pointer bugs in this program.
9+
= help: See https://doc.rust-lang.org/nightly/std/ptr/fn.from_exposed_addr.html for more details on that operation.
10+
= help: To ensure that Miri does not miss bugs in your program, use Strict Provenance APIs (https://doc.rust-lang.org/nightly/std/ptr/index.html#strict-provenance, https://crates.io/crates/sptr) instead.
11+
= help: You can then pass the `-Zmiri-strict-provenance` flag to Miri, to ensure you are not relying on `from_exposed_addr` semantics.
12+
= help: Alternatively, the `-Zmiri-permissive-provenance` flag disables this warning.
1313

1414
= note: inside `into_raw` at $DIR/box.rs:LL:CC
1515
note: inside `main` at $DIR/box.rs:LL:CC

tests/pass/extern_types.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ warning: integer-to-pointer cast
44
LL | let x: &Foo = unsafe { &*(16 as *const Foo) };
55
| ^^^^^^^^^^^^^^^^^^ integer-to-pointer cast
66
|
7-
= help: this program is using integer-to-pointer casts or (equivalently) `from_exposed_addr`,
8-
= help: which means that Miri might miss pointer bugs in this program
9-
= help: see https://doc.rust-lang.org/nightly/std/ptr/fn.from_exposed_addr.html for more details on that operation
10-
= help: to ensure that Miri does not miss bugs in your program, use `with_addr` (https://doc.rust-lang.org/nightly/std/ptr/index.html#strict-provenance) instead
11-
= help: you can then pass the `-Zmiri-strict-provenance` flag to Miri, to ensure you are not relying on `from_exposed_addr` semantics
12-
= help: alternatively, the `-Zmiri-permissive-provenance` flag disables this warning
7+
= help: This program is using integer-to-pointer casts or (equivalently) `ptr::from_exposed_addr`,
8+
= help: which means that Miri might miss pointer bugs in this program.
9+
= help: See https://doc.rust-lang.org/nightly/std/ptr/fn.from_exposed_addr.html for more details on that operation.
10+
= help: To ensure that Miri does not miss bugs in your program, use Strict Provenance APIs (https://doc.rust-lang.org/nightly/std/ptr/index.html#strict-provenance, https://crates.io/crates/sptr) instead.
11+
= help: You can then pass the `-Zmiri-strict-provenance` flag to Miri, to ensure you are not relying on `from_exposed_addr` semantics.
12+
= help: Alternatively, the `-Zmiri-permissive-provenance` flag disables this warning.
1313

1414
= note: inside `main` at $DIR/extern_types.rs:LL:CC
1515

0 commit comments

Comments
 (0)