Description
Zig Version
0.10.0-dev.3050+e05487746
Steps to Reproduce
The following code fails to compile and causes a segmentation fault on linux x86_64 when run with zig test
pub const State = struct { label: ?u8 = null, out: ?*State = null, out1: ?*State = null };
pub const NFA = struct { initial: *State, accept: *State };
//return a string representing the dotviz
//representation of the NFA
fn printNFA(a: Allocator, n: NFA) ![]u8 {
var seen_set = StateSet.init(a);
var state_queue = ArrayList(*State).init(a);
var nfa_string = try fmt.allocPrint(a, "digraph G {{", .{});
var initial = n.initial;
try state_queue.append(initial);
while (state_queue.items.len > 0) {
var item = state_queue.items[0];
var split: u8 = '-';
if (seen_set.contains(item) == false) {
if (item.out != null) {
try state_queue.append(item.out.?);
nfa_string = try fmt.allocPrintZ(a, "{s} \n {c} -> {c}", .{ nfa_string, item.label orelse split, item.out.?.label orelse sp lit });
}
if (item.out1 != null) {
try state_queue.append(item.out1.?);
nfa_string = try fmt.allocPrintZ(a, "{s} \n {c} -> {c}", .{ nfa_string, item.label orelse split, item.out1.?.label orelse s plit });
}
try seen_set.put(item, true);
}
_ = state_queue.orderedRemove(0);
}
nfa_string = try fmt.allocPrint(a, "{s} }}", .{nfa_string});
return nfa_string;
}
test "printNFA test" {
var t = std.testing.allocator;
var arena = std.heap.ArenaAllocator.init(t);
defer arena.deinit();
var h = arena.allocator();
var c = State{ .label = 'c', .out = null, .out1 = null };
var b = State{ .label = 'b', .out = null, .out1 = null };
var a = State{ .label = 'a', .out = &b, .out1 = &c };
var nfa = NFA{ .initial = &a, .accept = &c };
var nfa_string = try printNFA(t, nfa);
var expected_nfa = "digraph G { a -> b \n a -> c }".*;
defer h.free(nfa_string);
try std.testing.expectEqualStrings(nfa_string, &expected_nfa);
}
Expected Behavior
i expect the code to compile or tell me what the error is , if any
Actual Behavior
broken LLVM module found: Instruction does not dominate all uses!
%68 = getelementptr inbounds %"struct:305:75", %"struct:305:75"* %10, i32 0, i32 1, !dbg !4329
store i8 %70, i8* %68, align 1, !dbg !4328
Instruction does not dominate all uses!
%76 = getelementptr inbounds %"struct:305:75", %"struct:305:75"* %10, i32 0, i32 2, !dbg !4332
store i8 %78, i8* %76, align 1, !dbg !4333
Instruction does not dominate all uses!
%108 = getelementptr inbounds %"struct:309:75", %"struct:309:75"* %15, i32 0, i32 1, !dbg !4346
store i8 %110, i8* %108, align 1, !dbg !4345
Instruction does not dominate all uses!
%116 = getelementptr inbounds %"struct:309:75", %"struct:309:75"* %15, i32 0, i32 2, !dbg !4349
store i8 %118, i8* %116, align 1, !dbg !4350
This is a bug in the Zig compiler.thread 8584 panic:
Unable to dump stack trace: debug info stripped