mirror of
https://github.com/ziglang/zig.git
synced 2025-12-28 00:53:18 +00:00
Merge pull request #11133 from Vexu/stage2
stage2: misc fixes on the way to `std.debug.dumpCurrentStackTrace`
This commit is contained in:
commit
5ff7b04a6a
@ -1630,7 +1630,6 @@ fn getSymbolFromDwarf(address: u64, di: *DW.DwarfInfo) !SymbolInfo {
|
||||
.symbol_name = nosuspend di.getSymbolName(address) orelse "???",
|
||||
.compile_unit_name = compile_unit.die.getAttrString(di, DW.AT.name) catch |err| switch (err) {
|
||||
error.MissingDebugInfo, error.InvalidDebugInfo => "???",
|
||||
else => return err,
|
||||
},
|
||||
.line_info = nosuspend di.getLineNumberInfo(compile_unit.*, address) catch |err| switch (err) {
|
||||
error.MissingDebugInfo, error.InvalidDebugInfo => null,
|
||||
|
||||
@ -822,7 +822,7 @@ pub const DwarfInfo = struct {
|
||||
// in the list itself.
|
||||
// If no starting value is specified use zero.
|
||||
var base_address = compile_unit.die.getAttrAddr(AT.low_pc) catch |err| switch (err) {
|
||||
error.MissingDebugInfo => 0,
|
||||
error.MissingDebugInfo => @as(u64, 0), // TODO https://github.com/ziglang/zig/issues/11135
|
||||
else => return err,
|
||||
};
|
||||
|
||||
|
||||
@ -1035,9 +1035,8 @@ fn nosuspendExpr(
|
||||
});
|
||||
}
|
||||
gz.nosuspend_node = node;
|
||||
const result = try expr(gz, scope, rl, body_node);
|
||||
gz.nosuspend_node = 0;
|
||||
return rvalue(gz, rl, result, node);
|
||||
defer gz.nosuspend_node = 0;
|
||||
return expr(gz, scope, rl, body_node);
|
||||
}
|
||||
|
||||
fn suspendExpr(
|
||||
|
||||
11
src/Sema.zig
11
src/Sema.zig
@ -6972,7 +6972,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
|
||||
return sema.failWithOwnedErrorMsg(block, msg);
|
||||
}
|
||||
|
||||
if (special_prong == .@"else") {
|
||||
if (special_prong == .@"else" and seen_errors.count() == operand_ty.errorSetNames().len) {
|
||||
return sema.fail(
|
||||
block,
|
||||
special_prong_src,
|
||||
@ -16692,6 +16692,13 @@ fn coerceInMemoryAllowedErrorSets(
|
||||
else => unreachable,
|
||||
}
|
||||
|
||||
if (dst_ies.func == sema.owner_func) {
|
||||
// We are trying to coerce an error set to the current function's
|
||||
// inferred error set.
|
||||
try dst_ies.addErrorSet(sema.gpa, src_ty);
|
||||
return .ok;
|
||||
}
|
||||
|
||||
try sema.resolveInferredErrorSet(block, dest_src, dst_payload.data);
|
||||
// isAnyError might have changed from a false negative to a true positive after resolution.
|
||||
if (dest_ty.isAnyError()) {
|
||||
@ -18910,7 +18917,7 @@ fn resolvePeerTypes(
|
||||
}
|
||||
|
||||
const chosen_set_ty = err_set_ty orelse chosen_ty.errorUnionSet();
|
||||
const candidate_set_ty = chosen_ty.errorUnionSet();
|
||||
const candidate_set_ty = candidate_ty.errorUnionSet();
|
||||
|
||||
if (.ok == try sema.coerceInMemoryAllowedErrorSets(block, chosen_set_ty, candidate_set_ty, src, src)) {
|
||||
err_set_ty = chosen_set_ty;
|
||||
|
||||
@ -5347,7 +5347,14 @@ pub const FuncGen = struct {
|
||||
if (self.liveness.isUnused(inst)) return null;
|
||||
|
||||
const llvm_i32 = self.context.intType(32);
|
||||
const llvm_fn = self.getIntrinsic("llvm.frameaddress", &.{llvm_i32});
|
||||
const llvm_fn_name = "llvm.frameaddress.p0i8";
|
||||
const llvm_fn = self.dg.object.llvm_module.getNamedFunction(llvm_fn_name) orelse blk: {
|
||||
const llvm_p0i8 = self.context.intType(8).pointerType(0);
|
||||
const param_types = [_]*const llvm.Type{llvm_i32};
|
||||
const fn_type = llvm.functionType(llvm_p0i8, ¶m_types, param_types.len, .False);
|
||||
break :blk self.dg.object.llvm_module.addFunction(llvm_fn_name, fn_type);
|
||||
};
|
||||
|
||||
const params = [_]*const llvm.Value{llvm_i32.constNull()};
|
||||
const ptr_val = self.builder.buildCall(llvm_fn, ¶ms, params.len, .Fast, .Auto, "");
|
||||
const llvm_usize = try self.dg.llvmType(Type.usize);
|
||||
|
||||
@ -626,3 +626,26 @@ test "inferred error set equality" {
|
||||
try expect(BarError == BarError);
|
||||
try expect(BazError == BazError);
|
||||
}
|
||||
|
||||
test "peer type resolution of two different error unions" {
|
||||
const a: error{B}!void = {};
|
||||
const b: error{A}!void = {};
|
||||
var cond = true;
|
||||
const err = if (cond) a else b;
|
||||
try err;
|
||||
}
|
||||
|
||||
test "coerce error set to the current inferred error set" {
|
||||
const S = struct {
|
||||
fn foo() !void {
|
||||
var a = false;
|
||||
if (a) {
|
||||
const b: error{A}!void = error.A;
|
||||
return b;
|
||||
}
|
||||
const b = error.A;
|
||||
return b;
|
||||
}
|
||||
};
|
||||
S.foo() catch {};
|
||||
}
|
||||
|
||||
@ -610,14 +610,11 @@ test "switch on pointer type" {
|
||||
}
|
||||
|
||||
test "switch on error set with single else" {
|
||||
if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
|
||||
|
||||
const S = struct {
|
||||
fn doTheTest() !void {
|
||||
var some: error{Foo} = error.Foo;
|
||||
try expect(switch (some) {
|
||||
else => |a| blk: {
|
||||
a catch {};
|
||||
else => blk: {
|
||||
break :blk true;
|
||||
},
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user