Surprising behavior of aliasing model: references that are transmuted into existence might not have the expected properties

Aperta
#593 29 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Da chiarire
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
compilers

Direzione di ricerca

The issue provides no repository file or test entry point. Start with the Rust example and its discussion of Stacked Borrows and Tree Borrows; the work would need to establish an explicit decision about references copied with ptr::copy_nonoverlapping and document the outcome.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

A-aliasing-model

This code does not have UB under Stacked Borrows and Tree Borrows:

fn main() {
    let mut data = 1;
    let x = &mut data;
    let mut y = &mut 2;
    unsafe { std::ptr::copy_nonoverlapping(&raw const x, &raw mut y, 1); }
    *x = 3;
    *y = 4;
    *x = 5;
    *y = 6;
}

This is expected behavior. The copy_nonoverlapping makes y a perfect copy of x, those two just contain the same pointer. Mutable references are unique in the sense that no "other" pointer is allowed to be used while they are live -- but here, there's no "other" pointer, it's twice the same pointer.

Within the framework that SB and TB are built in, I don't see any way to avoid that. I don't think *x = 3 should mutate x itself, so it follows that x and y just are and remain the same pointer.

I am filing this issue mostly to remind us that when we move towards making decisions around the aliasing model, we should explicitly discuss this case. But maybe someone has an idea for how a model could make this UB?

Lingua principale
Nessun dato sulla lingua
Stelle
760
Fork
68
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di rust-lang/unsafe-code-guidelines

Tutte le issue di rust-lang/unsafe-code-guidelines

Issue simili

Altre issue su Compilers

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.