Skip to content

extern enums are unsafe #3991

Closed
Closed

Description

@LemonBoy
  • @intToEnum disables all the safety checks for extern unions, it should just de-duplicate the entries and validate the input data anyway.
  • @tagName produces invalid LLVM IR, eg:
broken LLVM module found: Duplicate integer as switch case
  switch i32 %0, label %BadValue [
    i32 1, label %Name
    i32 1, label %Name1
  ]

Activity

  1. added this to the 0.6.0 milestone on Dec 31, 2019
  2. added
    bug
    stage1
    on Dec 31, 2019
  3. andrewrk commented on Dec 31, 2019

    @andrewrk
    Member

    @intToEnum disables all the safety checks for extern unions, it should just de-duplicate the entries and validate the input data anyway.

    One of the accepted proposals was to allow extern enums to contain values that don't map to any particular tags. Idea being that they are non-exhaustive, and have the ABI size of the underlying integer tag type. This allows using extern enums in an ABI, and adding items later while remaining backwards-compatible.

    Happy to reconsider this if you are thinking of a potential issue with it?

    The broken switch thing is clearly a bug. I propose to resolve it by having the first tag name in declaration order be the canonical name.

  4. s-ol commented on Jan 25, 2020

    @s-ol
    Contributor

    I'm suddenly hitting the error that leads to this issue, and there is no traceback so I'm not sure what I shouldn't be doing:

    /usr/lib/zig/std/fmt.zig:372:31: error: TODO @tagName on non-exhaustive enum https://github.com/ziglang/zig/issues/3991
                return formatType(@tagName(value), "", options, context, Errors, output, max_depth);
    

    (this being a TODO is okay I guess, but it would be great if it left a full stack trace at least)

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

    bugstage1

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions