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

Using @TypeOf(x) as return type causes nothing to be emitted #22921

Open
Validark opened this issue Feb 17, 2025 · 2 comments
Open

Using @TypeOf(x) as return type causes nothing to be emitted #22921

Validark opened this issue Feb 17, 2025 · 2 comments
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness. regression It worked in a previous version of Zig, but stopped working.
Milestone

Comments

@Validark
Copy link
Contributor

Validark commented Feb 17, 2025

Zig Version

0.14.0-dev.3237+ddff1fa4c

Steps to Reproduce and Observed Behavior

This code fails to emit IR, seemingly because of the @TypeOf(s) (Godbolt)

export fn foo(s: u64) @TypeOf(s) {
    return s;
}

Expected Behavior

It should be equivalent to:

export fn foo(s: u64) u64 {
    return s;
}

The last working version of Zig I have on my machine is v0.14.0-dev.2851+b074fb7dd. The first broken version I have is v0.14.0-dev.3028+cdc9d65b0

@Validark Validark added the bug Observed behavior contradicts documented or intended behavior label Feb 17, 2025
@Vexu Vexu added the frontend Tokenization, parsing, AstGen, Sema, and Liveness. label Feb 17, 2025
@Vexu
Copy link
Member

Vexu commented Feb 17, 2025

LLVM backend stack trace

thread 553102 panic: attempt to use null value
/home/vexu/Documents/zig/zig/src/codegen/llvm.zig:1821:57: 0xa737ad0 in updateExports (zig)
        const global_index = self.nav_map.get(nav_index).?;
                                                        ^
/home/vexu/Documents/zig/zig/src/link/Elf.zig:2419:73: 0xa8fb822 in updateExports (zig)
    if (self.llvm_object) |llvm_object| return llvm_object.updateExports(pt, exported, export_indices);
                                                                        ^
/home/vexu/Documents/zig/zig/src/link.zig:865:85: 0xa7370ba in updateExports (zig)
                return @as(*tag.Type(), @fieldParentPtr("base", base)).updateExports(pt, exported, export_indices);
                                                                                    ^
/home/vexu/Documents/zig/zig/src/Zcu/PerThread.zig:2962:69: 0xa5a4dd4 in processExportsInner (zig)
        try zcu.handleUpdateExports(export_indices, lf.updateExports(pt, exported, export_indices));
                                                                    ^
/home/vexu/Documents/zig/zig/src/Zcu/PerThread.zig:2893:35: 0xa5a374d in processExports (zig)
        try pt.processExportsInner(&symbol_exports, exported, exports_list.items);
                                  ^
/home/vexu/Documents/zig/zig/src/Compilation.zig:2287:30: 0xa5af3c5 in update (zig)
        try pt.processExports();
                             ^
/home/vexu/Documents/zig/zig/src/main.zig:4500:20: 0xa5ed647 in updateModule (zig)
    try comp.update(prog_node);
                   ^
/home/vexu/Documents/zig/zig/src/main.zig:3690:21: 0xa6596e9 in buildOutputType (zig)
        updateModule(comp, color, root_prog_node) catch |err| switch (err) {
                    ^

Self hosted backend stack trace

error(link): NAV a.foo(InternPool.Nav.Index(225)) assigned symbol 14 but not allocated!
thread 553180 panic: reached unreachable code
/home/vexu/Documents/zig/zig/lib/std/debug.zig:518:14: 0xa510f1d in assert (zig)
    if (!ok) unreachable; // assertion failure
             ^
/home/vexu/Documents/zig/zig/src/link/Elf/ZigObject.zig:844:15: 0xaba7ce7 in updateSymtabSize (zig)
        assert(name.len > 0);
              ^
/home/vexu/Documents/zig/zig/src/link/Elf/file.zig:229:50: 0xaba861e in updateSymtabSize (zig)
            inline else => |x| x.updateSymtabSize(elf_file),
                                                 ^
/home/vexu/Documents/zig/zig/src/link/Elf.zig:3765:38: 0xabaa0e2 in updateSymtabSize (zig)
        try file_ptr.updateSymtabSize(self);
                                     ^
/home/vexu/Documents/zig/zig/src/link/Elf/relocatable.zig:294:34: 0xabe17f2 in updateSectionSizes (zig)
    try elf_file.updateSymtabSize();
                                 ^
/home/vexu/Documents/zig/zig/src/link/Elf/relocatable.zig:167:27: 0xabe7e40 in flushObject (zig)
    try updateSectionSizes(elf_file);
                          ^
/home/vexu/Documents/zig/zig/src/link/Elf.zig:854:47: 0xabef426 in flushModuleInner (zig)
        .Obj => return relocatable.flushObject(self, comp),
                                              ^
/home/vexu/Documents/zig/zig/src/link/Elf.zig:829:28: 0xa91ee31 in flushModule (zig)
    return flushModuleInner(self, arena, tid) catch |err| switch (err) {
                           ^
/home/vexu/Documents/zig/zig/src/link/Elf.zig:808:25: 0xa73a4b6 in flush (zig)
    try self.flushModule(arena, tid, prog_node);
                        ^
/home/vexu/Documents/zig/zig/src/link.zig:831:77: 0xa5abb0c in flush (zig)
                return @as(*tag.Type(), @fieldParentPtr("base", base)).flush(arena, tid, prog_node);
                                                                            ^
/home/vexu/Documents/zig/zig/src/Compilation.zig:2438:17: 0xa5ab466 in flush (zig)
        lf.flush(arena, tid, prog_node) catch |err| switch (err) {
                ^
/home/vexu/Documents/zig/zig/src/Compilation.zig:2398:22: 0xa5af671 in update (zig)
            try flush(comp, arena, .{
                     ^
/home/vexu/Documents/zig/zig/src/main.zig:4500:20: 0xa5ed647 in updateModule (zig)
    try comp.update(prog_node);
                   ^
/home/vexu/Documents/zig/zig/src/main.zig:3690:21: 0xa6596e9 in buildOutputType (zig)
        updateModule(comp, color, root_prog_node) catch |err| switch (err) {
                    ^

@Vexu Vexu added this to the 0.15.0 milestone Feb 17, 2025
@Validark
Copy link
Contributor Author

Hey @Vexu, do you think maybe this should go in the 0.14.0 milestone? This seems like a pretty critical bug.

@Vexu Vexu added the regression It worked in a previous version of Zig, but stopped working. label Feb 17, 2025
@Vexu Vexu modified the milestones: 0.15.0, 0.14.0 Feb 17, 2025
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. regression It worked in a previous version of Zig, but stopped working.
Projects
None yet
Development

No branches or pull requests

2 participants