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

Zero-bit types allowed in too many extern positions #21401

Open
wooster0 opened this issue Sep 13, 2024 · 3 comments
Open

Zero-bit types allowed in too many extern positions #21401

wooster0 opened this issue Sep 13, 2024 · 3 comments
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@wooster0
Copy link
Contributor

Zig Version

0.14.0-dev.1511+54b668f8a

Steps to Reproduce and Observed Behavior

extern const a: u0;

export fn x() void {
    var b: u0 = 0;
    @atomicStore(u0, &b, a, .unordered);
}
$ zig build-lib x.zig
error: Bitwidth for integer type out of range (Producer: 'zig 0.14.0' Reader: 'LLVM 18.1.8')

Expected Behavior

A successful compilation.

@wooster0 wooster0 added the bug Observed behavior contradicts documented or intended behavior label Sep 13, 2024
@alexrp
Copy link
Member

alexrp commented Sep 13, 2024

Wonder why this check (apparently?) isn't working:

if (!operand_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) return .none;

Aside: Doing nothing at all for the zero-sized case is very surprising behavior IMO. I would expect the instruction to at least result in a fence corresponding to the given ordering, even if no store actually takes place; the fence has implications for code other than the store itself. (And likewise for atomic loads.)

@Vexu
Copy link
Member

Vexu commented Sep 14, 2024

The problem is not with that check but with this one:
https://github.com/ziglang/zig/blob/4d81e8ee915c3e012131cf90ed87cc8c6a01a934/src/Sema.zig#L27601

Using u1 gives the expected error:

a.zig:1:17: error: extern variable cannot have type 'u1'
extern const a: u1;
                ^~
a.zig:1:17: note: only integers with 0, 8, 16, 32, 64 and 128 bits are extern compatible
referenced by:
    x: a.zig:4:17
    x: a.zig:3:1
    4 reference(s) hidden; use '-freference-trace=6' to see all references

@Vexu Vexu added the frontend Tokenization, parsing, AstGen, Sema, and Liveness. label Sep 14, 2024
@Vexu Vexu added this to the 0.14.0 milestone Sep 14, 2024
@Vexu Vexu changed the title LLVM erroring when passing extern u0 as value to @atomicStore Zero-bit types allowed in too many extern positions Sep 14, 2024
@Vexu
Copy link
Member

Vexu commented Sep 14, 2024

Regressed in #16404, fix is to check the position.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Projects
None yet
Development

No branches or pull requests

3 participants