Skip to content

Commit 03a05ae

Browse files
committed
Auto merge of #2195 - RalfJung:vtable-validation, r=RalfJung
test for Stacked Borrows error during vtable validation Fixes #2123 Needs rust-lang/rust#97761
2 parents 96ee9a0 + 6ed05d9 commit 03a05ae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+104
-67
lines changed

rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
09d52bc5d4260bac8b9a2ea8ac7a07c5c72906f1
1+
99930ac7f8cbb5d9b319b2e2e92794fd6f24f556

src/diagnostics.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ pub enum TerminationInfo {
1616
Exit(i64),
1717
Abort(String),
1818
UnsupportedInIsolation(String),
19-
ExperimentalUb {
19+
StackedBorrowsUb {
2020
msg: String,
2121
help: Option<String>,
22-
url: String,
2322
history: Option<TagHistory>,
2423
},
2524
Deadlock,
@@ -43,7 +42,7 @@ impl fmt::Display for TerminationInfo {
4342
Exit(code) => write!(f, "the evaluated program completed with exit code {}", code),
4443
Abort(msg) => write!(f, "{}", msg),
4544
UnsupportedInIsolation(msg) => write!(f, "{}", msg),
46-
ExperimentalUb { msg, .. } => write!(f, "{}", msg),
45+
StackedBorrowsUb { msg, .. } => write!(f, "{}", msg),
4746
Deadlock => write!(f, "the evaluated program deadlocked"),
4847
MultipleSymbolDefinitions { link_name, .. } =>
4948
write!(f, "multiple definitions of symbol `{}`", link_name),
@@ -146,7 +145,7 @@ pub fn report_error<'tcx, 'mir>(
146145
Exit(code) => return Some(*code),
147146
Abort(_) => Some("abnormal termination"),
148147
UnsupportedInIsolation(_) => Some("unsupported operation"),
149-
ExperimentalUb { .. } => Some("Undefined Behavior"),
148+
StackedBorrowsUb { .. } => Some("Undefined Behavior"),
150149
Deadlock => Some("deadlock"),
151150
MultipleSymbolDefinitions { .. } | SymbolShimClashing { .. } => None,
152151
};
@@ -157,11 +156,12 @@ pub fn report_error<'tcx, 'mir>(
157156
(None, format!("pass the flag `-Zmiri-disable-isolation` to disable isolation;")),
158157
(None, format!("or pass `-Zmiri-isolation-error=warn` to configure Miri to return an error code from isolated operations (if supported for that operation) and continue with a warning")),
159158
],
160-
ExperimentalUb { url, help, history, .. } => {
159+
StackedBorrowsUb { help, history, .. } => {
160+
let url = "https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md";
161161
msg.extend(help.clone());
162162
let mut helps = vec![
163-
(None, format!("this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental")),
164-
(None, format!("see {} for further information", url)),
163+
(None, format!("this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental")),
164+
(None, format!("see {url} for further information")),
165165
];
166166
match history {
167167
Some(TagHistory::Tagged {tag, created: (created_range, created_span), invalidated, protected }) => {

src/stacked_borrows.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -250,14 +250,7 @@ pub fn err_sb_ub<'tcx>(
250250
help: Option<String>,
251251
history: Option<TagHistory>,
252252
) -> InterpError<'tcx> {
253-
err_machine_stop!(TerminationInfo::ExperimentalUb {
254-
msg,
255-
help,
256-
url: format!(
257-
"https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md"
258-
),
259-
history
260-
})
253+
err_machine_stop!(TerminationInfo::StackedBorrowsUb { msg, help, history })
261254
}
262255

263256
// # Stacked Borrows Core Begin

tests/fail/box-cell-alias.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | unsafe { (*ptr).set(20); }
77
| trying to reborrow <TAG> for SharedReadWrite permission at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
88
| this error occurs as part of a reborrow at ALLOC[0x0..0x1]
99
|
10-
= help: this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental
10+
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
1111
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
1212
help: <TAG> was created by a retag at offsets [0x0..0x1]
1313
--> $DIR/box-cell-alias.rs:LL:CC

tests/fail/stacked_borrows/alias_through_mutation.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | let _val = *target_alias;
77
| attempting a read access using <TAG> at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
88
| this error occurs as part of an access at ALLOC[0x0..0x4]
99
|
10-
= help: this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental
10+
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
1111
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
1212
help: <TAG> was created by a retag at offsets [0x0..0x4]
1313
--> $DIR/alias_through_mutation.rs:LL:CC

tests/fail/stacked_borrows/aliasing_mut1.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: Undefined Behavior: not granting access to tag <TAG> because incompatible
44
LL | pub fn safe(_x: &mut i32, _y: &mut i32) {}
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not granting access to tag <TAG> because incompatible item is protected: [Unique for <TAG> (call ID)]
66
|
7-
= help: this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental
7+
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
88
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
99
help: <TAG> was created by a retag at offsets [0x0..0x4]
1010
--> $DIR/aliasing_mut1.rs:LL:CC

tests/fail/stacked_borrows/aliasing_mut2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: Undefined Behavior: not granting access to tag <TAG> because incompatible
44
LL | pub fn safe(_x: &i32, _y: &mut i32) {}
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not granting access to tag <TAG> because incompatible item is protected: [SharedReadOnly for <TAG> (call ID)]
66
|
7-
= help: this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental
7+
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
88
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
99
help: <TAG> was created by a retag at offsets [0x0..0x4]
1010
--> $DIR/aliasing_mut2.rs:LL:CC

tests/fail/stacked_borrows/aliasing_mut3.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | pub fn safe(_x: &mut i32, _y: &i32) {}
77
| trying to reborrow <untagged> for SharedReadOnly permission at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
88
| this error occurs as part of a reborrow at ALLOC[0x0..0x4]
99
|
10-
= help: this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental
10+
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
1111
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
1212
help: tag was most recently created at offsets [0x0..0x4]
1313
--> $DIR/aliasing_mut3.rs:LL:CC

tests/fail/stacked_borrows/aliasing_mut4.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: Undefined Behavior: not granting access to tag <TAG> because incompatible
44
LL | pub fn safe(_x: &i32, _y: &mut Cell<i32>) {}
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not granting access to tag <TAG> because incompatible item is protected: [SharedReadOnly for <TAG> (call ID)]
66
|
7-
= help: this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental
7+
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
88
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
99
help: <TAG> was created by a retag at offsets [0x0..0x4]
1010
--> $DIR/aliasing_mut4.rs:LL:CC

tests/fail/stacked_borrows/box_exclusive_violation1.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | *our
77
| attempting a read access using <TAG> at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
88
| this error occurs as part of an access at ALLOC[0x0..0x4]
99
|
10-
= help: this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental
10+
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
1111
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
1212
help: <TAG> was created by a retag at offsets [0x0..0x4]
1313
--> $DIR/box_exclusive_violation1.rs:LL:CC

tests/fail/stacked_borrows/buggy_as_mut_slice.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | v1[1] = 5;
77
| attempting a write access using <TAG> at ALLOC[0x4], but that tag does not exist in the borrow stack for this location
88
| this error occurs as part of an access at ALLOC[0x4..0x8]
99
|
10-
= help: this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental
10+
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
1111
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
1212
help: <TAG> was created by a retag at offsets [0x0..0xc]
1313
--> $DIR/buggy_as_mut_slice.rs:LL:CC

tests/fail/stacked_borrows/buggy_split_at_mut.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | let (a, b) = safe::split_at_mut(&mut array, 0);
77
| trying to reborrow <TAG> for Unique permission at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
88
| this error occurs as part of a reborrow at ALLOC[0x0..0x10]
99
|
10-
= help: this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental
10+
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
1111
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
1212
help: <TAG> was created by a retag at offsets [0x0..0x10]
1313
--> $DIR/buggy_split_at_mut.rs:LL:CC

tests/fail/stacked_borrows/deallocate_against_barrier1.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: Undefined Behavior: deallocating while item is protected: [Unique for <TA
44
LL | unsafe { __rust_dealloc(ptr, layout.size(), layout.align()) }
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ deallocating while item is protected: [Unique for <TAG> (call ID)]
66
|
7-
= help: this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental
7+
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
88
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
99

1010
= note: inside `std::alloc::dealloc` at RUSTLIB/alloc/src/alloc.rs:LL:CC

tests/fail/stacked_borrows/deallocate_against_barrier2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: Undefined Behavior: deallocating while item is protected: [SharedReadWrit
44
LL | unsafe { __rust_dealloc(ptr, layout.size(), layout.align()) }
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ deallocating while item is protected: [SharedReadWrite for <TAG> (call ID)]
66
|
7-
= help: this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental
7+
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
88
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
99

1010
= note: inside `std::alloc::dealloc` at RUSTLIB/alloc/src/alloc.rs:LL:CC

tests/fail/stacked_borrows/illegal_read1.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | let _val = *xref; // ...but any use of raw will invalidate our ref.
77
| attempting a read access using <TAG> at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
88
| this error occurs as part of an access at ALLOC[0x0..0x4]
99
|
10-
= help: this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental
10+
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
1111
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
1212
help: <TAG> was created by a retag at offsets [0x0..0x4]
1313
--> $DIR/illegal_read1.rs:LL:CC

tests/fail/stacked_borrows/illegal_read2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | let _val = *xref; // ...but any use of raw will invalidate our ref.
77
| attempting a read access using <TAG> at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
88
| this error occurs as part of an access at ALLOC[0x0..0x4]
99
|
10-
= help: this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental
10+
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
1111
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
1212
help: <TAG> was created by a retag at offsets [0x0..0x4]
1313
--> $DIR/illegal_read2.rs:LL:CC

tests/fail/stacked_borrows/illegal_read3.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | let _val = *xref2;
77
| attempting a read access using <TAG> at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
88
| this error occurs as part of an access at ALLOC[0x0..0x4]
99
|
10-
= help: this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental
10+
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
1111
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
1212
help: <TAG> was created by a retag at offsets [0x0..0x4]
1313
--> $DIR/illegal_read3.rs:LL:CC

tests/fail/stacked_borrows/illegal_read4.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | let _illegal = *xref2;
77
| attempting a read access using <TAG> at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
88
| this error occurs as part of an access at ALLOC[0x0..0x4]
99
|
10-
= help: this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental
10+
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
1111
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
1212
help: <TAG> was created by a retag at offsets [0x0..0x4]
1313
--> $DIR/illegal_read4.rs:LL:CC

tests/fail/stacked_borrows/illegal_read5.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | let _val = *xref; // the mutable one is dead and gone
77
| attempting a read access using <TAG> at ALLOC[$HEX], but that tag does not exist in the borrow stack for this location
88
| this error occurs as part of an access at ALLOC[$HEX..$HEX]
99
|
10-
= help: this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental
10+
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
1111
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
1212
help: <TAG> was created by a retag at offsets [$HEX..$HEX]
1313
--> $DIR/illegal_read5.rs:LL:CC

tests/fail/stacked_borrows/illegal_read6.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | let _val = *raw;
77
| attempting a read access using <untagged> at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
88
| this error occurs as part of an access at ALLOC[0x0..0x4]
99
|
10-
= help: this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental
10+
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
1111
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
1212
help: tag was most recently created at offsets [0x0..0x4]
1313
--> $DIR/illegal_read6.rs:LL:CC

tests/fail/stacked_borrows/illegal_read7.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | let _val = *x.get_mut();
77
| trying to reborrow <TAG> for SharedReadWrite permission at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
88
| this error occurs as part of a reborrow at ALLOC[0x0..0x4]
99
|
10-
= help: this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental
10+
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
1111
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
1212
help: <TAG> was created by a retag at offsets [0x0..0x4]
1313
--> $DIR/illegal_read7.rs:LL:CC

tests/fail/stacked_borrows/illegal_read8.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | let _fail = *y1;
77
| attempting a read access using <TAG> at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
88
| this error occurs as part of an access at ALLOC[0x0..0x4]
99
|
10-
= help: this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental
10+
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
1111
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
1212
help: <TAG> was created by a retag at offsets [0x0..0x4]
1313
--> $DIR/illegal_read8.rs:LL:CC

tests/fail/stacked_borrows/illegal_write1.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | let _x = *xref;
77
| attempting a read access using <TAG> at ALLOC[0x0], but that tag does not exist in the borrow stack for this location
88
| this error occurs as part of an access at ALLOC[0x0..0x4]
99
|
10-
= help: this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental
10+
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
1111
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
1212
help: <TAG> was created by a retag at offsets [0x0..0x4]
1313
--> $DIR/illegal_write1.rs:LL:CC

0 commit comments

Comments
 (0)