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

change semantics of @memcpy and @memset #15278

Merged
merged 21 commits into from
Apr 26, 2023
Merged

change semantics of @memcpy and @memset #15278

merged 21 commits into from
Apr 26, 2023

Commits on Apr 25, 2023

  1. change semantics of @memcpy and @memset

    Now they use slices or array pointers with any element type instead of
    requiring byte pointers.
    
    This is a breaking enhancement to the language.
    
    The safety check for overlapping pointers will be implemented in a
    future commit.
    
    closes #14040
    andrewrk committed Apr 25, 2023
    Configuration menu
    Copy the full SHA
    a5c910a View commit details
    Browse the repository at this point in the history
  2. update @memcpy to require equal src and dest lens

     * Sema: upgrade operands to array pointers if possible when emitting
       AIR.
     * Implement safety checks for length mismatch and aliasing.
     * AIR: make ptrtoint support slice operands. Implement in LLVM backend.
     * C backend: implement new `@memset` semantics. `@memcpy` is not done
       yet.
    andrewrk committed Apr 25, 2023
    Configuration menu
    Copy the full SHA
    edb5e49 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    92186b8 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    76e340c View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    25d1128 View commit details
    Browse the repository at this point in the history
  6. LLVM backend: support non-byte-sized memset

    Also introduce memset_safe AIR tag and support it in C backend and LLVM
    backend.
    andrewrk committed Apr 25, 2023
    Configuration menu
    Copy the full SHA
    057c950 View commit details
    Browse the repository at this point in the history
  7. C backend: fix memset for loop lowering

    Previously, this code casted the array pointer to u8 pointer, but I
    removed that in a different commit. This commit restores the cast, but
    instead of hard-coding u8, it uses the destination element pointer,
    since memset now supports arbitrary element types.
    andrewrk committed Apr 25, 2023
    Configuration menu
    Copy the full SHA
    0f65cc9 View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    83a7303 View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    482a0f6 View commit details
    Browse the repository at this point in the history
  10. add behavior test for @memset on slices

    and avoid new language feature in std.ArrayList for now, until x86_64
    self-hosted backend can implement it.
    andrewrk committed Apr 25, 2023
    Configuration menu
    Copy the full SHA
    7c56145 View commit details
    Browse the repository at this point in the history
  11. x86_64 backend: implement @memset for element ABI size > 1

     * make memset and memset_safe guarantee that if the length is
       comptime-known then it will be nonzero.
    andrewrk committed Apr 25, 2023
    Configuration menu
    Copy the full SHA
    881e931 View commit details
    Browse the repository at this point in the history
  12. Configuration menu
    Copy the full SHA
    58fabbc View commit details
    Browse the repository at this point in the history
  13. langref: fix compile error

    andrewrk committed Apr 25, 2023
    Configuration menu
    Copy the full SHA
    bd6f01c View commit details
    Browse the repository at this point in the history
  14. update zig1.wasm

    Needed due to the compiler depending on standard library APIs such as
    ArrayList that contain `@memset` and `@memcpy` calls in them. The number
    of parameters changed, so this is necessary for the compiler to build.
    andrewrk committed Apr 25, 2023
    Configuration menu
    Copy the full SHA
    a8de15f View commit details
    Browse the repository at this point in the history
  15. Configuration menu
    Copy the full SHA
    747f583 View commit details
    Browse the repository at this point in the history
  16. Configuration menu
    Copy the full SHA
    1ba72bc View commit details
    Browse the repository at this point in the history
  17. C backend: use ++ instead of += for airMemset

    It does the same thing but has fewer bytes in the output.
    andrewrk committed Apr 25, 2023
    Configuration menu
    Copy the full SHA
    d604553 View commit details
    Browse the repository at this point in the history
  18. stage2: introduce store_safe AIR instruction

    store:
    The value to store may be undefined, in which case the destination
    memory region has undefined bytes after this instruction is
    evaluated. In such case ignoring this instruction is legal
    lowering.
    
    store_safe:
    Same as `store`, except if the value to store is undefined, the
    memory region should be filled with 0xaa bytes, and any other
    safety metadata such as Valgrind integrations should be notified of
    this memory region being undefined.
    andrewrk committed Apr 25, 2023
    Configuration menu
    Copy the full SHA
    5378fdf View commit details
    Browse the repository at this point in the history
  19. Sema: fix memcpy alias safety incorrect math

    Previously it was not multiplying by the element ABI size. Now, it uses
    ptr_add instructions which do math based on the element type.
    andrewrk committed Apr 25, 2023
    Configuration menu
    Copy the full SHA
    792bbfa View commit details
    Browse the repository at this point in the history
  20. zig fmt

    andrewrk committed Apr 25, 2023
    Configuration menu
    Copy the full SHA
    401b7f6 View commit details
    Browse the repository at this point in the history
  21. C backend: fix lowering comparison when array ptr meets ptr

    Pointer comparisons were triggering `-Wcompare-distinct-pointer-types`
    before this fix, which adds `(void*)` casts if the lhs type and rhs type
    do not match pointer sizeness.
    andrewrk committed Apr 25, 2023
    Configuration menu
    Copy the full SHA
    badad16 View commit details
    Browse the repository at this point in the history