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

No compile errors with -fno-emit-bin if c files in the build #22682

Open
leecannon opened this issue Jan 30, 2025 · 1 comment
Open

No compile errors with -fno-emit-bin if c files in the build #22682

leecannon opened this issue Jan 30, 2025 · 1 comment
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@leecannon
Copy link
Contributor

leecannon commented Jan 30, 2025

Zig Version

0.14.0-dev.2989+bf6ee7cb3

Steps to Reproduce and Observed Behavior

With an empty c file called empty.c and main.zig containing:

pub fn main() void {
    const a: bool = 2;
    _ = a;
}
$ zig build-exe -fno-emit-bin empty.c main.zig
$ echo $?                                                           
0

The correct behavior occurs without the c file:

$ zig build-exe -fno-emit-bin main.zig  
main.zig:2:21: error: expected type 'bool', found 'comptime_int'
    const a: bool = 2;
                    ^
referenced by:
    posixCallMainAndExit: /home/lee/zig/0.14.0-dev.2989+bf6ee7cb3/files/lib/std/start.zig:656:37
    _start: /home/lee/zig/0.14.0-dev.2989+bf6ee7cb3/files/lib/std/start.zig:464:40
    3 reference(s) hidden; use '-freference-trace=5' to see all references
$ echo $?                                             
1

Expected Behavior

The same error as without -fno-emit-bin:

$ zig build-exe empty.c main.zig              
main.zig:2:21: error: expected type 'bool', found 'comptime_int'
    const a: bool = 2;
                    ^
referenced by:
    posixCallMainAndExit: /home/lee/zig/0.14.0-dev.2989+bf6ee7cb3/files/lib/std/start.zig:656:37
    _start: /home/lee/zig/0.14.0-dev.2989+bf6ee7cb3/files/lib/std/start.zig:464:40
    3 reference(s) hidden; use '-freference-trace=5' to see all references
$ echo $?                                                           
1
@leecannon leecannon added the bug Observed behavior contradicts documented or intended behavior label Jan 30, 2025
@leecannon leecannon changed the title -fno-emit-bin does not report compile errors when c files included in build No compile errors with -fno-emit-bin if c files in the build Feb 3, 2025
@leecannon
Copy link
Contributor Author

This issue is caused by comp.remaining_prelink_tasks being incremented here

comp.remaining_prelink_tasks += @intCast(comp.c_object_table.count());
but it is never decremented so performAllTheWorkInner returns early

zig/src/Compilation.zig

Lines 3852 to 3855 in 08d661f

if (comp.remaining_prelink_tasks > 0) {
// Indicates an error occurred preventing prelink phase from completing.
return;
}
but no error has been emitted so compilation exits without reporting failure.

But I'm struggling to follow through the logic to actually get to the bottom of this.

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
Projects
None yet
Development

No branches or pull requests

1 participant