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

langref: mark unsafe builtin functions #14543

Open
4 tasks
perillo opened this issue Feb 4, 2023 · 2 comments
Open
4 tasks

langref: mark unsafe builtin functions #14543

perillo opened this issue Feb 4, 2023 · 2 comments
Labels
Milestone

Comments

@perillo
Copy link
Contributor

perillo commented Feb 4, 2023

Some builtin functions can cause undefined behavior or subvert the Zig type system.
I think these builtin functions should be clearly marked.

Here is a list, probably incomplete:

  • @addrSpaceCast
    The documentation says that the operation may be illegal. What is the difference from undefined behavior?
    There is no documentation in the "Undefined Behavior" section.
  • @ptrCast
    The documentation says:
    "Casting an optional pointer which is null to a non-optional pointer invokes safety-checked Undefined Behavior".
    An additional warning is in the "volatile" section:
    "To convert one pointer type to another, use @ptrCast. This is an unsafe operation that Zig cannot protect you against."
    This is also documented in the "Undefined Behavior" section.
  • @alignCast
    Incorrect alignment is also documented in "Undefined Behavior" section.
  • @qualCast
    Warning about unsafe behavior is missing.
    Undefined behavior caused by @qualCast should probably be added to the "Undefined Behavior".
@rohlem
Copy link
Contributor

rohlem commented Feb 4, 2023

Potential sub-task of #1966 I think - marking every enumerated operation that it may be illegal probably makes sense for all of them.

@perillo
Copy link
Contributor Author

perillo commented Feb 4, 2023

Potential sub-task of #1966 I think - having back-links to note on each enumerated operation that it may be illegal probably makes sense in general.

Thanks. I have reported the new UB caused by @qualCast in that issue.

@Vexu Vexu added the docs label Feb 8, 2023
@Vexu Vexu added this to the 0.12.0 milestone Feb 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants