Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(c2rust-analyze) Support ptr-to-ptr casts between safely transmutable types, for now limited to same-sized integers #839

Merged
merged 35 commits into from
Jun 9, 2023

Commits on Feb 19, 2023

  1. (c2rust-analyze) Support ptr-to-ptr casts between safely transmutab…

    …le types, for now limited to same-sized integers.
    
    This introduces the concept of equivalent/compatible/safely transmutable types.
    This forms an equivalence class among types, as the safe transmutability must be mutual
    (i.e. transmutable in both directions; no prefix-transmutability).
    
    Thus, we can now allow ptr-to-ptr casts between safely transmutable pointee types,
    whereas previously they were only allowed for equal types.
    Equal types could have their `PointerId`s unified as they had the same structure,
    which is still of safely transmutability types,
    which are safely transmutability because they have the same structure/layout.
    
    As safe transmutability is difficult to check abstractly for any two types,
    for now we limit it to commonly transmuted types that we know are definitely transmutable:
    same-sized integer types (with potentially different signedness).
    
    Thus, this enables support for string casts like
    `b"" as *const u8 as *const core::ffi::c_char`, where `c_char = i8`,
    which fixes #840.
    
    Note that the above cast (#833) is still not supported due to the string literal `b""` (#837),
    but the cast itself (in `string_casts.rs` in `fn cast_only`) works.
    kkysen committed Feb 19, 2023
    Configuration menu
    Copy the full SHA
    81d4e46 View commit details
    Browse the repository at this point in the history
  2. (c2rust-analyze) Clarified that do_unify now requires only compat…

    …ible/safetly transmutable types, not identical.
    kkysen committed Feb 19, 2023
    Configuration menu
    Copy the full SHA
    68461db View commit details
    Browse the repository at this point in the history
  3. (c2rust-analyze) Support deeper levels of ptr transmutability (e.x.…

    … `a ~ b` => `*a ~ *b` for all `a`, `b`).
    kkysen committed Feb 19, 2023
    Configuration menu
    Copy the full SHA
    da4d961 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    62ec8dc View commit details
    Browse the repository at this point in the history
  5. (c2rust-analyze) Relaxed the transmutable checks from two-way to on…

    …e-way, now allowing for arrays and slices to decay.
    
    This expands the definition of safe transmutability to be one-way.
    That is, it checks if `*T as *U` is safe, rather than also `*U as *T`.
    
    Thus, we can now allow for casts decaying
    pointers to arrays and slices to pointers to their element type.
    
    `do_unify` is modified to also be one-way,
    which it was already in all call sites.
    
    New tests are also added to `string_casts.rs`
    for all the types of ptr-to-ptr casts.
    
    Out of the full string cast, `b"" as *const u8 as *const core::ffi::c_char`,
    this adds support for the `as *const u8` (from `&[u8; _]`),
    so only support for the string literal itself remains.
    kkysen committed Feb 19, 2023
    Configuration menu
    Copy the full SHA
    0d88d7a View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    a148146 View commit details
    Browse the repository at this point in the history
  7. (c2rust-analyze) Fix the is_transmutable_to docs, formalizing the…

    … expanded defintion of safe transmutability.
    kkysen committed Feb 19, 2023
    Configuration menu
    Copy the full SHA
    26a4275 View commit details
    Browse the repository at this point in the history

Commits on Apr 26, 2023

  1. (c2rust-analyze) Relax the transmutable checks from two-way to one-…

    …way, now allowing for arrays and slices to decay (#841)
    
    Relaxed the transmutable checks from two-way to one-way, now allowing
    for arrays and slices to decay.
    
    This expands the definition of safe transmutability to be one-way. That
    is, it checks if `*T as *U` is safe, rather than also `*U as *T`.
    
    Thus, we can now allow for casts decaying pointers to arrays and slices
    to pointers to their element type.
    
    `do_unify` is modified to also be one-way, which it was already in all
    call sites.
    
    New tests are also added to `string_casts.rs` for all the types of
    ptr-to-ptr casts.
    
    Out of the full string cast, `b"" as *const u8 as *const
    core::ffi::c_char`, this adds support for the `as *const u8` (from
    `&[u8; _]`), so only support for the string literal itself remains.
    kkysen committed Apr 26, 2023
    Configuration menu
    Copy the full SHA
    eae9234 View commit details
    Browse the repository at this point in the history

Commits on May 1, 2023

  1. Configuration menu
    Copy the full SHA
    fe926ea View commit details
    Browse the repository at this point in the history
  2. (c2rust-analyze) Expand transmutability to unsizing casts (`[A] => …

    …[A; N]`, `[A; N] => [A]`).
    
    This fixes transmutability-related crashes in `tests/analyze/string_casts.rs`
    (which weren't being actually run pre-`merge master` for some reason, and so were untested).
    kkysen committed May 1, 2023
    Configuration menu
    Copy the full SHA
    182b0b5 View commit details
    Browse the repository at this point in the history
  3. (c2rust-analyze/tests) Enable the cast_from_literal test now that…

    … string literals are also working (#886, #902).
    kkysen committed May 1, 2023
    Configuration menu
    Copy the full SHA
    32ca464 View commit details
    Browse the repository at this point in the history
  4. (c2rust-analyze) Revert the use of is_transmutable_to in `TypeChe…

    …cker::do_unify` (back to strict equality) as #883 resolved this (#839 (comment)).
    kkysen committed May 1, 2023
    Configuration menu
    Copy the full SHA
    9a7c501 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    0c9d0ac View commit details
    Browse the repository at this point in the history
  6. (c2rust-analyze) Add back the unsizing cast dataflow constraint from

    …#883.  It's not complete, but fixes the crash in `as_ptr.rs`.
    kkysen committed May 1, 2023
    Configuration menu
    Copy the full SHA
    2d45f80 View commit details
    Browse the repository at this point in the history

Commits on May 2, 2023

  1. Configuration menu
    Copy the full SHA
    14824a1 View commit details
    Browse the repository at this point in the history
  2. (c2rust-analyze/tests) Add an explicit (in terms of addr_of!) ver…

    …sion of the `cast_array_to_ptr` test. The other disabled tests still didn't work with the same approach.
    kkysen committed May 2, 2023
    Configuration menu
    Copy the full SHA
    95767c3 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    e41cec1 View commit details
    Browse the repository at this point in the history
  4. (c2rust-analyze/tests) Add a disabled `cast_array_to_slice_ptr_expl…

    …icit` test b/c it still doesn't work even explicitly.
    kkysen committed May 2, 2023
    Configuration menu
    Copy the full SHA
    2915b8d View commit details
    Browse the repository at this point in the history
  5. (c2rust-analyze/test) Reword explanation of explicit string cast te…

    …sts to specify `&raw` MIR statements, inserted with `addr_of!`s.
    kkysen committed May 2, 2023
    Configuration menu
    Copy the full SHA
    11bf351 View commit details
    Browse the repository at this point in the history

Commits on May 5, 2023

  1. (c2rust-analyze) Remove the leading | in a matches! so `rustfmt…

    …` formats it reasonably.
    kkysen committed May 5, 2023
    Configuration menu
    Copy the full SHA
    65e5140 View commit details
    Browse the repository at this point in the history
  2. (c2rust-analyze) Replace "equivalance relation" with "reflexive, tr…

    …ansitive" since it's non-symmetric, and equivalance relations are symmetric.
    kkysen committed May 5, 2023
    Configuration menu
    Copy the full SHA
    44ac9f4 View commit details
    Browse the repository at this point in the history

Commits on May 22, 2023

  1. (c2rust-analyze) Separate handling of CastKinds and only check sa…

    …fe transmutability for `CastKind::Misc`, which are the only non-type-checked ptr casts.
    
    Note that `CastKind::Pointer(PointerCast::Unsize)` needs different rules than safe transmutability.
    These rules are implemented by typeck, so there's no reason re-implementing that,
    but we can't include them in transmutability (will be removed in the next commit).
    kkysen committed May 22, 2023
    Configuration menu
    Copy the full SHA
    4bbb306 View commit details
    Browse the repository at this point in the history
  2. Revert "(c2rust-analyze) Expand transmutability to unsizing casts (…

    …`[A] => [A; N]`, `[A; N] => [A]`)."
    
    This reverts commit 182b0b5.
    kkysen committed May 22, 2023
    Configuration menu
    Copy the full SHA
    720c2fb View commit details
    Browse the repository at this point in the history
  3. (c2rust-analyze/tests) Remove the cast_array_to_slice_ptr tests a…

    …s that cast is unsound and has been removed from transmutability in the last commit.
    kkysen committed May 22, 2023
    Configuration menu
    Copy the full SHA
    df1d63d View commit details
    Browse the repository at this point in the history

Commits on May 25, 2023

  1. Configuration menu
    Copy the full SHA
    b15e24e View commit details
    Browse the repository at this point in the history

Commits on Jun 5, 2023

  1. Configuration menu
    Copy the full SHA
    6ea8a7e View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    1fd669c View commit details
    Browse the repository at this point in the history

Commits on Jun 8, 2023

  1. (c2rust-analyze) Adjust wording on safe transmutability definition …

    …to use well-defined instead of safe and to use "implies" instead of "and".
    kkysen committed Jun 8, 2023
    Configuration menu
    Copy the full SHA
    a73e64d View commit details
    Browse the repository at this point in the history
  2. (c2rust-analyze) Revert the arg names of do_unify to lty{1,2} f…

    …rom `{pl,rv}_lty`, as they are interchangeable.
    kkysen committed Jun 8, 2023
    Configuration menu
    Copy the full SHA
    435e399 View commit details
    Browse the repository at this point in the history
  3. (c2rust-analyze) Update safe transmutability rules to add `A ~ B =>…

    …` to the slice and array rules.
    kkysen committed Jun 8, 2023
    Configuration menu
    Copy the full SHA
    1317e03 View commit details
    Browse the repository at this point in the history
  4. (c2rust-analyze) For the array safe transmutability rule, require t…

    …han `N > 0` to avoid ZSTs, as then the rule would be unsound.
    kkysen committed Jun 8, 2023
    Configuration menu
    Copy the full SHA
    60a4376 View commit details
    Browse the repository at this point in the history
  5. (c2rust-analyze) Remove the slice rule for safe transmutability, as…

    … it's only sound for non-empty slices, but we can't check that at compile-time.
    kkysen committed Jun 8, 2023
    Configuration menu
    Copy the full SHA
    9b43bd6 View commit details
    Browse the repository at this point in the history

Commits on Jun 9, 2023

  1. Configuration menu
    Copy the full SHA
    355b56b View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    7f87dc1 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    31baf0a View commit details
    Browse the repository at this point in the history