authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-04-23 09:38:38+03:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-05-16 17:42:51-07:00
log53a5aee3b3684a03c91236702c9304dce21279e2
treeb14c0c4d2f017d9423f5f050aa42ea66eaa4ae7a
parent66c3988e5eebd423844d5dd20c762d6fefe20adf

stage2: enable error return tracing on llvm backend


3 files changed, 21 insertions(+), 17 deletions(-)

src/Compilation.zig+2-1
......@@ -1457,7 +1457,8 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
14571457 errdefer if (module) |zm| zm.deinit();
14581458
14591459 const error_return_tracing = !strip and switch (options.optimize_mode) {
1460 .Debug, .ReleaseSafe => true,
1460 .Debug, .ReleaseSafe => (!options.target.isWasm() or options.target.os.tag == .emscripten) and
1461 !options.target.cpu.arch.isBpf(),
14611462 .ReleaseFast, .ReleaseSmall => false,
14621463 };
14631464
src/Sema.zig+11-11
......@@ -1412,7 +1412,8 @@ fn analyzeAsType(
14121412}
14131413
14141414pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize) !void {
1415 const backend_supports_error_return_tracing = false;
1415 const backend_supports_error_return_tracing =
1416 sema.mod.comp.bin_file.options.use_llvm;
14161417 if (!backend_supports_error_return_tracing) {
14171418 // TODO implement this feature in all the backends and then delete this branch
14181419 return;
......@@ -5275,10 +5276,6 @@ fn analyzeCall(
52755276
52765277 try sema.queueFullTypeResolution(func_ty_info.return_type);
52775278 if (sema.owner_func != null and func_ty_info.return_type.isError()) {
5278 if (!sema.owner_func.?.calls_or_awaits_errorable_fn) {
5279 // Ensure the type exists so that backends can assume that.
5280 _ = try sema.getBuiltinType(block, call_src, "StackTrace");
5281 }
52825279 sema.owner_func.?.calls_or_awaits_errorable_fn = true;
52835280 }
52845281
......@@ -5692,10 +5689,6 @@ fn instantiateGenericCall(
56925689 }
56935690
56945691 if (sema.owner_func != null and new_fn_info.return_type.isError()) {
5695 if (!sema.owner_func.?.calls_or_awaits_errorable_fn) {
5696 // Ensure the type exists so that backends can assume that.
5697 _ = try sema.getBuiltinType(block, call_src, "StackTrace");
5698 }
56995692 sema.owner_func.?.calls_or_awaits_errorable_fn = true;
57005693 }
57015694
......@@ -12662,7 +12655,8 @@ fn analyzeRet(
1266212655 }
1266312656
1266412657 // TODO implement this feature in all the backends and then delete this check.
12665 const backend_supports_error_return_tracing = false;
12658 const backend_supports_error_return_tracing =
12659 sema.mod.comp.bin_file.options.use_llvm;
1266612660
1266712661 if (sema.fn_ret_ty.isError() and sema.mod.comp.bin_file.options.error_return_tracing and
1266812662 backend_supports_error_return_tracing)
......@@ -13410,7 +13404,8 @@ fn zirErrorReturnTrace(
1341013404 const opt_ptr_stack_trace_ty = try Type.Tag.optional_single_mut_pointer.create(sema.arena, stack_trace_ty);
1341113405
1341213406 // TODO implement this feature in all the backends and then delete this check.
13413 const backend_supports_error_return_tracing = false;
13407 const backend_supports_error_return_tracing =
13408 sema.mod.comp.bin_file.options.use_llvm;
1341413409
1341513410 if (sema.owner_func != null and
1341613411 sema.owner_func.?.calls_or_awaits_errorable_fn and
......@@ -21966,6 +21961,11 @@ pub fn resolveFnTypes(
2196621961) CompileError!void {
2196721962 try sema.resolveTypeFully(block, src, fn_info.return_type);
2196821963
21964 if (sema.mod.comp.bin_file.options.error_return_tracing and fn_info.return_type.isError()) {
21965 // Ensure the type exists so that backends can assume that.
21966 _ = try sema.getBuiltinType(block, src, "StackTrace");
21967 }
21968
2196921969 for (fn_info.param_types) |param_ty| {
2197021970 try sema.resolveTypeFully(block, src, param_ty);
2197121971 }
src/codegen/llvm.zig+8-5
......@@ -637,7 +637,7 @@ pub const Object = struct {
637637 const gpa = dg.gpa;
638638
639639 const err_return_tracing = fn_info.return_type.isError() and
640 dg.module.comp.bin_file.options.error_return_tracing and false;
640 dg.module.comp.bin_file.options.error_return_tracing;
641641
642642 const err_ret_trace = if (err_return_tracing)
643643 llvm_func.getParam(@boolToInt(ret_ptr != null))
......@@ -698,6 +698,9 @@ pub const Object = struct {
698698
699699 const lexical_block = dib.createLexicalBlock(subprogram.toScope(), di_file.?, line_number, 1);
700700 di_scope = lexical_block.toScope();
701
702 // Setup a debug location in case there is a call to `returnError` before a `.dbg_stmt`.
703 builder.setCurrentDebugLocation(line_number + func.lbrace_line, func.lbrace_column, di_scope.?, null);
701704 }
702705
703706 var fg: FuncGen = .{
......@@ -1765,7 +1768,7 @@ pub const Object = struct {
17651768 }
17661769
17671770 if (fn_info.return_type.isError() and
1768 o.module.comp.bin_file.options.error_return_tracing and false)
1771 o.module.comp.bin_file.options.error_return_tracing)
17691772 {
17701773 var ptr_ty_payload: Type.Payload.ElemType = .{
17711774 .base = .{ .tag = .single_mut_pointer },
......@@ -2018,7 +2021,7 @@ pub const DeclGen = struct {
20182021 }
20192022
20202023 const err_return_tracing = fn_info.return_type.isError() and
2021 dg.module.comp.bin_file.options.error_return_tracing and false;
2024 dg.module.comp.bin_file.options.error_return_tracing;
20222025
20232026 if (err_return_tracing) {
20242027 dg.addArgAttr(llvm_fn, @boolToInt(sret), "nonnull");
......@@ -2484,7 +2487,7 @@ pub const DeclGen = struct {
24842487 }
24852488
24862489 if (fn_info.return_type.isError() and
2487 dg.module.comp.bin_file.options.error_return_tracing and false)
2490 dg.module.comp.bin_file.options.error_return_tracing)
24882491 {
24892492 var ptr_ty_payload: Type.Payload.ElemType = .{
24902493 .base = .{ .tag = .single_mut_pointer },
......@@ -3796,7 +3799,7 @@ pub const FuncGen = struct {
37963799 };
37973800
37983801 if (fn_info.return_type.isError() and
3799 self.dg.module.comp.bin_file.options.error_return_tracing and false)
3802 self.dg.module.comp.bin_file.options.error_return_tracing)
38003803 {
38013804 try llvm_args.append(self.err_ret_trace.?);
38023805 }