No subobject provenance for arrays/slices

Đang mở
#622 54 bình luận 4 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
30/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
rust
Lĩnh vực
compilers, devtools

Hướng nghiên cứu

Start by reviewing the example and the related unsafe-code-guidelines issue 419, then read the Reference wording in pull request 2338. The work is complete when the provenance policy is resolved and Miri no longer reports the demonstrated array or slice accesses as undefined behavior.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

disposition-merge proposed-final-comment-period T-opsem

https://github.com/rust-lang/unsafe-code-guidelines/issues/419 is a big topic, but there is one specific form of subobject provenance which is violated particularly often: using a reference to one element of an array/slice to access another. Even C allows this, so IMO we should commit to also allowing this in Rust.

Concretely, this means the following code has no UB:

fn main() {
    let x = &mut [1, 2, 3];
    let ptr = &mut x[0] as *mut i32;
    unsafe { ptr.add(1).write(5) };
    
    let ptr = &x[1] as *const i32;
    let _val = unsafe { ptr.sub(1).read() };
}

This is based on the observation that violations of such subobject provenance are the major kind of Stacked Borrows UB that Miri finds. I'd like to make Miri stop report this as UB, and for this I'd like to be sure that indeed we don't want to make this UB.

See https://github.com/rust-lang/reference/pull/2338 for Reference-level wording of this.

Ngôn ngữ chính
Không có dữ liệu ngôn ngữ
Star
760
Fork
68
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của rust-lang/unsafe-code-guidelines

Tất cả issue của rust-lang/unsafe-code-guidelines

Issue tương tự

Thêm issue về Compilers

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.