mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 04:48:20 +00:00
parent
775e055b59
commit
446deb31a8
32
src/Sema.zig
32
src/Sema.zig
@ -14286,6 +14286,38 @@ fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
|
||||
const src = inst_data.src();
|
||||
const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
|
||||
const operand_ty = try sema.resolveType(block, operand_src, inst_data.operand);
|
||||
switch (operand_ty.zigTypeTag()) {
|
||||
.Fn,
|
||||
.NoReturn,
|
||||
.Undefined,
|
||||
.Null,
|
||||
.BoundFn,
|
||||
.Opaque,
|
||||
=> return sema.fail(block, operand_src, "no size available for type '{}'", .{operand_ty.fmt(sema.mod)}),
|
||||
|
||||
.Type,
|
||||
.EnumLiteral,
|
||||
.ComptimeFloat,
|
||||
.ComptimeInt,
|
||||
.Void,
|
||||
=> return sema.addIntUnsigned(Type.comptime_int, 0),
|
||||
|
||||
.Bool,
|
||||
.Int,
|
||||
.Float,
|
||||
.Pointer,
|
||||
.Array,
|
||||
.Struct,
|
||||
.Optional,
|
||||
.ErrorUnion,
|
||||
.ErrorSet,
|
||||
.Enum,
|
||||
.Union,
|
||||
.Vector,
|
||||
.Frame,
|
||||
.AnyFrame,
|
||||
=> {},
|
||||
}
|
||||
const target = sema.mod.getTarget();
|
||||
const bit_size = try operand_ty.bitSizeAdvanced(target, sema.kit(block, src));
|
||||
return sema.addIntUnsigned(Type.comptime_int, bit_size);
|
||||
|
||||
@ -310,3 +310,7 @@ test "lazy size cast to float" {
|
||||
try expect(@as(f32, @sizeOf(S)) == 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
test "bitSizeOf comptime_int" {
|
||||
try expect(@bitSizeOf(comptime_int) == 0);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user