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

fixes #20699; object variants with void fields crash with ORC #20703

Closed
wants to merge 1 commit into from

Conversation

ringabout
Copy link
Member

fixes #20699

Different from refc, ORC initializes object variants. If an object variant has void fields, it will get a wrong initial value. In fact, it shouldn't be assigned with a default value since the void field is eliminated from types.

@deech
Copy link
Contributor

deech commented Oct 30, 2022

Instead of omitting the struct initialization in the presence of a void why not have a special empty Void struct in the type declaration? That way it is more explicit. I think it's undefined behavior technically but compilers seem to support it.

typedef struct Void Void;
struct Void {};

typedef struct SomeObject SomeObject;
struct SomeObject {
  void* payload;
};

typedef struct Variant Variant;
struct Variant {
  char kind;
  union{
    Void _kind_1;  
    struct {
      SomeObject a;
    } _kind_2;
  };
};

static const Variant V = {0, {._kind_1 = {}}};

@bung87
Copy link
Collaborator

bung87 commented Oct 30, 2022

it's a large refactoring rather than fix one specific issue. nim-lang/RFCs#508

@ringabout ringabout closed this Nov 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Default value of object parameterized with a RootRef generates incorrect C
3 participants