mirror of
https://github.com/ziglang/zig.git
synced 2026-02-16 06:18:32 +00:00
stage2: enable error return tracing on llvm backend
This commit is contained in:
parent
66c3988e5e
commit
53a5aee3b3
@ -1457,7 +1457,8 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
|
||||
errdefer if (module) |zm| zm.deinit();
|
||||
|
||||
const error_return_tracing = !strip and switch (options.optimize_mode) {
|
||||
.Debug, .ReleaseSafe => true,
|
||||
.Debug, .ReleaseSafe => (!options.target.isWasm() or options.target.os.tag == .emscripten) and
|
||||
!options.target.cpu.arch.isBpf(),
|
||||
.ReleaseFast, .ReleaseSmall => false,
|
||||
};
|
||||
|
||||
|
||||
22
src/Sema.zig
22
src/Sema.zig
@ -1412,7 +1412,8 @@ fn analyzeAsType(
|
||||
}
|
||||
|
||||
pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize) !void {
|
||||
const backend_supports_error_return_tracing = false;
|
||||
const backend_supports_error_return_tracing =
|
||||
sema.mod.comp.bin_file.options.use_llvm;
|
||||
if (!backend_supports_error_return_tracing) {
|
||||
// TODO implement this feature in all the backends and then delete this branch
|
||||
return;
|
||||
@ -5275,10 +5276,6 @@ fn analyzeCall(
|
||||
|
||||
try sema.queueFullTypeResolution(func_ty_info.return_type);
|
||||
if (sema.owner_func != null and func_ty_info.return_type.isError()) {
|
||||
if (!sema.owner_func.?.calls_or_awaits_errorable_fn) {
|
||||
// Ensure the type exists so that backends can assume that.
|
||||
_ = try sema.getBuiltinType(block, call_src, "StackTrace");
|
||||
}
|
||||
sema.owner_func.?.calls_or_awaits_errorable_fn = true;
|
||||
}
|
||||
|
||||
@ -5692,10 +5689,6 @@ fn instantiateGenericCall(
|
||||
}
|
||||
|
||||
if (sema.owner_func != null and new_fn_info.return_type.isError()) {
|
||||
if (!sema.owner_func.?.calls_or_awaits_errorable_fn) {
|
||||
// Ensure the type exists so that backends can assume that.
|
||||
_ = try sema.getBuiltinType(block, call_src, "StackTrace");
|
||||
}
|
||||
sema.owner_func.?.calls_or_awaits_errorable_fn = true;
|
||||
}
|
||||
|
||||
@ -12662,7 +12655,8 @@ fn analyzeRet(
|
||||
}
|
||||
|
||||
// TODO implement this feature in all the backends and then delete this check.
|
||||
const backend_supports_error_return_tracing = false;
|
||||
const backend_supports_error_return_tracing =
|
||||
sema.mod.comp.bin_file.options.use_llvm;
|
||||
|
||||
if (sema.fn_ret_ty.isError() and sema.mod.comp.bin_file.options.error_return_tracing and
|
||||
backend_supports_error_return_tracing)
|
||||
@ -13410,7 +13404,8 @@ fn zirErrorReturnTrace(
|
||||
const opt_ptr_stack_trace_ty = try Type.Tag.optional_single_mut_pointer.create(sema.arena, stack_trace_ty);
|
||||
|
||||
// TODO implement this feature in all the backends and then delete this check.
|
||||
const backend_supports_error_return_tracing = false;
|
||||
const backend_supports_error_return_tracing =
|
||||
sema.mod.comp.bin_file.options.use_llvm;
|
||||
|
||||
if (sema.owner_func != null and
|
||||
sema.owner_func.?.calls_or_awaits_errorable_fn and
|
||||
@ -21966,6 +21961,11 @@ pub fn resolveFnTypes(
|
||||
) CompileError!void {
|
||||
try sema.resolveTypeFully(block, src, fn_info.return_type);
|
||||
|
||||
if (sema.mod.comp.bin_file.options.error_return_tracing and fn_info.return_type.isError()) {
|
||||
// Ensure the type exists so that backends can assume that.
|
||||
_ = try sema.getBuiltinType(block, src, "StackTrace");
|
||||
}
|
||||
|
||||
for (fn_info.param_types) |param_ty| {
|
||||
try sema.resolveTypeFully(block, src, param_ty);
|
||||
}
|
||||
|
||||
@ -637,7 +637,7 @@ pub const Object = struct {
|
||||
const gpa = dg.gpa;
|
||||
|
||||
const err_return_tracing = fn_info.return_type.isError() and
|
||||
dg.module.comp.bin_file.options.error_return_tracing and false;
|
||||
dg.module.comp.bin_file.options.error_return_tracing;
|
||||
|
||||
const err_ret_trace = if (err_return_tracing)
|
||||
llvm_func.getParam(@boolToInt(ret_ptr != null))
|
||||
@ -698,6 +698,9 @@ pub const Object = struct {
|
||||
|
||||
const lexical_block = dib.createLexicalBlock(subprogram.toScope(), di_file.?, line_number, 1);
|
||||
di_scope = lexical_block.toScope();
|
||||
|
||||
// Setup a debug location in case there is a call to `returnError` before a `.dbg_stmt`.
|
||||
builder.setCurrentDebugLocation(line_number + func.lbrace_line, func.lbrace_column, di_scope.?, null);
|
||||
}
|
||||
|
||||
var fg: FuncGen = .{
|
||||
@ -1765,7 +1768,7 @@ pub const Object = struct {
|
||||
}
|
||||
|
||||
if (fn_info.return_type.isError() and
|
||||
o.module.comp.bin_file.options.error_return_tracing and false)
|
||||
o.module.comp.bin_file.options.error_return_tracing)
|
||||
{
|
||||
var ptr_ty_payload: Type.Payload.ElemType = .{
|
||||
.base = .{ .tag = .single_mut_pointer },
|
||||
@ -2018,7 +2021,7 @@ pub const DeclGen = struct {
|
||||
}
|
||||
|
||||
const err_return_tracing = fn_info.return_type.isError() and
|
||||
dg.module.comp.bin_file.options.error_return_tracing and false;
|
||||
dg.module.comp.bin_file.options.error_return_tracing;
|
||||
|
||||
if (err_return_tracing) {
|
||||
dg.addArgAttr(llvm_fn, @boolToInt(sret), "nonnull");
|
||||
@ -2484,7 +2487,7 @@ pub const DeclGen = struct {
|
||||
}
|
||||
|
||||
if (fn_info.return_type.isError() and
|
||||
dg.module.comp.bin_file.options.error_return_tracing and false)
|
||||
dg.module.comp.bin_file.options.error_return_tracing)
|
||||
{
|
||||
var ptr_ty_payload: Type.Payload.ElemType = .{
|
||||
.base = .{ .tag = .single_mut_pointer },
|
||||
@ -3796,7 +3799,7 @@ pub const FuncGen = struct {
|
||||
};
|
||||
|
||||
if (fn_info.return_type.isError() and
|
||||
self.dg.module.comp.bin_file.options.error_return_tracing and false)
|
||||
self.dg.module.comp.bin_file.options.error_return_tracing)
|
||||
{
|
||||
try llvm_args.append(self.err_ret_trace.?);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user