authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-11-07 14:17:26+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-01-09 13:52:37-07:00
log6ea3d3e19fce2317e8d7e60a78307f16f2538d72
treebe0d8fd8353e7bef9295f59bf86042fc4c2f7935
parent6a94bcbbc6fdd4cd33981f924a7bd27773889e53

Merge pull request #13446 from Vexu/stage2-fixes

Stage2 bug fixes

12 files changed, 275 insertions(+), 46 deletions(-)

src/Sema.zig+109-29
......@@ -1917,6 +1917,7 @@ fn resolveMaybeUndefValAllowVariablesMaybeRuntime(
19171917 const ty_pl = sema.air_instructions.items(.data)[i].ty_pl;
19181918 const val = sema.air_values.items[ty_pl.payload];
19191919 if (val.tag() == .runtime_value) make_runtime.* = true;
1920 if (val.isPtrToThreadLocal(sema.mod)) make_runtime.* = true;
19201921 return val;
19211922 },
19221923 .const_ty => {
......@@ -4380,7 +4381,7 @@ fn zirValidateArrayInit(
43804381 var block_index = block.instructions.items.len - 1;
43814382 while (block.instructions.items[block_index] != elem_ptr_air_inst) {
43824383 if (block_index == 0) {
4383 array_is_comptime = true;
4384 array_is_comptime = false;
43844385 continue :outer;
43854386 }
43864387 block_index -= 1;
......@@ -10343,6 +10344,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1034310344 }
1034410345 if (err_set) try sema.maybeErrorUnwrapComptime(&child_block, special.body, operand);
1034510346 if (special.is_inline) child_block.inline_case_capture = operand;
10347 if (empty_enum) {
10348 return Air.Inst.Ref.void_value;
10349 }
1034610350 return sema.resolveBlockBody(block, src, &child_block, special.body, inst, merges);
1034710351 }
1034810352
......@@ -11992,10 +11996,18 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1199211996 const element_vals = try sema.arena.alloc(Value, final_len_including_sent);
1199311997 var elem_i: usize = 0;
1199411998 while (elem_i < lhs_len) : (elem_i += 1) {
11995 element_vals[elem_i] = try lhs_sub_val.elemValue(sema.mod, sema.arena, elem_i);
11999 const elem_val = try lhs_sub_val.elemValue(sema.mod, sema.arena, elem_i);
12000 const elem_val_inst = try sema.addConstant(lhs_info.elem_type, elem_val);
12001 const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, .unneeded);
12002 const coereced_elem_val = try sema.resolveConstMaybeUndefVal(block, .unneeded, coerced_elem_val_inst, "");
12003 element_vals[elem_i] = coereced_elem_val;
1199612004 }
1199712005 while (elem_i < result_len) : (elem_i += 1) {
11998 element_vals[elem_i] = try rhs_sub_val.elemValue(sema.mod, sema.arena, elem_i - lhs_len);
12006 const elem_val = try rhs_sub_val.elemValue(sema.mod, sema.arena, elem_i - lhs_len);
12007 const elem_val_inst = try sema.addConstant(lhs_info.elem_type, elem_val);
12008 const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, .unneeded);
12009 const coereced_elem_val = try sema.resolveConstMaybeUndefVal(block, .unneeded, coerced_elem_val_inst, "");
12010 element_vals[elem_i] = coereced_elem_val;
1199912011 }
1200012012 if (res_sent_val) |sent_val| {
1200112013 element_vals[result_len] = sent_val;
......@@ -12469,10 +12481,12 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1246912481
1247012482 if (maybe_rhs_val) |rhs_val| {
1247112483 if (is_int) {
12472 return sema.addConstant(
12473 resolved_type,
12474 try lhs_val.intDiv(rhs_val, resolved_type, sema.arena, target),
12475 );
12484 const res = try lhs_val.intDiv(rhs_val, resolved_type, sema.arena, target);
12485 var vector_index: usize = undefined;
12486 if (!(try sema.intFitsInType(block, src, res, resolved_type, &vector_index))) {
12487 return sema.failWithIntegerOverflow(block, src, resolved_type, res, vector_index);
12488 }
12489 return sema.addConstant(resolved_type, res);
1247612490 } else {
1247712491 return sema.addConstant(
1247812492 resolved_type,
......@@ -12584,10 +12598,12 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1258412598 if (modulus_val.compareWithZero(.neq)) {
1258512599 return sema.fail(block, src, "exact division produced remainder", .{});
1258612600 }
12587 return sema.addConstant(
12588 resolved_type,
12589 try lhs_val.intDiv(rhs_val, resolved_type, sema.arena, target),
12590 );
12601 const res = try lhs_val.intDiv(rhs_val, resolved_type, sema.arena, target);
12602 var vector_index: usize = undefined;
12603 if (!(try sema.intFitsInType(block, src, res, resolved_type, &vector_index))) {
12604 return sema.failWithIntegerOverflow(block, src, resolved_type, res, vector_index);
12605 }
12606 return sema.addConstant(resolved_type, res);
1259112607 } else {
1259212608 const modulus_val = try lhs_val.floatMod(rhs_val, resolved_type, sema.arena, target);
1259312609 if (modulus_val.compareWithZero(.neq)) {
......@@ -12862,10 +12878,12 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1286212878
1286312879 if (maybe_rhs_val) |rhs_val| {
1286412880 if (is_int) {
12865 return sema.addConstant(
12866 resolved_type,
12867 try lhs_val.intDiv(rhs_val, resolved_type, sema.arena, target),
12868 );
12881 const res = try lhs_val.intDiv(rhs_val, resolved_type, sema.arena, target);
12882 var vector_index: usize = undefined;
12883 if (!(try sema.intFitsInType(block, src, res, resolved_type, &vector_index))) {
12884 return sema.failWithIntegerOverflow(block, src, resolved_type, res, vector_index);
12885 }
12886 return sema.addConstant(resolved_type, res);
1286912887 } else {
1287012888 return sema.addConstant(
1287112889 resolved_type,
......@@ -22457,7 +22475,10 @@ fn fieldVal(
2245722475 } else (try sema.mod.getErrorValue(field_name)).key;
2245822476
2245922477 return sema.addConstant(
22460 try child_type.copy(arena),
22478 if (!child_type.isAnyError())
22479 try child_type.copy(arena)
22480 else
22481 try Type.Tag.error_set_single.create(arena, name),
2246122482 try Value.Tag.@"error".create(arena, .{ .name = name }),
2246222483 );
2246322484 },
......@@ -22668,7 +22689,10 @@ fn fieldPtr(
2266822689 var anon_decl = try block.startAnonDecl(src);
2266922690 defer anon_decl.deinit();
2267022691 return sema.analyzeDeclRef(try anon_decl.finish(
22671 try child_type.copy(anon_decl.arena()),
22692 if (!child_type.isAnyError())
22693 try child_type.copy(anon_decl.arena())
22694 else
22695 try Type.Tag.error_set_single.create(anon_decl.arena(), name),
2267222696 try Value.Tag.@"error".create(anon_decl.arena(), .{ .name = name }),
2267322697 0, // default alignment
2267422698 ));
......@@ -22827,6 +22851,7 @@ fn fieldCallBind(
2282722851 {
2282822852 const first_param_type = decl_type.fnParamType(0);
2282922853 const first_param_tag = first_param_type.tag();
22854 var opt_buf: Type.Payload.ElemType = undefined;
2283022855 // zig fmt: off
2283122856 if (first_param_tag == .var_args_param or
2283222857 first_param_tag == .generic_poison or (
......@@ -22845,7 +22870,27 @@ fn fieldCallBind(
2284522870 });
2284622871 return sema.addConstant(ty, value);
2284722872 } else if (first_param_type.eql(concrete_ty, sema.mod)) {
22848 var deref = try sema.analyzeLoad(block, src, object_ptr, src);
22873 const deref = try sema.analyzeLoad(block, src, object_ptr, src);
22874 const ty = Type.Tag.bound_fn.init();
22875 const value = try Value.Tag.bound_fn.create(arena, .{
22876 .func_inst = decl_val,
22877 .arg0_inst = deref,
22878 });
22879 return sema.addConstant(ty, value);
22880 } else if (first_param_tag != .generic_poison and first_param_type.zigTypeTag() == .Optional and
22881 first_param_type.optionalChild(&opt_buf).eql(concrete_ty, sema.mod))
22882 {
22883 const deref = try sema.analyzeLoad(block, src, object_ptr, src);
22884 const ty = Type.Tag.bound_fn.init();
22885 const value = try Value.Tag.bound_fn.create(arena, .{
22886 .func_inst = decl_val,
22887 .arg0_inst = deref,
22888 });
22889 return sema.addConstant(ty, value);
22890 } else if (first_param_tag != .generic_poison and first_param_type.zigTypeTag() == .ErrorUnion and
22891 first_param_type.errorUnionPayload().eql(concrete_ty, sema.mod))
22892 {
22893 const deref = try sema.analyzeLoad(block, src, object_ptr, src);
2284922894 const ty = Type.Tag.bound_fn.init();
2285022895 const value = try Value.Tag.bound_fn.create(arena, .{
2285122896 .func_inst = decl_val,
......@@ -28763,6 +28808,13 @@ fn resolvePeerTypes(
2876328808 }
2876428809 }
2876528810 },
28811 .Fn => {
28812 if (!cand_info.mutable and cand_info.pointee_type.zigTypeTag() == .Fn and .ok == try sema.coerceInMemoryAllowedFns(block, chosen_ty, cand_info.pointee_type, target, src, src)) {
28813 chosen = candidate;
28814 chosen_i = candidate_i + 1;
28815 continue;
28816 }
28817 },
2876628818 else => {},
2876728819 }
2876828820 },
......@@ -28793,6 +28845,11 @@ fn resolvePeerTypes(
2879328845 .Vector => continue,
2879428846 else => {},
2879528847 },
28848 .Fn => if (chosen_ty.isSinglePointer() and chosen_ty.isConstPtr() and chosen_ty.childType().zigTypeTag() == .Fn) {
28849 if (.ok == try sema.coerceInMemoryAllowedFns(block, chosen_ty.childType(), candidate_ty, target, src, src)) {
28850 continue;
28851 }
28852 },
2879628853 else => {},
2879728854 }
2879828855
......@@ -30440,23 +30497,23 @@ pub fn typeHasOnePossibleValue(
3044030497 if (enum_obj.tag_ty.hasRuntimeBits()) {
3044130498 return null;
3044230499 }
30443 if (enum_obj.fields.count() == 1) {
30444 if (enum_obj.values.count() == 0) {
30500 switch (enum_obj.fields.count()) {
30501 0 => return Value.initTag(.unreachable_value),
30502 1 => if (enum_obj.values.count() == 0) {
3044530503 return Value.zero; // auto-numbered
3044630504 } else {
3044730505 return enum_obj.values.keys()[0];
30448 }
30449 } else {
30450 return null;
30506 },
30507 else => return null,
3045130508 }
3045230509 },
3045330510 .enum_simple => {
3045430511 const resolved_ty = try sema.resolveTypeFields(block, src, ty);
3045530512 const enum_simple = resolved_ty.castTag(.enum_simple).?.data;
30456 if (enum_simple.fields.count() == 1) {
30457 return Value.zero;
30458 } else {
30459 return null;
30513 switch (enum_simple.fields.count()) {
30514 0 => return Value.initTag(.unreachable_value),
30515 1 => return Value.zero,
30516 else => return null,
3046030517 }
3046130518 },
3046230519 .enum_nonexhaustive => {
......@@ -30473,7 +30530,7 @@ pub fn typeHasOnePossibleValue(
3047330530 const tag_val = (try sema.typeHasOnePossibleValue(block, src, union_obj.tag_ty)) orelse
3047430531 return null;
3047530532 const fields = union_obj.fields.values();
30476 if (fields.len == 0) return Value.initTag(.empty_struct_value);
30533 if (fields.len == 0) return Value.initTag(.unreachable_value);
3047730534 const only_field = fields[0];
3047830535 if (only_field.ty.eql(resolved_ty, sema.mod)) {
3047930536 const msg = try Module.ErrorMsg.create(
......@@ -32036,15 +32093,36 @@ fn elemPtrType(sema: *Sema, ptr_ty: Type, offset: ?usize) !Type {
3203632093 const ptr_info = ptr_ty.ptrInfo().data;
3203732094 const elem_ty = ptr_ty.elemType2();
3203832095 const allow_zero = ptr_info.@"allowzero" and (offset orelse 0) == 0;
32096 const target = sema.mod.getTarget();
32097 const parent_ty = ptr_ty.childType();
32098
32099 const vector_info: struct {
32100 host_size: u16,
32101 bit_offset: u16,
32102 alignment: u32,
32103 } = if (parent_ty.tag() == .vector) blk: {
32104 const elem_bits = elem_ty.bitSize(target);
32105 const is_packed = elem_bits != 0 and (elem_bits & (elem_bits - 1)) != 0;
32106 // TODO: runtime-known index
32107 assert(!is_packed or offset != null);
32108 const is_packed_with_offset = is_packed and offset != null and offset.? != 0;
32109 const target_offset = if (is_packed_with_offset) (if (target.cpu.arch.endian() == .Big) (parent_ty.vectorLen() - 1 - offset.?) else offset.?) else 0;
32110 break :blk .{
32111 .host_size = if (is_packed_with_offset) @intCast(u16, parent_ty.abiSize(target)) else 0,
32112 .bit_offset = if (is_packed_with_offset) @intCast(u16, elem_bits * target_offset) else 0,
32113 .alignment = if (is_packed_with_offset) @intCast(u16, parent_ty.abiAlignment(target)) else 0,
32114 };
32115 } else .{ .host_size = 0, .bit_offset = 0, .alignment = 0 };
32116
3203932117 const alignment: u32 = a: {
3204032118 // Calculate the new pointer alignment.
3204132119 if (ptr_info.@"align" == 0) {
32120 if (vector_info.alignment != 0) break :a vector_info.alignment;
3204232121 // ABI-aligned pointer. Any pointer arithmetic maintains the same ABI-alignedness.
3204332122 break :a 0;
3204432123 }
3204532124 // If the addend is not a comptime-known value we can still count on
3204632125 // it being a multiple of the type size.
32047 const target = sema.mod.getTarget();
3204832126 const elem_size = elem_ty.abiSize(target);
3204932127 const addend = if (offset) |off| elem_size * off else elem_size;
3205032128
......@@ -32061,5 +32139,7 @@ fn elemPtrType(sema: *Sema, ptr_ty: Type, offset: ?usize) !Type {
3206132139 .@"allowzero" = allow_zero,
3206232140 .@"volatile" = ptr_info.@"volatile",
3206332141 .@"align" = alignment,
32142 .host_size = vector_info.host_size,
32143 .bit_offset = vector_info.bit_offset,
3206432144 });
3206532145}
src/type.zig+16-17
......@@ -3574,15 +3574,13 @@ pub const Type = extern union {
35743574 .u128, .i128, .f128 => return 128,
35753575
35763576 .@"struct" => {
3577 if (sema_kit) |sk| _ = try sk.sema.resolveTypeFields(sk.block, sk.src, ty);
3578 if (ty.containerLayout() != .Packed) {
3577 const struct_obj = ty.castTag(.@"struct").?.data;
3578 if (struct_obj.layout != .Packed) {
35793579 return (try ty.abiSizeAdvanced(target, if (sema_kit) |sk| .{ .sema_kit = sk } else .eager)).scalar * 8;
35803580 }
3581 var total: u64 = 0;
3582 for (ty.structFields().values()) |field| {
3583 total += try bitSizeAdvanced(field.ty, target, sema_kit);
3584 }
3585 return total;
3581 if (sema_kit) |sk| _ = try sk.sema.resolveTypeLayout(sk.block, sk.src, ty);
3582 assert(struct_obj.haveLayout());
3583 return try struct_obj.backing_int_ty.bitSizeAdvanced(target, sema_kit);
35863584 },
35873585
35883586 .tuple, .anon_struct => {
......@@ -5015,22 +5013,22 @@ pub const Type = extern union {
50155013 if (enum_full.tag_ty.hasRuntimeBits()) {
50165014 return null;
50175015 }
5018 if (enum_full.fields.count() == 1) {
5019 if (enum_full.values.count() == 0) {
5020 return Value.zero;
5016 switch (enum_full.fields.count()) {
5017 0 => return Value.initTag(.unreachable_value),
5018 1 => if (enum_full.values.count() == 0) {
5019 return Value.zero; // auto-numbered
50215020 } else {
50225021 return enum_full.values.keys()[0];
5023 }
5024 } else {
5025 return null;
5022 },
5023 else => return null,
50265024 }
50275025 },
50285026 .enum_simple => {
50295027 const enum_simple = ty.castTag(.enum_simple).?.data;
5030 if (enum_simple.fields.count() == 1) {
5031 return Value.zero;
5032 } else {
5033 return null;
5028 switch (enum_simple.fields.count()) {
5029 0 => return Value.initTag(.unreachable_value),
5030 1 => return Value.zero,
5031 else => return null,
50345032 }
50355033 },
50365034 .enum_nonexhaustive => {
......@@ -5044,6 +5042,7 @@ pub const Type = extern union {
50445042 .@"union", .union_safety_tagged, .union_tagged => {
50455043 const union_obj = ty.cast(Payload.Union).?.data;
50465044 const tag_val = union_obj.tag_ty.onePossibleValue() orelse return null;
5045 if (union_obj.fields.count() == 0) return Value.initTag(.unreachable_value);
50475046 const only_field = union_obj.fields.values()[0];
50485047 const val_val = only_field.ty.onePossibleValue() orelse return null;
50495048 _ = tag_val;
src/value.zig+23
......@@ -2806,6 +2806,29 @@ pub const Value = extern union {
28062806 };
28072807 }
28082808
2809 pub fn isPtrToThreadLocal(val: Value, mod: *Module) bool {
2810 return switch (val.tag()) {
2811 .variable => false,
2812 else => val.isPtrToThreadLocalInner(mod),
2813 };
2814 }
2815
2816 fn isPtrToThreadLocalInner(val: Value, mod: *Module) bool {
2817 return switch (val.tag()) {
2818 .slice => val.castTag(.slice).?.data.ptr.isPtrToThreadLocalInner(mod),
2819 .comptime_field_ptr => val.castTag(.comptime_field_ptr).?.data.field_val.isPtrToThreadLocalInner(mod),
2820 .elem_ptr => val.castTag(.elem_ptr).?.data.array_ptr.isPtrToThreadLocalInner(mod),
2821 .field_ptr => val.castTag(.field_ptr).?.data.container_ptr.isPtrToThreadLocalInner(mod),
2822 .eu_payload_ptr => val.castTag(.eu_payload_ptr).?.data.container_ptr.isPtrToThreadLocalInner(mod),
2823 .opt_payload_ptr => val.castTag(.opt_payload_ptr).?.data.container_ptr.isPtrToThreadLocalInner(mod),
2824 .decl_ref => mod.declPtr(val.castTag(.decl_ref).?.data).val.isPtrToThreadLocalInner(mod),
2825 .decl_ref_mut => mod.declPtr(val.castTag(.decl_ref_mut).?.data.decl_index).val.isPtrToThreadLocalInner(mod),
2826
2827 .variable => val.castTag(.variable).?.data.is_threadlocal,
2828 else => false,
2829 };
2830 }
2831
28092832 // Asserts that the provided start/end are in-bounds.
28102833 pub fn sliceArray(
28112834 val: Value,
test/behavior/array.zig+22
......@@ -574,3 +574,25 @@ test "tuple to array handles sentinel" {
574574 };
575575 try expect(S.b[0] == 1);
576576}
577
578test "array init of container level array variable" {
579 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
580 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
581 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
582
583 const S = struct {
584 var pair: [2]usize = .{ 1, 2 };
585 noinline fn foo(x: usize, y: usize) void {
586 pair = [2]usize{ x, y };
587 }
588 noinline fn bar(x: usize, y: usize) void {
589 var tmp: [2]usize = .{ x, y };
590 pair = tmp;
591 }
592 };
593 try expectEqual([2]usize{ 1, 2 }, S.pair);
594 S.foo(3, 4);
595 try expectEqual([2]usize{ 3, 4 }, S.pair);
596 S.bar(5, 6);
597 try expectEqual([2]usize{ 5, 6 }, S.pair);
598}
test/behavior/cast.zig+10
......@@ -1419,3 +1419,13 @@ test "floatToInt to zero-bit int" {
14191419 var a: f32 = 0.0;
14201420 comptime try std.testing.expect(@floatToInt(u0, a) == 0);
14211421}
1422
1423test "peer type resolution of function pointer and function body" {
1424 if (builtin.zig_backend == .stage1) return error.SkipZigTest;
1425
1426 const T = fn () u32;
1427 const a: T = undefined;
1428 const b: *const T = undefined;
1429 try expect(@TypeOf(a, b) == *const fn () u32);
1430 try expect(@TypeOf(b, a) == *const fn () u32);
1431}
test/behavior/empty_union.zig+18
......@@ -48,3 +48,21 @@ test "empty extern union" {
4848 try expect(@sizeOf(U) == 0);
4949 try expect(@alignOf(U) == 1);
5050}
51
52test "empty union passed as argument" {
53 const U = union(enum) {
54 fn f(u: @This()) void {
55 switch (u) {}
56 }
57 };
58 U.f(@as(U, undefined));
59}
60
61test "empty enum passed as argument" {
62 const E = enum {
63 fn f(e: @This()) void {
64 switch (e) {}
65 }
66 };
67 E.f(@as(E, undefined));
68}
test/behavior/error.zig+10
......@@ -855,3 +855,13 @@ test "error from comptime string" {
855855 try expect(mem.eql(u8, name, @errorName(err)));
856856 }
857857}
858
859test "field access of anyerror results in smaller error set" {
860 if (builtin.zig_backend == .stage1) return error.SkipZigTest;
861
862 const E1 = @TypeOf(error.Foo);
863 try expect(@TypeOf(E1.Foo) == E1);
864 const E2 = error{ A, B, C };
865 try expect(@TypeOf(E2.A) == E2);
866 try expect(@TypeOf(@field(anyerror, "NotFound")) == error{NotFound});
867}
test/behavior/eval.zig+11
......@@ -1488,3 +1488,14 @@ test "x or true is comptime-known true" {
14881488 }
14891489 try expect(T.x == 3);
14901490}
1491
1492test "non-optional and optional array elements concatenated" {
1493 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
1494 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
1495 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
1496 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
1497
1498 const array = [1]u8{'A'} ++ [1]?u8{null};
1499 var index: usize = 0;
1500 try expect(array[index].? == 'A');
1501}
test/behavior/fn.zig+19
......@@ -434,3 +434,22 @@ test "implicit cast function to function ptr" {
434434 var fnPtr2: *const fn () callconv(.C) c_int = S2.someFunctionThatReturnsAValue;
435435 try expect(fnPtr2() == 123);
436436}
437
438test "method call with optional and error union first param" {
439 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
440 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
441
442 const S = struct {
443 x: i32 = 1234,
444
445 fn opt(s: ?@This()) !void {
446 try expect(s.?.x == 1234);
447 }
448 fn errUnion(s: anyerror!@This()) !void {
449 try expect((try s).x == 1234);
450 }
451 };
452 var s: S = .{};
453 try s.opt();
454 try s.errUnion();
455}
test/cases/compile_errors/address_of_threadlocal_not_comptime_known.zig created+13
......@@ -0,0 +1,13 @@
1threadlocal var global: u32 = 23;
2threadlocal var global_ptr: *u32 = &global;
3
4pub export fn entry() void {
5 if (global_ptr.* != 23) unreachable;
6}
7
8// error
9// backend=stage2
10// target=native
11//
12// :2:36: error: unable to resolve comptime value
13// :2:36: note: container level variable initializers must be comptime-known
test/cases/compile_errors/bitsize_of_packed_struct_checks_backing_int_ty.zig created+13
......@@ -0,0 +1,13 @@
1const Foo = packed struct(u32) {
2 x: u1,
3};
4fn bar(_: Foo) callconv(.C) void {}
5pub export fn entry() void {
6 bar(.{ .x = 0 });
7}
8
9// error
10// backend=stage2
11// target=native
12//
13// :1:27: error: backing integer type 'u32' has bit size 32 but the struct fields have a total bit size of 1
test/cases/compile_errors/div_overflow.zig created+11
......@@ -0,0 +1,11 @@
1comptime {
2 const a = -128;
3 const b: i8 = -1;
4 _ = a / b;
5}
6
7// error
8// backend=stage2
9// target=native
10//
11// :4:11: error: overflow of integer type 'i8' with value '128'