authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-07-28 17:28:37+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-08-01 23:37:01+03:00
logf1768b40b2468d63355c8cf83d3614ae23a54317
treede545d2d3b1c91c08f4223d67cb00157718adade
parent57f9405a8fcaec6043d680fa47ae0e98709160c2

stage2: better source location for var decls


11 files changed, 131 insertions(+), 51 deletions(-)

src/AstGen.zig+2-1
...@@ -7424,7 +7424,8 @@ fn builtinCall(...@@ -7424,7 +7424,8 @@ fn builtinCall(
7424 const token_starts = tree.tokens.items(.start);7424 const token_starts = tree.tokens.items(.start);
7425 const node_start = token_starts[tree.firstToken(node)];7425 const node_start = token_starts[tree.firstToken(node)];
7426 astgen.advanceSourceCursor(node_start);7426 astgen.advanceSourceCursor(node_start);
7427 const result = try gz.addExtendedPayload(.builtin_src, Zir.Inst.LineColumn{7427 const result = try gz.addExtendedPayload(.builtin_src, Zir.Inst.Src{
7428 .node = gz.nodeIndexToRelative(node),
7428 .line = astgen.source_line,7429 .line = astgen.source_line,
7429 .column = astgen.source_column,7430 .column = astgen.source_column,
7430 });7431 });
src/Module.zig+94-13
...@@ -2161,6 +2161,10 @@ pub const SrcLoc = struct {...@@ -2161,6 +2161,10 @@ pub const SrcLoc = struct {
2161 .local_var_decl => tree.localVarDecl(node),2161 .local_var_decl => tree.localVarDecl(node),
2162 .simple_var_decl => tree.simpleVarDecl(node),2162 .simple_var_decl => tree.simpleVarDecl(node),
2163 .aligned_var_decl => tree.alignedVarDecl(node),2163 .aligned_var_decl => tree.alignedVarDecl(node),
2164 .@"usingnamespace" => {
2165 const node_data = tree.nodes.items(.data);
2166 return nodeToSpan(tree, node_data[node].lhs);
2167 },
2164 else => unreachable,2168 else => unreachable,
2165 };2169 };
2166 if (full.ast.type_node != 0) {2170 if (full.ast.type_node != 0) {
...@@ -2171,6 +2175,58 @@ pub const SrcLoc = struct {...@@ -2171,6 +2175,58 @@ pub const SrcLoc = struct {
2171 const end = start + @intCast(u32, tree.tokenSlice(tok_index).len);2175 const end = start + @intCast(u32, tree.tokenSlice(tok_index).len);
2172 return Span{ .start = start, .end = end, .main = start };2176 return Span{ .start = start, .end = end, .main = start };
2173 },2177 },
2178 .node_offset_var_decl_align => |node_off| {
2179 const tree = try src_loc.file_scope.getTree(gpa);
2180 const node = src_loc.declRelativeToNodeIndex(node_off);
2181 const node_tags = tree.nodes.items(.tag);
2182 const full: Ast.full.VarDecl = switch (node_tags[node]) {
2183 .global_var_decl => tree.globalVarDecl(node),
2184 .local_var_decl => tree.localVarDecl(node),
2185 .simple_var_decl => tree.simpleVarDecl(node),
2186 .aligned_var_decl => tree.alignedVarDecl(node),
2187 else => unreachable,
2188 };
2189 return nodeToSpan(tree, full.ast.align_node);
2190 },
2191 .node_offset_var_decl_section => |node_off| {
2192 const tree = try src_loc.file_scope.getTree(gpa);
2193 const node = src_loc.declRelativeToNodeIndex(node_off);
2194 const node_tags = tree.nodes.items(.tag);
2195 const full: Ast.full.VarDecl = switch (node_tags[node]) {
2196 .global_var_decl => tree.globalVarDecl(node),
2197 .local_var_decl => tree.localVarDecl(node),
2198 .simple_var_decl => tree.simpleVarDecl(node),
2199 .aligned_var_decl => tree.alignedVarDecl(node),
2200 else => unreachable,
2201 };
2202 return nodeToSpan(tree, full.ast.section_node);
2203 },
2204 .node_offset_var_decl_addrspace => |node_off| {
2205 const tree = try src_loc.file_scope.getTree(gpa);
2206 const node = src_loc.declRelativeToNodeIndex(node_off);
2207 const node_tags = tree.nodes.items(.tag);
2208 const full: Ast.full.VarDecl = switch (node_tags[node]) {
2209 .global_var_decl => tree.globalVarDecl(node),
2210 .local_var_decl => tree.localVarDecl(node),
2211 .simple_var_decl => tree.simpleVarDecl(node),
2212 .aligned_var_decl => tree.alignedVarDecl(node),
2213 else => unreachable,
2214 };
2215 return nodeToSpan(tree, full.ast.addrspace_node);
2216 },
2217 .node_offset_var_decl_init => |node_off| {
2218 const tree = try src_loc.file_scope.getTree(gpa);
2219 const node = src_loc.declRelativeToNodeIndex(node_off);
2220 const node_tags = tree.nodes.items(.tag);
2221 const full: Ast.full.VarDecl = switch (node_tags[node]) {
2222 .global_var_decl => tree.globalVarDecl(node),
2223 .local_var_decl => tree.localVarDecl(node),
2224 .simple_var_decl => tree.simpleVarDecl(node),
2225 .aligned_var_decl => tree.alignedVarDecl(node),
2226 else => unreachable,
2227 };
2228 return nodeToSpan(tree, full.ast.init_node);
2229 },
2174 .node_offset_builtin_call_arg0 => |n| return src_loc.byteOffsetBuiltinCallArg(gpa, n, 0),2230 .node_offset_builtin_call_arg0 => |n| return src_loc.byteOffsetBuiltinCallArg(gpa, n, 0),
2175 .node_offset_builtin_call_arg1 => |n| return src_loc.byteOffsetBuiltinCallArg(gpa, n, 1),2231 .node_offset_builtin_call_arg1 => |n| return src_loc.byteOffsetBuiltinCallArg(gpa, n, 1),
2176 .node_offset_builtin_call_arg2 => |n| return src_loc.byteOffsetBuiltinCallArg(gpa, n, 2),2232 .node_offset_builtin_call_arg2 => |n| return src_loc.byteOffsetBuiltinCallArg(gpa, n, 2),
...@@ -2857,6 +2913,18 @@ pub const LazySrcLoc = union(enum) {...@@ -2857,6 +2913,18 @@ pub const LazySrcLoc = union(enum) {
2857 /// to the type expression.2913 /// to the type expression.
2858 /// The Decl is determined contextually.2914 /// The Decl is determined contextually.
2859 node_offset_var_decl_ty: i32,2915 node_offset_var_decl_ty: i32,
2916 /// The source location points to the alignment expression of a var decl.
2917 /// The Decl is determined contextually.
2918 node_offset_var_decl_align: i32,
2919 /// The source location points to the linksection expression of a var decl.
2920 /// The Decl is determined contextually.
2921 node_offset_var_decl_section: i32,
2922 /// The source location points to the addrspace expression of a var decl.
2923 /// The Decl is determined contextually.
2924 node_offset_var_decl_addrspace: i32,
2925 /// The source location points to the initializer of a var decl.
2926 /// The Decl is determined contextually.
2927 node_offset_var_decl_init: i32,
2860 /// The source location points to a for loop condition expression,2928 /// The source location points to a for loop condition expression,
2861 /// found by taking this AST node index offset from the containing2929 /// found by taking this AST node index offset from the containing
2862 /// Decl AST node, which points to a for loop AST node. Next, navigate2930 /// Decl AST node, which points to a for loop AST node. Next, navigate
...@@ -3098,6 +3166,10 @@ pub const LazySrcLoc = union(enum) {...@@ -3098,6 +3166,10 @@ pub const LazySrcLoc = union(enum) {
3098 .node_offset,3166 .node_offset,
3099 .node_offset_initializer,3167 .node_offset_initializer,
3100 .node_offset_var_decl_ty,3168 .node_offset_var_decl_ty,
3169 .node_offset_var_decl_align,
3170 .node_offset_var_decl_section,
3171 .node_offset_var_decl_addrspace,
3172 .node_offset_var_decl_init,
3101 .node_offset_for_cond,3173 .node_offset_for_cond,
3102 .node_offset_builtin_call_arg0,3174 .node_offset_builtin_call_arg0,
3103 .node_offset_builtin_call_arg1,3175 .node_offset_builtin_call_arg1,
...@@ -4414,17 +4486,26 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {...@@ -4414,17 +4486,26 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
4414 const body = zir.extra[extra.end..][0..extra.data.body_len];4486 const body = zir.extra[extra.end..][0..extra.data.body_len];
4415 const result_ref = (try sema.analyzeBodyBreak(&block_scope, body)).?.operand;4487 const result_ref = (try sema.analyzeBodyBreak(&block_scope, body)).?.operand;
4416 try wip_captures.finalize();4488 try wip_captures.finalize();
4417 const src = LazySrcLoc.nodeOffset(0);4489 const align_src: LazySrcLoc = .{ .node_offset_var_decl_align = 0 };
4418 const decl_tv = try sema.resolveInstValue(&block_scope, .unneeded, result_ref, undefined);4490 const section_src: LazySrcLoc = .{ .node_offset_var_decl_section = 0 };
4491 const address_space_src: LazySrcLoc = .{ .node_offset_var_decl_addrspace = 0 };
4492 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = 0 };
4493 const init_src: LazySrcLoc = .{ .node_offset_var_decl_init = 0 };
4494 const decl_tv = try sema.resolveInstValue(&block_scope, init_src, result_ref, undefined);
4419 const decl_align: u32 = blk: {4495 const decl_align: u32 = blk: {
4420 const align_ref = decl.zirAlignRef();4496 const align_ref = decl.zirAlignRef();
4421 if (align_ref == .none) break :blk 0;4497 if (align_ref == .none) break :blk 0;
4422 break :blk try sema.resolveAlign(&block_scope, src, align_ref);4498 break :blk try sema.resolveAlign(&block_scope, align_src, align_ref);
4423 };4499 };
4424 const decl_linksection: ?[*:0]const u8 = blk: {4500 const decl_linksection: ?[*:0]const u8 = blk: {
4425 const linksection_ref = decl.zirLinksectionRef();4501 const linksection_ref = decl.zirLinksectionRef();
4426 if (linksection_ref == .none) break :blk null;4502 if (linksection_ref == .none) break :blk null;
4427 const bytes = try sema.resolveConstString(&block_scope, src, linksection_ref, "linksection must be comptime known");4503 const bytes = try sema.resolveConstString(&block_scope, section_src, linksection_ref, "linksection must be comptime known");
4504 if (mem.indexOfScalar(u8, bytes, 0) != null) {
4505 return sema.fail(&block_scope, section_src, "linksection cannot contain null bytes", .{});
4506 } else if (bytes.len == 0) {
4507 return sema.fail(&block_scope, section_src, "linksection cannot be empty", .{});
4508 }
4428 break :blk (try decl_arena_allocator.dupeZ(u8, bytes)).ptr;4509 break :blk (try decl_arena_allocator.dupeZ(u8, bytes)).ptr;
4429 };4510 };
4430 const target = sema.mod.getTarget();4511 const target = sema.mod.getTarget();
...@@ -4442,27 +4523,27 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {...@@ -4442,27 +4523,27 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
4442 .constant => target_util.defaultAddressSpace(target, .global_constant),4523 .constant => target_util.defaultAddressSpace(target, .global_constant),
4443 else => unreachable,4524 else => unreachable,
4444 },4525 },
4445 else => |addrspace_ref| try sema.analyzeAddrspace(&block_scope, src, addrspace_ref, addrspace_ctx),4526 else => |addrspace_ref| try sema.analyzeAddrspace(&block_scope, address_space_src, addrspace_ref, addrspace_ctx),
4446 };4527 };
4447 };4528 };
44484529
4449 // Note this resolves the type of the Decl, not the value; if this Decl4530 // Note this resolves the type of the Decl, not the value; if this Decl
4450 // is a struct, for example, this resolves `type` (which needs no resolution),4531 // is a struct, for example, this resolves `type` (which needs no resolution),
4451 // not the struct itself.4532 // not the struct itself.
4452 try sema.resolveTypeLayout(&block_scope, src, decl_tv.ty);4533 try sema.resolveTypeLayout(&block_scope, ty_src, decl_tv.ty);
44534534
4454 const decl_arena_state = try decl_arena_allocator.create(std.heap.ArenaAllocator.State);4535 const decl_arena_state = try decl_arena_allocator.create(std.heap.ArenaAllocator.State);
44554536
4456 if (decl.is_usingnamespace) {4537 if (decl.is_usingnamespace) {
4457 if (!decl_tv.ty.eql(Type.type, mod)) {4538 if (!decl_tv.ty.eql(Type.type, mod)) {
4458 return sema.fail(&block_scope, src, "expected type, found {}", .{4539 return sema.fail(&block_scope, ty_src, "expected type, found {}", .{
4459 decl_tv.ty.fmt(mod),4540 decl_tv.ty.fmt(mod),
4460 });4541 });
4461 }4542 }
4462 var buffer: Value.ToTypeBuffer = undefined;4543 var buffer: Value.ToTypeBuffer = undefined;
4463 const ty = try decl_tv.val.toType(&buffer).copy(decl_arena_allocator);4544 const ty = try decl_tv.val.toType(&buffer).copy(decl_arena_allocator);
4464 if (ty.getNamespace() == null) {4545 if (ty.getNamespace() == null) {
4465 return sema.fail(&block_scope, src, "type {} has no namespace", .{ty.fmt(mod)});4546 return sema.fail(&block_scope, ty_src, "type {} has no namespace", .{ty.fmt(mod)});
4466 }4547 }
44674548
4468 decl.ty = Type.type;4549 decl.ty = Type.type;
...@@ -4508,7 +4589,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {...@@ -4508,7 +4589,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
4508 decl.analysis = .complete;4589 decl.analysis = .complete;
4509 decl.generation = mod.generation;4590 decl.generation = mod.generation;
45104591
4511 const has_runtime_bits = try sema.fnHasRuntimeBits(&block_scope, src, decl.ty);4592 const has_runtime_bits = try sema.fnHasRuntimeBits(&block_scope, ty_src, decl.ty);
45124593
4513 if (has_runtime_bits) {4594 if (has_runtime_bits) {
4514 // We don't fully codegen the decl until later, but we do need to reserve a global4595 // We don't fully codegen the decl until later, but we do need to reserve a global
...@@ -4525,7 +4606,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {...@@ -4525,7 +4606,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
45254606
4526 const is_inline = decl.ty.fnCallingConvention() == .Inline;4607 const is_inline = decl.ty.fnCallingConvention() == .Inline;
4527 if (decl.is_exported) {4608 if (decl.is_exported) {
4528 const export_src = src; // TODO make this point at `export` token4609 const export_src: LazySrcLoc = .{ .token_offset = @boolToInt(decl.is_pub) };
4529 if (is_inline) {4610 if (is_inline) {
4530 return sema.fail(&block_scope, export_src, "export of inline function", .{});4611 return sema.fail(&block_scope, export_src, "export of inline function", .{});
4531 }4612 }
...@@ -4588,14 +4669,14 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {...@@ -4588,14 +4669,14 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
4588 decl.generation = mod.generation;4669 decl.generation = mod.generation;
45894670
4590 const has_runtime_bits = is_extern or4671 const has_runtime_bits = is_extern or
4591 (queue_linker_work and try sema.typeHasRuntimeBits(&block_scope, src, decl.ty));4672 (queue_linker_work and try sema.typeHasRuntimeBits(&block_scope, ty_src, decl.ty));
45924673
4593 if (has_runtime_bits) {4674 if (has_runtime_bits) {
4594 log.debug("queue linker work for {*} ({s})", .{ decl, decl.name });4675 log.debug("queue linker work for {*} ({s})", .{ decl, decl.name });
45954676
4596 // Needed for codegen_decl which will call updateDecl and then the4677 // Needed for codegen_decl which will call updateDecl and then the
4597 // codegen backend wants full access to the Decl Type.4678 // codegen backend wants full access to the Decl Type.
4598 try sema.resolveTypeFully(&block_scope, src, decl.ty);4679 try sema.resolveTypeFully(&block_scope, ty_src, decl.ty);
45994680
4600 try mod.comp.bin_file.allocateDeclIndexes(decl_index);4681 try mod.comp.bin_file.allocateDeclIndexes(decl_index);
4601 try mod.comp.work_queue.writeItem(.{ .codegen_decl = decl_index });4682 try mod.comp.work_queue.writeItem(.{ .codegen_decl = decl_index });
...@@ -4606,7 +4687,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {...@@ -4606,7 +4687,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
4606 }4687 }
46074688
4608 if (decl.is_exported) {4689 if (decl.is_exported) {
4609 const export_src = src; // TODO point to the export token4690 const export_src: LazySrcLoc = .{ .token_offset = @boolToInt(decl.is_pub) };
4610 // The scope needs to have the decl in it.4691 // The scope needs to have the decl in it.
4611 const options: std.builtin.ExportOptions = .{ .name = mem.sliceTo(decl.name, 0) };4692 const options: std.builtin.ExportOptions = .{ .name = mem.sliceTo(decl.name, 0) };
4612 try sema.analyzeExport(&block_scope, export_src, options, decl_index);4693 try sema.analyzeExport(&block_scope, export_src, options, decl_index);
src/Sema.zig+7-15
...@@ -2971,7 +2971,7 @@ fn zirAllocExtended(...@@ -2971,7 +2971,7 @@ fn zirAllocExtended(
2971 const extra = sema.code.extraData(Zir.Inst.AllocExtended, extended.operand);2971 const extra = sema.code.extraData(Zir.Inst.AllocExtended, extended.operand);
2972 const src = LazySrcLoc.nodeOffset(extra.data.src_node);2972 const src = LazySrcLoc.nodeOffset(extra.data.src_node);
2973 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = extra.data.src_node };2973 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = extra.data.src_node };
2974 const align_src = src; // TODO better source location2974 const align_src: LazySrcLoc = .{ .node_offset_var_decl_align = extra.data.src_node };
2975 const small = @bitCast(Zir.Inst.AllocExtended.Small, extended.small);2975 const small = @bitCast(Zir.Inst.AllocExtended.Small, extended.small);
29762976
2977 var extra_index: usize = extra.end;2977 var extra_index: usize = extra.end;
...@@ -8046,7 +8046,7 @@ fn zirPtrToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -8046,7 +8046,7 @@ fn zirPtrToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
8046 if (try sema.resolveMaybeUndefValIntable(block, ptr_src, ptr)) |ptr_val| {8046 if (try sema.resolveMaybeUndefValIntable(block, ptr_src, ptr)) |ptr_val| {
8047 return sema.addConstant(Type.usize, ptr_val);8047 return sema.addConstant(Type.usize, ptr_val);
8048 }8048 }
8049 try sema.requireRuntimeBlock(block, ptr_src, ptr_src);8049 try sema.requireRuntimeBlock(block, inst_data.src(), ptr_src);
8050 return block.addUnOp(.ptrtoint, ptr);8050 return block.addUnOp(.ptrtoint, ptr);
8051}8051}
80528052
...@@ -13174,8 +13174,8 @@ fn zirBuiltinSrc(...@@ -13174,8 +13174,8 @@ fn zirBuiltinSrc(
13174 const tracy = trace(@src());13174 const tracy = trace(@src());
13175 defer tracy.end();13175 defer tracy.end();
1317613176
13177 const src = sema.src; // TODO better source location13177 const extra = sema.code.extraData(Zir.Inst.Src, extended.operand).data;
13178 const extra = sema.code.extraData(Zir.Inst.LineColumn, extended.operand).data;13178 const src = LazySrcLoc.nodeOffset(extra.node);
13179 const func = sema.func orelse return sema.fail(block, src, "@src outside function", .{});13179 const func = sema.func orelse return sema.fail(block, src, "@src outside function", .{});
13180 const fn_owner_decl = sema.mod.declPtr(func.owner_decl);13180 const fn_owner_decl = sema.mod.declPtr(func.owner_decl);
1318113181
...@@ -18959,10 +18959,8 @@ fn zirVarExtended(...@@ -18959,10 +18959,8 @@ fn zirVarExtended(
18959 extended: Zir.Inst.Extended.InstData,18959 extended: Zir.Inst.Extended.InstData,
18960) CompileError!Air.Inst.Ref {18960) CompileError!Air.Inst.Ref {
18961 const extra = sema.code.extraData(Zir.Inst.ExtendedVar, extended.operand);18961 const extra = sema.code.extraData(Zir.Inst.ExtendedVar, extended.operand);
18962 const src = sema.src;18962 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = 0 };
18963 const ty_src: LazySrcLoc = src; // TODO add a LazySrcLoc that points at type18963 const init_src: LazySrcLoc = .{ .node_offset_var_decl_init = 0 };
18964 const name_src: LazySrcLoc = src; // TODO add a LazySrcLoc that points at the name token
18965 const init_src: LazySrcLoc = src; // TODO add a LazySrcLoc that points at init expr
18966 const small = @bitCast(Zir.Inst.ExtendedVar.Small, extended.small);18964 const small = @bitCast(Zir.Inst.ExtendedVar.Small, extended.small);
1896718965
18968 var extra_index: usize = extra.end;18966 var extra_index: usize = extra.end;
...@@ -18976,12 +18974,6 @@ fn zirVarExtended(...@@ -18976,12 +18974,6 @@ fn zirVarExtended(
18976 // ZIR supports encoding this information but it is not used; the information18974 // ZIR supports encoding this information but it is not used; the information
18977 // is encoded via the Decl entry.18975 // is encoded via the Decl entry.
18978 assert(!small.has_align);18976 assert(!small.has_align);
18979 //const align_val: Value = if (small.has_align) blk: {
18980 // const align_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);
18981 // extra_index += 1;
18982 // const align_tv = try sema.resolveInstConst(block, align_src, align_ref);
18983 // break :blk align_tv.val;
18984 //} else Value.@"null";
1898518977
18986 const uncasted_init: Air.Inst.Ref = if (small.has_init) blk: {18978 const uncasted_init: Air.Inst.Ref = if (small.has_init) blk: {
18987 const init_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);18979 const init_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);
...@@ -19005,7 +18997,7 @@ fn zirVarExtended(...@@ -19005,7 +18997,7 @@ fn zirVarExtended(
19005 return sema.failWithNeededComptime(block, init_src, "container level variable initializers must be comptime known");18997 return sema.failWithNeededComptime(block, init_src, "container level variable initializers must be comptime known");
19006 } else Value.initTag(.unreachable_value);18998 } else Value.initTag(.unreachable_value);
1900718999
19008 try sema.validateVarType(block, name_src, var_ty, small.is_extern);19000 try sema.validateVarType(block, ty_src, var_ty, small.is_extern);
1900919001
19010 const new_var = try sema.gpa.create(Module.Var);19002 const new_var = try sema.gpa.create(Module.Var);
19011 errdefer sema.gpa.destroy(new_var);19003 errdefer sema.gpa.destroy(new_var);
src/Zir.zig+6
...@@ -3548,6 +3548,12 @@ pub const Inst = struct {...@@ -3548,6 +3548,12 @@ pub const Inst = struct {
3548 ty: Ref,3548 ty: Ref,
3549 init_count: u32,3549 init_count: u32,
3550 };3550 };
3551
3552 pub const Src = struct {
3553 node: i32,
3554 line: u32,
3555 column: u32,
3556 };
3551};3557};
35523558
3553pub const SpecialProng = enum { none, @"else", under };3559pub const SpecialProng = enum { none, @"else", under };
test/cases/compile_errors/global_variable_alignment_non_power_of_2.zig created+8
...@@ -0,0 +1,8 @@
1const some_data: [100]u8 align(3) = undefined;
2export fn entry() usize { return @sizeOf(@TypeOf(some_data)); }
3
4// error
5// backend=stage2
6// target=native
7//
8// :1:32: error: alignment value '3' is not a power of two
test/cases/compile_errors/src_outside_function.zig created+9
...@@ -0,0 +1,9 @@
1comptime {
2 @src();
3}
4
5// error
6// backend=stage2
7// target=native
8//
9// :2:5: error: @src outside function
test/cases/compile_errors/stage1/obj/global_variable_alignment_non_power_of_2.zig deleted-8
...@@ -1,8 +0,0 @@
1const some_data: [100]u8 align(3) = undefined;
2export fn entry() usize { return @sizeOf(@TypeOf(some_data)); }
3
4// error
5// backend=stage1
6// target=native
7//
8// tmp.zig:1:32: error: alignment value 3 is not a power of 2
test/cases/compile_errors/stage1/obj/src_outside_function.zig deleted-9
...@@ -1,9 +0,0 @@
1comptime {
2 @src();
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:5: error: @src outside function
test/cases/compile_errors/type_variables_must_be_constant.zig+2-2
...@@ -7,5 +7,5 @@ export fn entry() foo {...@@ -7,5 +7,5 @@ export fn entry() foo {
7// backend=stage27// backend=stage2
8// target=native8// target=native
9//9//
10// :1:1: error: variable of type 'type' must be const or comptime10// :1:5: error: variable of type 'type' must be const or comptime
11// :1:1: note: types are not available at runtime11// :1:5: note: types are not available at runtime
test/cases/compile_errors/use_invalid_number_literal_as_array_index.zig+2-2
...@@ -8,5 +8,5 @@ export fn entry() void {...@@ -8,5 +8,5 @@ export fn entry() void {
8// backend=stage28// backend=stage2
9// target=native9// target=native
10//10//
11// :1:1: error: variable of type 'comptime_int' must be const or comptime11// :1:5: error: variable of type 'comptime_int' must be const or comptime
12// :1:1: note: to modify this variable at runtime, it must be given an explicit fixed-size number type12// :1:5: note: to modify this variable at runtime, it must be given an explicit fixed-size number type
test/cases/compile_errors/usingnamespace_with_wrong_type.zig+1-1
...@@ -4,4 +4,4 @@ usingnamespace void;...@@ -4,4 +4,4 @@ usingnamespace void;
4// backend=stage24// backend=stage2
5// target=native5// target=native
6//6//
7// :1:1: error: type void has no namespace7// :1:16: error: type void has no namespace