Skip to content

zig cc exe OFFSETOF macro crash #9528

Closed
@leonardo-ourmachinery

Description

zig 0.9

This code just crashes if compiled with zig cc -g

#include <stddef.h>
typedef struct foo
{
    int a;
}foo;

#define OFFSETOF(TYPE, ELEMENT) ((size_t)&(((TYPE *)0)->ELEMENT))

int main(int argc, char** argv)
{
    int offset = OFFSETOF(foo, a);
    (void) offset;
    
    return 0;
}

the crash happens on the OFFSETOF line:
Unhandled exception at 0x00007FF6955A100F in a.exe: 0xC000001D: Illegal Instruction.

The problem manifested in a dll compiled with zig cc in a slightly different way, but the crash is exactly the same so I suppose the root cause of the problem is the same:

image

I tried to isolate the problem and arrived at the small program that I posted above, hope it helps.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions