Repository navigation
Open
Description
Zig Version
0.10.0-dev.3659+e5e6eb983
Steps to Reproduce
Run zig test file.zig where file has the following zig code:
const std = @import("std");
fn Bomb(types: []const type) type {
const TriggerBombType = blk: {
const Type = std.builtin.Type;
var struct_fields: [types.len]Type.StructField = undefined;
inline for (types) |T, i| {
const ArrT = std.ArrayList(T);
var num_buf: [8]u8 = undefined;
struct_fields[i] = .{
.name = std.fmt.bufPrint(&num_buf, "{d}", .{i}) catch unreachable,
.field_type = if (@sizeOf(T) > 0) ArrT else T,
.default_value = null,
.is_comptime = false,
.alignment = if (@sizeOf(T) > 0) @alignOf(ArrT) else 0,
};
}
const RtrTypeInfo = Type{ .Struct = .{
.layout = .Auto,
.fields = &struct_fields,
.decls = &[0]Type.Declaration{},
.is_tuple = true,
} };
break :blk @Type(RtrTypeInfo);
};
@compileLog(@sizeOf(TriggerBombType)); // boom (segmentation fault)
return struct {};
}
test "trigger bug" {
const A = struct {};
const B = struct { b: i32 };
const Explosion = Bomb(&[_]type{ A, B });
_ = Explosion;
}Expected Behavior
Compiler to print the size of generated type and fail because of the compileLog
Actual Behavior
$ zig test file.zig
Segmentation faultAlso in the original code where i detected this issue (ecez) I get the following error:
zig test src/archetype.zig
LLVM Emit Object... warning: stack frame size (8589934760) exceeds limit (4294967295) in function 'archetype.test.init() produce expected arche type'
Test [1/17] test.init() produce expected arche type... Stack Overflow
error: the following test command failed with exit code 3:
src\zig-cache\o\f185d8eaf05ee1cfa06939f009e64792\test.exe C:\Program Files\Zig\zig.exepresumably because the type generated with a similar mechanism is garbage
Activity
Avokadoen commentedon Jan 5, 2023
@Vexu @andrewrk I have never contributed to the compiler directly before, but if I got a few hints of what the issue might be, then I would be willing to attempt to solve this issue as it has blocked my progress for a while now.
Vexu commentedon Jan 5, 2023
The bug has already been fixed and the only thing remaining for this issue is to add a test.
Avokadoen commentedon Jan 5, 2023
That is great news! Cheers! 🎉