Skip to content

Pointer to integer casts that expose provenance are incorrectly removed #97421

Closed
@tmiasko

Description

@tmiasko

The pointer to integer cast has an implicit side effect of exposing the provenance, so it cannot be removed under strict provenance model.

Example of an incorrect transformation:

pub fn expose_addr<T>(a: &T) {
    a as *const T as usize;
}
-// MIR for `expose_addr` before SimplifyLocals
+// MIR for `expose_addr` after SimplifyLocals
 
 fn expose_addr(_1: &T) -> () {
     debug a => _1;                       // in scope 0 at a.rs:1:23: 1:24
     let mut _0: ();                      // return place in scope 0 at a.rs:1:30: 1:30
-    let _2: usize;                       // in scope 0 at a.rs:2:5: 2:27
-    let mut _3: *const T;                // in scope 0 at a.rs:2:5: 2:18
 
     bb0: {
-        _3 = &raw const (*_1);           // scope 0 at a.rs:2:5: 2:6
-        _2 = move _3 as usize (Misc);    // scope 0 at a.rs:2:5: 2:27
         return;                          // scope 0 at a.rs:3:2: 3:2
     }
 }

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-mir-optArea: MIR optimizationsA-strict-provenanceArea: Strict provenance for raw pointersC-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions