Skip to content

Expression inside an anonymous struct literal causes invalid LLVM module #9908

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

Closed
ghost opened this issue Oct 6, 2021 · 3 comments
Closed
Labels
backend-llvm The LLVM backend outputs an LLVM IR Module. bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend.
Milestone

Comments

@ghost
Copy link

ghost commented Oct 6, 2021

test "repr" {

    var a: usize = 4321;
    var b: usize = 1234;

    const func = struct {
        fn func(arg: anytype) void {}
    }.func;

    func(.{ if (a < b) a else b });

}

Produces:

broken LLVM module found: Instruction does not dominate all uses!
  %6 = getelementptr inbounds %"struct:121:11", %"struct:121:11"* %1, i32 0, i32 0, !dbg !2628
  store i64 %7, i64* %6, align 8, !dbg !2629

This is a bug in the Zig compiler.thread 223064 panic: 
Unable to dump stack trace: debug info stripped
@ghost ghost changed the title Expression inside an anonymous struct blows up compiler. Expression inside an anonymous struct literal blows up compiler. Oct 6, 2021
@charles-l
Copy link
Contributor

charles-l commented Oct 12, 2021

This doesn't seem to blow up in the nightly build (as of 0.9.0-dev.1343+75cecef63), but it's still wrong for non-comptime booleans. E.g.

const std = @import("std");
const print = std.debug.print;
const process = std.process;

pub fn main() !void {
    var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
    defer arena.deinit();

    var args = process.args();
    _ = args.skip();
    var a = try std.fmt.parseInt(u8, try args.next(&arena.allocator).?, 10);
    var b = try std.fmt.parseInt(u8, try args.next(&arena.allocator).?, 10);
    print("{} < {} {}\n", .{ a, b, if (a < b) true else false });
}
$ zig run test.zig -- 1 2
1 < 2 true
$ zig run test.zig -- 2 1
2 < 1 true

@schmee
Copy link
Contributor

schmee commented Nov 15, 2021

Just ran in to this, the booleans being wrong is still a thing as of 0.9.0-dev.1625+d3a099c14 👍

@andrewrk andrewrk changed the title Expression inside an anonymous struct literal blows up compiler. Expression inside an anonymous struct literal causes invalid LLVM module Nov 20, 2021
@andrewrk andrewrk added backend-llvm The LLVM backend outputs an LLVM IR Module. bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend. labels Nov 20, 2021
@andrewrk andrewrk added this to the 0.10.0 milestone Nov 20, 2021
@Vexu
Copy link
Member

Vexu commented Jan 13, 2023

Duplicate of #3882

@Vexu Vexu marked this as a duplicate of #3882 Jan 13, 2023
@Vexu Vexu closed this as completed Jan 13, 2023
@andrewrk andrewrk modified the milestones: 0.12.0, 0.11.0 Jan 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend-llvm The LLVM backend outputs an LLVM IR Module. 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

4 participants