mirror of
https://github.com/ziglang/zig.git
synced 2024-11-15 00:26:57 +00:00
Merge pull request #13032 from jacobly0/br-on-undef-val
stage2: fix branches on undefined values
This commit is contained in:
commit
54eb0f2daa
@ -4430,6 +4430,8 @@ pub fn semaFile(mod: *Module, file: *File) SemaError!void {
|
||||
new_decl.has_linksection_or_addrspace = false;
|
||||
new_decl.ty = ty_ty;
|
||||
new_decl.val = struct_val;
|
||||
new_decl.@"align" = 0;
|
||||
new_decl.@"linksection" = null;
|
||||
new_decl.has_tv = true;
|
||||
new_decl.owns_tv = true;
|
||||
new_decl.alive = true; // This Decl corresponds to a File and is therefore always alive.
|
||||
|
15
src/Sema.zig
15
src/Sema.zig
@ -8107,6 +8107,13 @@ fn funcCommon(
|
||||
for (comptime_params) |ct| is_generic = is_generic or ct;
|
||||
is_generic = is_generic or ret_ty_requires_comptime;
|
||||
|
||||
if (!is_generic and sema.wantErrorReturnTracing(return_type)) {
|
||||
// Make sure that StackTrace's fields are resolved so that the backend can
|
||||
// lower this fn type.
|
||||
const unresolved_stack_trace_ty = try sema.getBuiltinType(block, ret_ty_src, "StackTrace");
|
||||
_ = try sema.resolveTypeFields(block, ret_ty_src, unresolved_stack_trace_ty);
|
||||
}
|
||||
|
||||
break :fn_ty try Type.Tag.function.create(sema.arena, .{
|
||||
.param_types = param_types,
|
||||
.comptime_params = comptime_params.ptr,
|
||||
@ -15631,7 +15638,7 @@ fn zirRetLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir
|
||||
return sema.analyzeRet(block, operand, src);
|
||||
}
|
||||
|
||||
if (sema.wantErrorReturnTracing()) {
|
||||
if (sema.wantErrorReturnTracing(sema.fn_ret_ty)) {
|
||||
const is_non_err = try sema.analyzePtrIsNonErr(block, src, ret_ptr);
|
||||
return retWithErrTracing(sema, block, src, is_non_err, .ret_load, ret_ptr);
|
||||
}
|
||||
@ -15698,11 +15705,11 @@ fn retWithErrTracing(
|
||||
return always_noreturn;
|
||||
}
|
||||
|
||||
fn wantErrorReturnTracing(sema: *Sema) bool {
|
||||
fn wantErrorReturnTracing(sema: *Sema, fn_ret_ty: Type) bool {
|
||||
// TODO implement this feature in all the backends and then delete this check.
|
||||
const backend_supports_error_return_tracing = sema.mod.comp.bin_file.options.use_llvm;
|
||||
|
||||
return sema.fn_ret_ty.isError() and
|
||||
return fn_ret_ty.isError() and
|
||||
sema.mod.comp.bin_file.options.error_return_tracing and
|
||||
backend_supports_error_return_tracing;
|
||||
}
|
||||
@ -15754,7 +15761,7 @@ fn analyzeRet(
|
||||
|
||||
try sema.resolveTypeLayout(block, src, sema.fn_ret_ty);
|
||||
|
||||
if (sema.wantErrorReturnTracing()) {
|
||||
if (sema.wantErrorReturnTracing(sema.fn_ret_ty)) {
|
||||
// Avoid adding a frame to the error return trace in case the value is comptime-known
|
||||
// to be not an error.
|
||||
const is_non_err = try sema.analyzeIsNonErr(block, src, operand);
|
||||
|
@ -2332,10 +2332,13 @@ pub const Object = struct {
|
||||
// buffer is only used for int_type, `builtin` is a struct.
|
||||
const builtin_ty = mod.declPtr(builtin_decl).val.toType(undefined);
|
||||
const builtin_namespace = builtin_ty.getNamespace().?;
|
||||
const stack_trace_decl = builtin_namespace.decls
|
||||
const stack_trace_decl_index = builtin_namespace.decls
|
||||
.getKeyAdapted(stack_trace_str, Module.DeclAdapter{ .mod = mod }).?;
|
||||
const stack_trace_decl = mod.declPtr(stack_trace_decl_index);
|
||||
|
||||
return mod.declPtr(stack_trace_decl).val.toType(undefined);
|
||||
// Sema should have ensured that StackTrace was analyzed.
|
||||
assert(stack_trace_decl.has_tv);
|
||||
return stack_trace_decl.val.toType(undefined);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -97,4 +97,6 @@ pub fn addCases(cases: *tests.StandaloneContext) void {
|
||||
// Disabled due to tripping LLVM 13 assertion:
|
||||
// https://github.com/ziglang/zig/issues/12015
|
||||
//cases.add("tools/update_spirv_features.zig");
|
||||
|
||||
cases.addBuildFile("test/standalone/issue_13030/build.zig", .{ .build_modes = true });
|
||||
}
|
||||
|
18
test/standalone/issue_13030/build.zig
Normal file
18
test/standalone/issue_13030/build.zig
Normal file
@ -0,0 +1,18 @@
|
||||
const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
const Builder = std.build.Builder;
|
||||
const CrossTarget = std.zig.CrossTarget;
|
||||
|
||||
pub fn build(b: *Builder) void {
|
||||
const mode = b.standardReleaseOptions();
|
||||
const target = b.standardTargetOptions(.{});
|
||||
|
||||
const obj = b.addObject("main", "main.zig");
|
||||
obj.setBuildMode(mode);
|
||||
|
||||
obj.setTarget(target);
|
||||
b.default_step.dependOn(&obj.step);
|
||||
|
||||
const test_step = b.step("test", "Test the program");
|
||||
test_step.dependOn(&obj.step);
|
||||
}
|
7
test/standalone/issue_13030/main.zig
Normal file
7
test/standalone/issue_13030/main.zig
Normal file
@ -0,0 +1,7 @@
|
||||
fn b(comptime T: type) ?*const fn () error{}!T {
|
||||
return null;
|
||||
}
|
||||
|
||||
export fn entry() void {
|
||||
_ = b(void);
|
||||
}
|
Loading…
Reference in New Issue
Block a user