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

Support _Atomic in translate-c #11415

Open
iacore opened this issue Apr 11, 2022 · 5 comments
Open

Support _Atomic in translate-c #11415

iacore opened this issue Apr 11, 2022 · 5 comments
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. translate-c C to Zig source translation feature (@cImport)
Milestone

Comments

@iacore
Copy link
Contributor

iacore commented Apr 11, 2022

_Atomic data types are available in C11 that ensures atomic read and load. I'm not sure how to implement this in Zig.

Zig Version

0.10.0-dev.1427+ad5770eba

Steps to Reproduce

Save the text below as test.c:

_Atomic(int) hi;

Then run zig translate-c test.c.

Expected Behavior

No error

Actual Behavior

> zig translate-c test.c | grep hi
pub const hi = @compileError("unable to resolve variable type"); // test.c:1:14
@iacore iacore added the bug Observed behavior contradicts documented or intended behavior label Apr 11, 2022
@nektro
Copy link
Contributor

nektro commented Apr 12, 2022

@andrewrk andrewrk added enhancement Solving this issue will likely involve adding new logic or components to the codebase. translate-c C to Zig source translation feature (@cImport) and removed bug Observed behavior contradicts documented or intended behavior labels Apr 16, 2022
@andrewrk andrewrk added this to the 0.11.0 milestone Apr 16, 2022
@iacore
Copy link
Contributor Author

iacore commented Apr 18, 2022

The problem is that _Atomic is a type attribute, where @atomicLoad is usage of a term. If _Atomic(uint8_t) is translated to u8, then assignments to atomic variables need to use @atomicStore.

This is fine on x86 and some CPU architectures where load/store of register-sized integer is always atomic, but what problem will C non-compilance cause down the road? Should we even care about this? Maybe generate compile-time warnings is fine.

@daurnimator
Copy link
Contributor

Partially related #4248

@lorislibralato
Copy link
Contributor

Probably related #5101

@kayhayen
Copy link

kayhayen commented Mar 4, 2024

This affects Nuitka (the Python compiler) and Python 3.11 or higher. We as a project want to use zig as a backend C compiler, with long term hope of being able to use it exclusively. I am commenting here more follow. Writing a compiler myself, I know how hard this issue can be to solve for you, seeing a 0.15 milestone probably means, this will take a while.

Nuitka requires C11 more or less with modern Python.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. translate-c C to Zig source translation feature (@cImport)
Projects
None yet
Development

No branches or pull requests

6 participants