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 {...@@ -1457,7 +1457,8 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
1457 errdefer if (module) |zm| zm.deinit();1457 errdefer if (module) |zm| zm.deinit();
14581458
1459 const error_return_tracing = !strip and switch (options.optimize_mode) {1459 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(),
1461 .ReleaseFast, .ReleaseSmall => false,1462 .ReleaseFast, .ReleaseSmall => false,
1462 };1463 };
14631464
src/Sema.zig+11-11
...@@ -1412,7 +1412,8 @@ fn analyzeAsType(...@@ -1412,7 +1412,8 @@ fn analyzeAsType(
1412}1412}
14131413
1414pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize) !void {1414pub 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;
1416 if (!backend_supports_error_return_tracing) {1417 if (!backend_supports_error_return_tracing) {
1417 // TODO implement this feature in all the backends and then delete this branch1418 // TODO implement this feature in all the backends and then delete this branch
1418 return;1419 return;
...@@ -5275,10 +5276,6 @@ fn analyzeCall(...@@ -5275,10 +5276,6 @@ fn analyzeCall(
52755276
5276 try sema.queueFullTypeResolution(func_ty_info.return_type);5277 try sema.queueFullTypeResolution(func_ty_info.return_type);
5277 if (sema.owner_func != null and func_ty_info.return_type.isError()) {5278 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 }
5282 sema.owner_func.?.calls_or_awaits_errorable_fn = true;5279 sema.owner_func.?.calls_or_awaits_errorable_fn = true;
5283 }5280 }
52845281
...@@ -5692,10 +5689,6 @@ fn instantiateGenericCall(...@@ -5692,10 +5689,6 @@ fn instantiateGenericCall(
5692 }5689 }
56935690
5694 if (sema.owner_func != null and new_fn_info.return_type.isError()) {5691 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 }
5699 sema.owner_func.?.calls_or_awaits_errorable_fn = true;5692 sema.owner_func.?.calls_or_awaits_errorable_fn = true;
5700 }5693 }
57015694
...@@ -12662,7 +12655,8 @@ fn analyzeRet(...@@ -12662,7 +12655,8 @@ fn analyzeRet(
12662 }12655 }
1266312656
12664 // TODO implement this feature in all the backends and then delete this check.12657 // 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
12667 if (sema.fn_ret_ty.isError() and sema.mod.comp.bin_file.options.error_return_tracing and12661 if (sema.fn_ret_ty.isError() and sema.mod.comp.bin_file.options.error_return_tracing and
12668 backend_supports_error_return_tracing)12662 backend_supports_error_return_tracing)
...@@ -13410,7 +13404,8 @@ fn zirErrorReturnTrace(...@@ -13410,7 +13404,8 @@ fn zirErrorReturnTrace(
13410 const opt_ptr_stack_trace_ty = try Type.Tag.optional_single_mut_pointer.create(sema.arena, stack_trace_ty);13404 const opt_ptr_stack_trace_ty = try Type.Tag.optional_single_mut_pointer.create(sema.arena, stack_trace_ty);
1341113405
13412 // TODO implement this feature in all the backends and then delete this check.13406 // 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
13415 if (sema.owner_func != null and13410 if (sema.owner_func != null and
13416 sema.owner_func.?.calls_or_awaits_errorable_fn and13411 sema.owner_func.?.calls_or_awaits_errorable_fn and
...@@ -21966,6 +21961,11 @@ pub fn resolveFnTypes(...@@ -21966,6 +21961,11 @@ pub fn resolveFnTypes(
21966) CompileError!void {21961) CompileError!void {
21967 try sema.resolveTypeFully(block, src, fn_info.return_type);21962 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
21969 for (fn_info.param_types) |param_ty| {21969 for (fn_info.param_types) |param_ty| {
21970 try sema.resolveTypeFully(block, src, param_ty);21970 try sema.resolveTypeFully(block, src, param_ty);
21971 }21971 }
src/codegen/llvm.zig+8-5
...@@ -637,7 +637,7 @@ pub const Object = struct {...@@ -637,7 +637,7 @@ pub const Object = struct {
637 const gpa = dg.gpa;637 const gpa = dg.gpa;
638638
639 const err_return_tracing = fn_info.return_type.isError() and639 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
642 const err_ret_trace = if (err_return_tracing)642 const err_ret_trace = if (err_return_tracing)
643 llvm_func.getParam(@boolToInt(ret_ptr != null))643 llvm_func.getParam(@boolToInt(ret_ptr != null))
...@@ -698,6 +698,9 @@ pub const Object = struct {...@@ -698,6 +698,9 @@ pub const Object = struct {
698698
699 const lexical_block = dib.createLexicalBlock(subprogram.toScope(), di_file.?, line_number, 1);699 const lexical_block = dib.createLexicalBlock(subprogram.toScope(), di_file.?, line_number, 1);
700 di_scope = lexical_block.toScope();700 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);
701 }704 }
702705
703 var fg: FuncGen = .{706 var fg: FuncGen = .{
...@@ -1765,7 +1768,7 @@ pub const Object = struct {...@@ -1765,7 +1768,7 @@ pub const Object = struct {
1765 }1768 }
17661769
1767 if (fn_info.return_type.isError() and1770 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)
1769 {1772 {
1770 var ptr_ty_payload: Type.Payload.ElemType = .{1773 var ptr_ty_payload: Type.Payload.ElemType = .{
1771 .base = .{ .tag = .single_mut_pointer },1774 .base = .{ .tag = .single_mut_pointer },
...@@ -2018,7 +2021,7 @@ pub const DeclGen = struct {...@@ -2018,7 +2021,7 @@ pub const DeclGen = struct {
2018 }2021 }
20192022
2020 const err_return_tracing = fn_info.return_type.isError() and2023 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
2023 if (err_return_tracing) {2026 if (err_return_tracing) {
2024 dg.addArgAttr(llvm_fn, @boolToInt(sret), "nonnull");2027 dg.addArgAttr(llvm_fn, @boolToInt(sret), "nonnull");
...@@ -2484,7 +2487,7 @@ pub const DeclGen = struct {...@@ -2484,7 +2487,7 @@ pub const DeclGen = struct {
2484 }2487 }
24852488
2486 if (fn_info.return_type.isError() and2489 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)
2488 {2491 {
2489 var ptr_ty_payload: Type.Payload.ElemType = .{2492 var ptr_ty_payload: Type.Payload.ElemType = .{
2490 .base = .{ .tag = .single_mut_pointer },2493 .base = .{ .tag = .single_mut_pointer },
...@@ -3796,7 +3799,7 @@ pub const FuncGen = struct {...@@ -3796,7 +3799,7 @@ pub const FuncGen = struct {
3796 };3799 };
37973800
3798 if (fn_info.return_type.isError() and3801 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)
3800 {3803 {
3801 try llvm_args.append(self.err_ret_trace.?);3804 try llvm_args.append(self.err_ret_trace.?);
3802 }3805 }