Skip to content

Implement clang bounds-safety attributes #921

Description

@ehaas

https://clang.llvm.org/docs/BoundsSafety.html

There's a lot here if you include the runtime checks and new builtins but I think it can be handled in chunks - my suggestion would be that we start with a flag like -fexperimental-bounds-safety and add some of the easier attributes first (single, bidi_indexable, terminated_by, etc). counted_by / sized_by might need parser changes because it looks like they can refer "forward" to identifiers which aren't defined yet:

void foo(int *__attribute__((counted_by(count))) p, size_t count) { ... }

This also adds compile time checking for certain types of pointers. For example single pointers can only be dereferenced or indexed with a constant value of 0.

Not all of the types will map cleanly to zig types - ended_by (pointer with another pointer as its upper bound) but this should allow us to translate things into Zig single pointers, slices, and sentinel-terminated slices.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions