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

Broken deminance in produced llvm ir #8986

Open
espindola opened this issue Jun 4, 2021 · 0 comments
Open

Broken deminance in produced llvm ir #8986

espindola opened this issue Jun 4, 2021 · 0 comments
Labels
bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend.
Milestone

Comments

@espindola
Copy link

Given the program

const std = @import("std");
const fs = std.fs;
const io = std.io;
const PT_TLS = 7;

const PT_LOPROC = 0x70000000;
const PT_HIPROC = 0x7fffffff;

fn printProgramHeaderTypeName(t: u32, stdout: fs.File.Writer) !void {
    try switch (t) {
        PT_TLS => stdout.writeAll("foo"),
        PT_LOPROC...PT_HIPROC => stdout.print("bar", .{}),
        else => {
            return switch (t) {
                else => stdout.print("xyz", .{}),
            };
        },
    };
}

pub fn main() !void {
    const stdout = io.getStdOut().writer();
    try printProgramHeaderTypeName(42, stdout);
}

A debug build of zig at 11ae6c4 produces invalid LLVM IR, resulting in the error:

broken LLVM module found: Instruction does not dominate all uses!td.os.WriteError,st...
  %12 = call fastcc i16 @"std.io.writer.Writer(std.fs.file.File,std.os.WriteError,std.fs.file.File.write).print.166"(%std.builtin.StackTrace* %0, %"std.io.writer.Writer(std.fs.file.File,std.os.WriteError,std.fs.file.File.write)"* %2), !dbg !18191
  store i16 %12, i16* %4, align 2, !dbg !18184
Instruction does not dominate all uses!
  %12 = call fastcc i16 @"std.io.writer.Writer(std.fs.file.File,std.os.WriteError,std.fs.file.File.write).print.166"(%std.builtin.StackTrace* %0, %"std.io.writer.Writer(std.fs.file.File,std.os.WriteError,std.fs.file.File.write)"* %2), !dbg !18191
  %13 = icmp ne i16 %12, 0, !dbg !18192

The backtrace is:

#0  0x00007ffff787cd22 in raise () from /usr/lib/libc.so.6
#1  0x00007ffff7866862 in abort () from /usr/lib/libc.so.6
#2  0x0000555556b93269 in std.os.abort () at /home/espindola/zig/zig/lib/std/os.zig:233
#3  0x0000555556b9dcab in std.debug.panicExtra (trace=0x0, first_trace_addr=..., args=...) at /home/espindola/zig/zig/lib/std/debug.zig:305
#4  0x0000555556b8efeb in std.builtin.default_panic (msg=..., error_return_trace=0x0) at /home/espindola/zig/zig/lib/std/builtin.zig:690
#5  0x0000555556b9fe28 in stage2_panic (ptr=0x55556015b94c "", len=0) at /home/espindola/zig/zig/src/stage1.zig:171
#6  0x00005555577064bd in zig_panic (format=0x55556015d9a0 "broken LLVM module found: %s\nThis is a bug in the Zig compiler.") at ../src/stage1/util.cpp:20
#7  0x000055555772c6c5 in do_code_gen (g=0x555568805550) at ../src/stage1/codegen.cpp:8489
#8  0x00005555577314e8 in codegen_build_object (g=0x555568805550) at ../src/stage1/codegen.cpp:9641
#9  0x00005555577023cc in zig_stage1_build_object (stage1=0x555568805550) at ../src/stage1/stage1.cpp:130
#10 0x0000555556f41af5 in Module.build_object (mod=0x555568805550) at /home/espindola/zig/zig/src/stage1.zig:143
#11 0x0000555556d2de15 in Compilation.updateStage1Module (comp=0x555568803148, main_progress_node=0x7fffffff8be8) at /home/espindola/zig/zig/src/Compilation.zig:3950
#12 0x0000555556d05401 in Compilation.performAllTheWork (self=0x555568803148) at /home/espindola/zig/zig/src/Compilation.zig:2232
#13 0x0000555556cff4db in Compilation.update (self=0x555568803148) at /home/espindola/zig/zig/src/Compilation.zig:1631
#14 0x0000555556c99e60 in main.updateModule (gpa=0x5555686daef0 <c_allocator_state>, comp=0x555568803148, hook=...) at /home/espindola/zig/zig/src/main.zig:2255
#15 0x0000555556bc9033 in main.buildOutputType (gpa=0x5555686daef0 <c_allocator_state>, arena=0x7fffffffe5b8, all_args=..., arg_mode=...) at /home/espindola/zig/zig/src/main.zig:1987
#16 0x0000555556b9e398 in main.mainArgs (gpa=0x5555686daef0 <c_allocator_state>, arena=0x7fffffffe5b8, args=...) at /home/espindola/zig/zig/src/main.zig:202
#17 0x0000555556b9ddda in main (argc=3, argv=0x7fffffffe7f8) at /home/espindola/zig/zig/src/stage1.zig:45
@espindola espindola changed the title Broken deminance is produced llvm ir Broken deminance in produced llvm ir Jun 4, 2021
@Vexu Vexu added bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend. labels Jun 4, 2021
@Vexu Vexu added this to the 0.10.0 milestone Jun 4, 2021
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 stage1 The process of building from source via WebAssembly and the C backend.
Projects
None yet
Development

No branches or pull requests

2 participants