GVN does not account for implicit retags during assignment
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
Reproduce the snippet in the issue under Miri with -Zmir-opt-level=1 -Zmir-enable-passes=+GVN -Zmiri-tree-borrows to confirm the Tree Borrows error at borrow_field_a. The open question is whether the fix belongs in MIR semantics for implicit retags or in the GVN pass, and the maintainers have not decided that. Done means the reproducer passes Miri under both Stacked Borrows and Tree Borrows, which needs maintainer agreement on the approach first.
索引モデルが issue の本文から書いたものです。
説明
This code is fine under our current aliasing models, but GVN optimizes it into something that has UB under both Stacked Borrows and Tree Borrows:
fn main() {
struct Foo {
a: String,
b: Vec<u32>,
}
unsafe fn borrow_field_a<'a>(this: *mut Foo) -> &'a mut String {
&mut (*this).a
}
unsafe fn borrow_field_b<'a>(this: *mut Foo) -> &'a mut Vec<u32> {
&mut (*this).b
}
let mut foo = Foo { a: "hello".into(), b: vec![0, 1, 2] };
let ptr = &mut foo as *mut Foo;
let a = unsafe { borrow_field_a(ptr) };
let b = unsafe { borrow_field_b(ptr) };
b.push(4);
a.push_str(" world");
assert_eq!(format!("{:?} {:?}", a, b), r#""hello world" [0, 1, 2, 4]"#);
}
Running this in Miri with -Zmir-opt-level=1 -Zmir-enable-passes=+GVN -Zmiri-tree-borrows reports UB:
error: Undefined Behavior: reborrow through <605> at alloc406[0x0] is forbidden
--> /opt/compiler-explorer/rust-miri-nightly/lib/rustlib/src/rust/library/core/src/fmt/mod.rs:2918:70
|
= note: Undefined Behavior occurred here
::: /opt/compiler-explorer/rust-miri-nightly/lib/rustlib/src/rust/library/core/src/fmt/mod.rs:2924:0
|
= note: in this macro invocation
|
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Tree Borrows rules it violated are still experimental
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/tree-borrows.md for further information
= help: the accessed tag <605> has state Disabled which forbids this reborrow (acting as a child read access)
help: the accessed tag <605> was created here, in the initial state Reserved
--> <source>:19:22
|
19 | let a = unsafe { borrow_field_a(ptr) };
| ^^^^^^^^^^^^^^^^^^^
help: the accessed tag <605> later transitioned to Disabled due to a foreign write access at offsets [0x0..0x8]
--> <source>:22:5
|
22 | a.push_str(" world");
| ^^^^^^^^^^^^^^^^^^^^
https://rust.godbolt.org/z/z5nqqhfxn
Cc @rust-lang/wg-mir-opt
I'm not sure if the fix here is a change in MIR semantics or a change in GVN, but something surely needs to be fixed.
- 主要言語
- Rust
- スター
- 121k
- フォーク
- 17.3k
- 平均マージ
- 2日 21時間
- マージ済み PR(30日)
- 531
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
rust-lang/rust のほかの issue
-
A-run-make relnotes relnotes-needs-review relnotes-tracking-issue T-lang T-libs
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
relnotes relnotes-needs-review relnotes-tracking-issue T-compiler T-libs
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
A-LLVM O-Arm O-UEFI O-x86_64 relnotes relnotes-needs-review relnotes-tracking-issue T-compiler
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
rust-lang/rust#165504 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
relnotes relnotes-tracking-issue T-libs
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
unclear wording in vec macro対応中かも @Suhird が 5 日前に担当しました。 オープンA-docs A-slice-vec T-libs
難易度 1/5 1〜3時間 初心者へのやさしさ 70/100
rust-lang/rust#165360 · コメント 6 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 69/100
bytecodealliance/rustix#1736 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
longbridge/gpui-kit#3871 ·
メンテナーはふだん 1 日以内に返信
-
area:models enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
メンテナーはふだん 1 日以内に返信
-
good first issue help wanted
難易度 1/5 1時間未満 初心者へのやさしさ 84/100
servo/rust-smallvec#864 ·