mirror of
https://github.com/ziglang/zig.git
synced 2026-02-19 07:48:31 +00:00
Merge pull request #13891 from Vexu/compile-errors
Organize and implement remaining stage1 compile errors
This commit is contained in:
commit
4af305b30a
@ -286,7 +286,7 @@ const Parser = struct {
|
||||
.keyword_comptime => switch (p.token_tags[p.tok_i + 1]) {
|
||||
.l_brace => {
|
||||
if (doc_comment) |some| {
|
||||
try p.warnMsg(.{ .tag = .test_doc_comment, .token = some });
|
||||
try p.warnMsg(.{ .tag = .comptime_doc_comment, .token = some });
|
||||
}
|
||||
const comptime_token = p.nextToken();
|
||||
const block = p.parseBlock() catch |err| switch (err) {
|
||||
|
||||
@ -4210,6 +4210,18 @@ test "zig fmt: remove newlines surrounding doc comment within container decl" {
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: invalid else branch statement" {
|
||||
try testError(
|
||||
\\/// This is a doc comment for a comptime block.
|
||||
\\comptime {}
|
||||
\\/// This is a doc comment for a test
|
||||
\\test "This is my test" {}
|
||||
, &[_]Error{
|
||||
.comptime_doc_comment,
|
||||
.test_doc_comment,
|
||||
});
|
||||
}
|
||||
|
||||
test "zig fmt: invalid else branch statement" {
|
||||
try testError(
|
||||
\\comptime {
|
||||
|
||||
@ -31,6 +31,7 @@ const clangMain = @import("main.zig").clangMain;
|
||||
const Module = @import("Module.zig");
|
||||
const Cache = @import("Cache.zig");
|
||||
const translate_c = @import("translate_c.zig");
|
||||
const clang = @import("clang.zig");
|
||||
const c_codegen = @import("codegen/c.zig");
|
||||
const ThreadPool = @import("ThreadPool.zig");
|
||||
const WaitGroup = @import("WaitGroup.zig");
|
||||
@ -2749,6 +2750,9 @@ pub fn totalErrorCount(self: *Compilation) usize {
|
||||
const decl = module.declPtr(key);
|
||||
if (decl.getFileScope().okToReportErrors()) {
|
||||
total += 1;
|
||||
if (module.cimport_errors.get(key)) |errors| {
|
||||
total += errors.len;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (module.emit_h) |emit_h| {
|
||||
@ -2858,6 +2862,23 @@ pub fn getAllErrorsAlloc(self: *Compilation) !AllErrors {
|
||||
// We'll try again once parsing succeeds.
|
||||
if (decl.getFileScope().okToReportErrors()) {
|
||||
try AllErrors.add(module, &arena, &errors, entry.value_ptr.*.*);
|
||||
if (module.cimport_errors.get(entry.key_ptr.*)) |cimport_errors| for (cimport_errors) |c_error| {
|
||||
if (c_error.path) |some|
|
||||
try errors.append(.{
|
||||
.src = .{
|
||||
.src_path = try arena_allocator.dupe(u8, std.mem.span(some)),
|
||||
.span = .{ .start = c_error.offset, .end = c_error.offset + 1, .main = c_error.offset },
|
||||
.msg = try arena_allocator.dupe(u8, std.mem.span(c_error.msg)),
|
||||
.line = c_error.line,
|
||||
.column = c_error.column,
|
||||
.source_line = if (c_error.source_line) |line| try arena_allocator.dupe(u8, std.mem.span(line)) else null,
|
||||
},
|
||||
})
|
||||
else
|
||||
try errors.append(.{
|
||||
.plain = .{ .msg = try arena_allocator.dupe(u8, std.mem.span(c_error.msg)) },
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3524,7 +3545,7 @@ test "cImport" {
|
||||
|
||||
const CImportResult = struct {
|
||||
out_zig_path: []u8,
|
||||
errors: []translate_c.ClangErrMsg,
|
||||
errors: []clang.ErrorMsg,
|
||||
};
|
||||
|
||||
/// Caller owns returned memory.
|
||||
@ -3599,7 +3620,7 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult {
|
||||
|
||||
const c_headers_dir_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{"include"});
|
||||
const c_headers_dir_path_z = try arena.dupeZ(u8, c_headers_dir_path);
|
||||
var clang_errors: []translate_c.ClangErrMsg = &[0]translate_c.ClangErrMsg{};
|
||||
var clang_errors: []clang.ErrorMsg = &[0]clang.ErrorMsg{};
|
||||
var tree = translate_c.translate(
|
||||
comp.gpa,
|
||||
new_argv.ptr,
|
||||
@ -3665,7 +3686,7 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult {
|
||||
}
|
||||
return CImportResult{
|
||||
.out_zig_path = out_zig_path,
|
||||
.errors = &[0]translate_c.ClangErrMsg{},
|
||||
.errors = &[0]clang.ErrorMsg{},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -31,6 +31,7 @@ const target_util = @import("target.zig");
|
||||
const build_options = @import("build_options");
|
||||
const Liveness = @import("Liveness.zig");
|
||||
const isUpDir = @import("introspect.zig").isUpDir;
|
||||
const clang = @import("clang.zig");
|
||||
|
||||
/// General-purpose allocator. Used for both temporary and long-term storage.
|
||||
gpa: Allocator,
|
||||
@ -111,6 +112,9 @@ failed_embed_files: std.AutoArrayHashMapUnmanaged(*EmbedFile, *ErrorMsg) = .{},
|
||||
/// Using a map here for consistency with the other fields here.
|
||||
/// The ErrorMsg memory is owned by the `Export`, using Module's general purpose allocator.
|
||||
failed_exports: std.AutoArrayHashMapUnmanaged(*Export, *ErrorMsg) = .{},
|
||||
/// If a decl failed due to a cimport error, the corresponding Clang errors
|
||||
/// are stored here.
|
||||
cimport_errors: std.AutoArrayHashMapUnmanaged(Decl.Index, []CImportError) = .{},
|
||||
|
||||
/// Candidates for deletion. After a semantic analysis update completes, this list
|
||||
/// contains Decls that need to be deleted if they end up having no references to them.
|
||||
@ -172,6 +176,21 @@ reference_table: std.AutoHashMapUnmanaged(Decl.Index, struct {
|
||||
src: LazySrcLoc,
|
||||
}) = .{},
|
||||
|
||||
pub const CImportError = struct {
|
||||
offset: u32,
|
||||
line: u32,
|
||||
column: u32,
|
||||
path: ?[*:0]u8,
|
||||
source_line: ?[*:0]u8,
|
||||
msg: [*:0]u8,
|
||||
|
||||
pub fn deinit(err: CImportError, gpa: Allocator) void {
|
||||
if (err.path) |some| gpa.free(std.mem.span(some));
|
||||
if (err.source_line) |some| gpa.free(std.mem.span(some));
|
||||
gpa.free(std.mem.span(err.msg));
|
||||
}
|
||||
};
|
||||
|
||||
pub const StringLiteralContext = struct {
|
||||
bytes: *ArrayListUnmanaged(u8),
|
||||
|
||||
@ -3449,6 +3468,11 @@ pub fn deinit(mod: *Module) void {
|
||||
}
|
||||
mod.failed_exports.deinit(gpa);
|
||||
|
||||
for (mod.cimport_errors.values()) |errs| {
|
||||
for (errs) |err| err.deinit(gpa);
|
||||
}
|
||||
mod.cimport_errors.deinit(gpa);
|
||||
|
||||
mod.compile_log_decls.deinit(gpa);
|
||||
|
||||
for (mod.decl_exports.values()) |*export_list| {
|
||||
@ -5381,6 +5405,9 @@ pub fn clearDecl(
|
||||
if (mod.failed_decls.fetchSwapRemove(decl_index)) |kv| {
|
||||
kv.value.destroy(gpa);
|
||||
}
|
||||
if (mod.cimport_errors.fetchSwapRemove(decl_index)) |kv| {
|
||||
for (kv.value) |err| err.deinit(gpa);
|
||||
}
|
||||
if (mod.emit_h) |emit_h| {
|
||||
if (emit_h.failed_decls.fetchSwapRemove(decl_index)) |kv| {
|
||||
kv.value.destroy(gpa);
|
||||
@ -5768,6 +5795,9 @@ fn markOutdatedDecl(mod: *Module, decl_index: Decl.Index) !void {
|
||||
if (mod.failed_decls.fetchSwapRemove(decl_index)) |kv| {
|
||||
kv.value.destroy(mod.gpa);
|
||||
}
|
||||
if (mod.cimport_errors.fetchSwapRemove(decl_index)) |kv| {
|
||||
for (kv.value) |err| err.deinit(mod.gpa);
|
||||
}
|
||||
if (decl.has_tv and decl.owns_tv) {
|
||||
if (decl.val.castTag(.function)) |payload| {
|
||||
const func = payload.data;
|
||||
|
||||
344
src/Sema.zig
344
src/Sema.zig
@ -2257,6 +2257,9 @@ fn failWithOwnedErrorMsg(sema: *Sema, err_msg: *Module.ErrorMsg) CompileError {
|
||||
sema.owner_decl.analysis = .sema_failure;
|
||||
sema.owner_decl.generation = mod.generation;
|
||||
}
|
||||
if (sema.func) |func| {
|
||||
func.state = .sema_failure;
|
||||
}
|
||||
const gop = mod.failed_decls.getOrPutAssumeCapacity(sema.owner_decl_index);
|
||||
if (gop.found_existing) {
|
||||
// If there are multiple errors for the same Decl, prefer the first one added.
|
||||
@ -4109,6 +4112,8 @@ fn validateUnionInit(
|
||||
const union_init = try sema.addConstant(union_ty, union_val);
|
||||
try sema.storePtr2(block, init_src, union_ptr, init_src, union_init, init_src, .store);
|
||||
return;
|
||||
} else if (try sema.typeRequiresComptime(union_ty)) {
|
||||
return sema.failWithNeededComptime(block, field_ptr_data.src(), "initializer of comptime only union must be comptime-known");
|
||||
}
|
||||
|
||||
const new_tag = try sema.addConstant(tag_ty, tag_val);
|
||||
@ -4226,6 +4231,7 @@ fn validateStructInit(
|
||||
var first_block_index = block.instructions.items.len;
|
||||
var make_runtime = false;
|
||||
|
||||
const require_comptime = try sema.typeRequiresComptime(struct_ty);
|
||||
const air_tags = sema.air_instructions.items(.tag);
|
||||
const air_datas = sema.air_instructions.items(.data);
|
||||
|
||||
@ -4301,6 +4307,9 @@ fn validateStructInit(
|
||||
}
|
||||
if (try sema.resolveMaybeUndefValAllowVariablesMaybeRuntime(bin_op.rhs, &make_runtime)) |val| {
|
||||
field_values[i] = val;
|
||||
} else if (require_comptime) {
|
||||
const field_ptr_data = sema.code.instructions.items(.data)[field_ptr].pl_node;
|
||||
return sema.failWithNeededComptime(block, field_ptr_data.src(), "initializer of comptime only struct must be comptime-known");
|
||||
} else {
|
||||
struct_is_comptime = false;
|
||||
}
|
||||
@ -5121,20 +5130,58 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr
|
||||
|
||||
if (c_import_res.errors.len != 0) {
|
||||
const msg = msg: {
|
||||
defer @import("clang.zig").ErrorMsg.delete(c_import_res.errors.ptr, c_import_res.errors.len);
|
||||
|
||||
const msg = try sema.errMsg(&child_block, src, "C import failed", .{});
|
||||
errdefer msg.destroy(sema.gpa);
|
||||
|
||||
if (!mod.comp.bin_file.options.link_libc)
|
||||
try sema.errNote(&child_block, src, msg, "libc headers not available; compilation does not link against libc", .{});
|
||||
|
||||
for (c_import_res.errors) |_| {
|
||||
// TODO integrate with LazySrcLoc
|
||||
// try mod.errNoteNonLazy(.{}, msg, "{s}", .{clang_err.msg_ptr[0..clang_err.msg_len]});
|
||||
// if (clang_err.filename_ptr) |p| p[0..clang_err.filename_len] else "(no file)",
|
||||
// clang_err.line + 1,
|
||||
// clang_err.column + 1,
|
||||
const gop = try sema.mod.cimport_errors.getOrPut(sema.gpa, sema.owner_decl_index);
|
||||
if (!gop.found_existing) {
|
||||
var errs = try std.ArrayListUnmanaged(Module.CImportError).initCapacity(sema.gpa, c_import_res.errors.len);
|
||||
errdefer {
|
||||
for (errs.items) |err| err.deinit(sema.gpa);
|
||||
errs.deinit(sema.gpa);
|
||||
}
|
||||
|
||||
for (c_import_res.errors) |c_error| {
|
||||
const path = if (c_error.filename_ptr) |some|
|
||||
try sema.gpa.dupeZ(u8, some[0..c_error.filename_len])
|
||||
else
|
||||
null;
|
||||
errdefer if (path) |some| sema.gpa.free(some);
|
||||
|
||||
const c_msg = try sema.gpa.dupeZ(u8, c_error.msg_ptr[0..c_error.msg_len]);
|
||||
errdefer sema.gpa.free(c_msg);
|
||||
|
||||
const line = line: {
|
||||
const source = c_error.source orelse break :line null;
|
||||
var start = c_error.offset;
|
||||
while (start > 0) : (start -= 1) {
|
||||
if (source[start - 1] == '\n') break;
|
||||
}
|
||||
var end = c_error.offset;
|
||||
while (true) : (end += 1) {
|
||||
if (source[end] == 0) break;
|
||||
if (source[end] == '\n') break;
|
||||
}
|
||||
break :line try sema.gpa.dupeZ(u8, source[start..end]);
|
||||
};
|
||||
errdefer if (line) |some| sema.gpa.free(some);
|
||||
|
||||
errs.appendAssumeCapacity(.{
|
||||
.path = path orelse null,
|
||||
.source_line = line orelse null,
|
||||
.line = c_error.line,
|
||||
.column = c_error.column,
|
||||
.offset = c_error.offset,
|
||||
.msg = c_msg,
|
||||
});
|
||||
}
|
||||
gop.value_ptr.* = errs.items;
|
||||
}
|
||||
@import("clang.zig").Stage2ErrorMsg.delete(c_import_res.errors.ptr, c_import_res.errors.len);
|
||||
break :msg msg;
|
||||
};
|
||||
return sema.failWithOwnedErrorMsg(msg);
|
||||
@ -5402,7 +5449,7 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
|
||||
const options = sema.resolveExportOptions(block, .unneeded, extra.options) catch |err| switch (err) {
|
||||
error.NeededSourceLocation => {
|
||||
_ = try sema.resolveExportOptions(block, options_src, extra.options);
|
||||
return error.AnalysisFail;
|
||||
unreachable;
|
||||
},
|
||||
else => |e| return e,
|
||||
};
|
||||
@ -5429,7 +5476,7 @@ fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
|
||||
const options = sema.resolveExportOptions(block, .unneeded, extra.options) catch |err| switch (err) {
|
||||
error.NeededSourceLocation => {
|
||||
_ = try sema.resolveExportOptions(block, options_src, extra.options);
|
||||
return error.AnalysisFail;
|
||||
unreachable;
|
||||
},
|
||||
else => |e| return e,
|
||||
};
|
||||
@ -6379,6 +6426,7 @@ fn analyzeCall(
|
||||
}),
|
||||
else => unreachable,
|
||||
};
|
||||
if (!is_comptime_call and module_fn.state == .sema_failure) return error.AnalysisFail;
|
||||
|
||||
// Analyze the ZIR. The same ZIR gets analyzed into a runtime function
|
||||
// or an inlined call depending on what union tag the `label` field is
|
||||
@ -6512,7 +6560,7 @@ fn analyzeCall(
|
||||
func_ty_info.param_types,
|
||||
func,
|
||||
);
|
||||
return error.AnalysisFail;
|
||||
unreachable;
|
||||
},
|
||||
else => |e| return e,
|
||||
};
|
||||
@ -6674,7 +6722,7 @@ fn analyzeCall(
|
||||
uncasted_arg,
|
||||
opts,
|
||||
);
|
||||
return error.AnalysisFail;
|
||||
unreachable;
|
||||
},
|
||||
else => |e| return e,
|
||||
};
|
||||
@ -6687,7 +6735,7 @@ fn analyzeCall(
|
||||
uncasted_arg,
|
||||
Module.argSrc(call_src.node_offset.x, sema.gpa, decl, i, bound_arg_src),
|
||||
);
|
||||
return error.AnalysisFail;
|
||||
unreachable;
|
||||
},
|
||||
else => |e| return e,
|
||||
};
|
||||
@ -6991,7 +7039,7 @@ fn instantiateGenericCall(
|
||||
const decl = sema.mod.declPtr(block.src_decl);
|
||||
const arg_src = Module.argSrc(call_src.node_offset.x, sema.gpa, decl, i, bound_arg_src);
|
||||
_ = try sema.analyzeGenericCallArgVal(block, arg_src, uncasted_args[i]);
|
||||
return error.AnalysisFail;
|
||||
unreachable;
|
||||
},
|
||||
else => |e| return e,
|
||||
};
|
||||
@ -7174,7 +7222,7 @@ fn instantiateGenericCall(
|
||||
const decl = sema.mod.declPtr(block.src_decl);
|
||||
const arg_src = Module.argSrc(call_src.node_offset.x, sema.gpa, decl, arg_i, bound_arg_src);
|
||||
_ = try sema.resolveConstValue(block, arg_src, arg, "argument to parameter with comptime-only type must be comptime-known");
|
||||
return error.AnalysisFail;
|
||||
unreachable;
|
||||
},
|
||||
else => |e| return e,
|
||||
};
|
||||
@ -7330,7 +7378,7 @@ fn instantiateGenericCall(
|
||||
new_fn_info,
|
||||
&runtime_i,
|
||||
);
|
||||
return error.AnalysisFail;
|
||||
unreachable;
|
||||
},
|
||||
else => |e| return e,
|
||||
};
|
||||
@ -8417,6 +8465,10 @@ fn funcCommon(
|
||||
const param_types = try sema.arena.alloc(Type, block.params.items.len);
|
||||
const comptime_params = try sema.arena.alloc(bool, block.params.items.len);
|
||||
for (block.params.items) |param, i| {
|
||||
const is_noalias = blk: {
|
||||
const index = std.math.cast(u5, i) orelse break :blk false;
|
||||
break :blk @truncate(u1, noalias_bits >> index) != 0;
|
||||
};
|
||||
param_types[i] = param.ty;
|
||||
sema.analyzeParameter(
|
||||
block,
|
||||
@ -8427,6 +8479,7 @@ fn funcCommon(
|
||||
&is_generic,
|
||||
cc_resolved,
|
||||
has_body,
|
||||
is_noalias,
|
||||
) catch |err| switch (err) {
|
||||
error.NeededSourceLocation => {
|
||||
const decl = sema.mod.declPtr(block.src_decl);
|
||||
@ -8439,8 +8492,9 @@ fn funcCommon(
|
||||
&is_generic,
|
||||
cc_resolved,
|
||||
has_body,
|
||||
is_noalias,
|
||||
);
|
||||
return error.AnalysisFail;
|
||||
unreachable;
|
||||
},
|
||||
else => |e| return e,
|
||||
};
|
||||
@ -8689,6 +8743,7 @@ fn analyzeParameter(
|
||||
is_generic: *bool,
|
||||
cc: std.builtin.CallingConvention,
|
||||
has_body: bool,
|
||||
is_noalias: bool,
|
||||
) !void {
|
||||
const requires_comptime = try sema.typeRequiresComptime(param.ty);
|
||||
comptime_params[i] = param.is_comptime or requires_comptime;
|
||||
@ -8743,6 +8798,9 @@ fn analyzeParameter(
|
||||
};
|
||||
return sema.failWithOwnedErrorMsg(msg);
|
||||
}
|
||||
if (!this_generic and is_noalias and !param.ty.isPtrAtRuntime()) {
|
||||
return sema.fail(block, param_src, "non-pointer parameter declared noalias", .{});
|
||||
}
|
||||
}
|
||||
|
||||
fn zirParam(
|
||||
@ -10633,7 +10691,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
|
||||
const case_src = Module.SwitchProngSrc{ .range = .{ .prong = multi_i, .item = range_i } };
|
||||
const decl = sema.mod.declPtr(case_block.src_decl);
|
||||
try sema.emitBackwardBranch(block, case_src.resolve(sema.gpa, decl, src_node_offset, .none));
|
||||
return error.AnalysisFail;
|
||||
unreachable;
|
||||
},
|
||||
else => return err,
|
||||
};
|
||||
@ -10669,7 +10727,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
|
||||
const case_src = Module.SwitchProngSrc{ .multi = .{ .prong = multi_i, .item = @intCast(u32, item_i) } };
|
||||
const decl = sema.mod.declPtr(case_block.src_decl);
|
||||
try sema.emitBackwardBranch(block, case_src.resolve(sema.gpa, decl, src_node_offset, .none));
|
||||
return error.AnalysisFail;
|
||||
unreachable;
|
||||
},
|
||||
else => return err,
|
||||
};
|
||||
@ -11101,10 +11159,8 @@ fn resolveSwitchItemVal(
|
||||
} else |err| switch (err) {
|
||||
error.NeededSourceLocation => {
|
||||
const src = switch_prong_src.resolve(sema.gpa, sema.mod.declPtr(block.src_decl), switch_node_offset, range_expand);
|
||||
return TypedValue{
|
||||
.ty = item_ty,
|
||||
.val = try sema.resolveConstValue(block, src, item, "switch prong values must be comptime-known"),
|
||||
};
|
||||
_ = try sema.resolveConstValue(block, src, item, "switch prong values must be comptime-known");
|
||||
unreachable;
|
||||
},
|
||||
else => |e| return e,
|
||||
}
|
||||
@ -11618,6 +11674,21 @@ fn zirShl(
|
||||
});
|
||||
}
|
||||
}
|
||||
if (rhs_ty.zigTypeTag() == .Vector) {
|
||||
var i: usize = 0;
|
||||
while (i < rhs_ty.vectorLen()) : (i += 1) {
|
||||
if (rhs_val.indexVectorlike(i).compareHetero(.lt, Value.zero, target)) {
|
||||
return sema.fail(block, rhs_src, "shift by negative amount '{}' at index '{d}'", .{
|
||||
rhs_val.indexVectorlike(i).fmtValue(scalar_ty, sema.mod),
|
||||
i,
|
||||
});
|
||||
}
|
||||
}
|
||||
} else if (rhs_val.compareHetero(.lt, Value.zero, target)) {
|
||||
return sema.fail(block, rhs_src, "shift by negative amount '{}'", .{
|
||||
rhs_val.fmtValue(scalar_ty, sema.mod),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const runtime_src = if (maybe_lhs_val) |lhs_val| rs: {
|
||||
@ -11787,6 +11858,21 @@ fn zirShr(
|
||||
});
|
||||
}
|
||||
}
|
||||
if (rhs_ty.zigTypeTag() == .Vector) {
|
||||
var i: usize = 0;
|
||||
while (i < rhs_ty.vectorLen()) : (i += 1) {
|
||||
if (rhs_val.indexVectorlike(i).compareHetero(.lt, Value.zero, target)) {
|
||||
return sema.fail(block, rhs_src, "shift by negative amount '{}' at index '{d}'", .{
|
||||
rhs_val.indexVectorlike(i).fmtValue(scalar_ty, sema.mod),
|
||||
i,
|
||||
});
|
||||
}
|
||||
}
|
||||
} else if (rhs_val.compareHetero(.lt, Value.zero, target)) {
|
||||
return sema.fail(block, rhs_src, "shift by negative amount '{}'", .{
|
||||
rhs_val.fmtValue(scalar_ty, sema.mod),
|
||||
});
|
||||
}
|
||||
if (maybe_lhs_val) |lhs_val| {
|
||||
if (lhs_val.isUndef()) {
|
||||
return sema.addConstUndef(lhs_ty);
|
||||
@ -14721,7 +14807,9 @@ fn analyzeCmp(
|
||||
) CompileError!Air.Inst.Ref {
|
||||
const lhs_ty = sema.typeOf(lhs);
|
||||
const rhs_ty = sema.typeOf(rhs);
|
||||
try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
|
||||
if (lhs_ty.zigTypeTag() != .Optional and rhs_ty.zigTypeTag() != .Optional) {
|
||||
try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
|
||||
}
|
||||
|
||||
if (lhs_ty.zigTypeTag() == .Vector and rhs_ty.zigTypeTag() == .Vector) {
|
||||
return sema.cmpVector(block, src, lhs, rhs, op, lhs_src, rhs_src);
|
||||
@ -15217,12 +15305,17 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
|
||||
try Value.Tag.ty.create(params_anon_decl.arena(), try param_ty.copy(params_anon_decl.arena())),
|
||||
);
|
||||
|
||||
const is_noalias = blk: {
|
||||
const index = std.math.cast(u5, i) orelse break :blk false;
|
||||
break :blk @truncate(u1, info.noalias_bits >> index) != 0;
|
||||
};
|
||||
|
||||
const param_fields = try params_anon_decl.arena().create([3]Value);
|
||||
param_fields.* = .{
|
||||
// is_generic: bool,
|
||||
Value.makeBool(is_generic),
|
||||
// is_noalias: bool,
|
||||
Value.false, // TODO
|
||||
Value.makeBool(is_noalias),
|
||||
// arg_type: ?type,
|
||||
param_ty_val,
|
||||
};
|
||||
@ -17409,7 +17502,7 @@ fn zirStructInitAnon(
|
||||
const decl = sema.mod.declPtr(block.src_decl);
|
||||
const field_src = Module.initSrc(src.node_offset.x, sema.gpa, decl, runtime_index);
|
||||
try sema.requireRuntimeBlock(block, src, field_src);
|
||||
return error.AnalysisFail;
|
||||
unreachable;
|
||||
},
|
||||
else => |e| return e,
|
||||
};
|
||||
@ -17474,25 +17567,31 @@ fn zirArrayInit(
|
||||
defer gpa.free(resolved_args);
|
||||
for (args[1..]) |arg, i| {
|
||||
const resolved_arg = try sema.resolveInst(arg);
|
||||
const arg_src = src; // TODO better source location
|
||||
const elem_ty = if (array_ty.zigTypeTag() == .Struct)
|
||||
array_ty.structFieldType(i)
|
||||
else
|
||||
array_ty.elemType2();
|
||||
resolved_args[i] = try sema.coerce(block, elem_ty, resolved_arg, arg_src);
|
||||
resolved_args[i] = sema.coerce(block, elem_ty, resolved_arg, .unneeded) catch |err| switch (err) {
|
||||
error.NeededSourceLocation => {
|
||||
const decl = sema.mod.declPtr(block.src_decl);
|
||||
const elem_src = Module.initSrc(src.node_offset.x, sema.gpa, decl, i);
|
||||
_ = try sema.coerce(block, elem_ty, resolved_arg, elem_src);
|
||||
unreachable;
|
||||
},
|
||||
else => return err,
|
||||
};
|
||||
}
|
||||
|
||||
if (sentinel_val) |some| {
|
||||
resolved_args[resolved_args.len - 1] = try sema.addConstant(array_ty.elemType2(), some);
|
||||
}
|
||||
|
||||
const opt_runtime_src: ?LazySrcLoc = for (resolved_args) |arg| {
|
||||
const arg_src = src; // TODO better source location
|
||||
const opt_runtime_index: ?u32 = for (resolved_args) |arg, i| {
|
||||
const comptime_known = try sema.isComptimeKnown(arg);
|
||||
if (!comptime_known) break arg_src;
|
||||
if (!comptime_known) break @intCast(u32, i);
|
||||
} else null;
|
||||
|
||||
const runtime_src = opt_runtime_src orelse {
|
||||
const runtime_index = opt_runtime_index orelse {
|
||||
const elem_vals = try sema.arena.alloc(Value, resolved_args.len);
|
||||
|
||||
for (resolved_args) |arg, i| {
|
||||
@ -17504,7 +17603,15 @@ fn zirArrayInit(
|
||||
return sema.addConstantMaybeRef(block, array_ty, array_val, is_ref);
|
||||
};
|
||||
|
||||
try sema.requireRuntimeBlock(block, src, runtime_src);
|
||||
sema.requireRuntimeBlock(block, src, .unneeded) catch |err| switch (err) {
|
||||
error.NeededSourceLocation => {
|
||||
const decl = sema.mod.declPtr(block.src_decl);
|
||||
const elem_src = Module.initSrc(src.node_offset.x, sema.gpa, decl, runtime_index);
|
||||
try sema.requireRuntimeBlock(block, src, elem_src);
|
||||
unreachable;
|
||||
},
|
||||
else => return err,
|
||||
};
|
||||
try sema.queueFullTypeResolution(array_ty);
|
||||
|
||||
if (is_ref) {
|
||||
@ -18502,10 +18609,47 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in
|
||||
}
|
||||
|
||||
var buffer: Value.ToTypeBuffer = undefined;
|
||||
const field_ty = try field_type_val.toType(&buffer).copy(new_decl_arena_allocator);
|
||||
gop.value_ptr.* = .{
|
||||
.ty = try field_type_val.toType(&buffer).copy(new_decl_arena_allocator),
|
||||
.ty = field_ty,
|
||||
.abi_align = @intCast(u32, (try alignment_val.getUnsignedIntAdvanced(target, sema)).?),
|
||||
};
|
||||
|
||||
if (field_ty.zigTypeTag() == .Opaque) {
|
||||
const msg = msg: {
|
||||
const msg = try sema.errMsg(block, src, "opaque types have unknown size and therefore cannot be directly embedded in unions", .{});
|
||||
errdefer msg.destroy(sema.gpa);
|
||||
|
||||
try sema.addDeclaredHereNote(msg, field_ty);
|
||||
break :msg msg;
|
||||
};
|
||||
return sema.failWithOwnedErrorMsg(msg);
|
||||
}
|
||||
if (union_obj.layout == .Extern and !try sema.validateExternType(field_ty, .union_field)) {
|
||||
const msg = msg: {
|
||||
const msg = try sema.errMsg(block, src, "extern unions cannot contain fields of type '{}'", .{field_ty.fmt(sema.mod)});
|
||||
errdefer msg.destroy(sema.gpa);
|
||||
|
||||
const src_decl = sema.mod.declPtr(block.src_decl);
|
||||
try sema.explainWhyTypeIsNotExtern(msg, src.toSrcLoc(src_decl), field_ty, .union_field);
|
||||
|
||||
try sema.addDeclaredHereNote(msg, field_ty);
|
||||
break :msg msg;
|
||||
};
|
||||
return sema.failWithOwnedErrorMsg(msg);
|
||||
} else if (union_obj.layout == .Packed and !(validatePackedType(field_ty))) {
|
||||
const msg = msg: {
|
||||
const msg = try sema.errMsg(block, src, "packed unions cannot contain fields of type '{}'", .{field_ty.fmt(sema.mod)});
|
||||
errdefer msg.destroy(sema.gpa);
|
||||
|
||||
const src_decl = sema.mod.declPtr(block.src_decl);
|
||||
try sema.explainWhyTypeIsNotPacked(msg, src.toSrcLoc(src_decl), field_ty);
|
||||
|
||||
try sema.addDeclaredHereNote(msg, field_ty);
|
||||
break :msg msg;
|
||||
};
|
||||
return sema.failWithOwnedErrorMsg(msg);
|
||||
}
|
||||
}
|
||||
|
||||
if (tag_ty_field_names) |names| {
|
||||
@ -18587,21 +18731,25 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in
|
||||
// is_noalias: bool,
|
||||
const arg_is_noalias = arg_val[1].toBool();
|
||||
// arg_type: ?type,
|
||||
const param_type_val = arg_val[2];
|
||||
const param_type_opt_val = arg_val[2];
|
||||
|
||||
if (arg_is_generic) {
|
||||
return sema.fail(block, src, "Type.Fn.Param.is_generic must be false for @Type", .{});
|
||||
}
|
||||
|
||||
const param_type_val = param_type_opt_val.optionalValue() orelse
|
||||
return sema.fail(block, src, "Type.Fn.Param.arg_type must be non-null for @Type", .{});
|
||||
const param_type = try param_type_val.toType(&buf).copy(sema.arena);
|
||||
|
||||
if (arg_is_noalias) {
|
||||
noalias_bits = @as(u32, 1) << (std.math.cast(u5, i) orelse
|
||||
if (!param_type.isPtrAtRuntime()) {
|
||||
return sema.fail(block, src, "non-pointer parameter declared noalias", .{});
|
||||
}
|
||||
noalias_bits |= @as(u32, 1) << (std.math.cast(u5, i) orelse
|
||||
return sema.fail(block, src, "this compiler implementation only supports 'noalias' on the first 32 parameters", .{}));
|
||||
}
|
||||
|
||||
const param_type = param_type_val.optionalValue() orelse
|
||||
return sema.fail(block, src, "Type.Fn.Param.arg_type must be non-null for @Type", .{});
|
||||
|
||||
param_types[i] = try param_type.toType(&buf).copy(sema.arena);
|
||||
param_types[i] = param_type;
|
||||
comptime_params[i] = false;
|
||||
}
|
||||
|
||||
@ -18745,13 +18893,60 @@ fn reifyStruct(
|
||||
}
|
||||
|
||||
var buffer: Value.ToTypeBuffer = undefined;
|
||||
const field_ty = try field_type_val.toType(&buffer).copy(new_decl_arena_allocator);
|
||||
gop.value_ptr.* = .{
|
||||
.ty = try field_type_val.toType(&buffer).copy(new_decl_arena_allocator),
|
||||
.ty = field_ty,
|
||||
.abi_align = abi_align,
|
||||
.default_val = default_val,
|
||||
.is_comptime = is_comptime_val.toBool(),
|
||||
.offset = undefined,
|
||||
};
|
||||
|
||||
if (field_ty.zigTypeTag() == .Opaque) {
|
||||
const msg = msg: {
|
||||
const msg = try sema.errMsg(block, src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});
|
||||
errdefer msg.destroy(sema.gpa);
|
||||
|
||||
try sema.addDeclaredHereNote(msg, field_ty);
|
||||
break :msg msg;
|
||||
};
|
||||
return sema.failWithOwnedErrorMsg(msg);
|
||||
}
|
||||
if (field_ty.zigTypeTag() == .NoReturn) {
|
||||
const msg = msg: {
|
||||
const msg = try sema.errMsg(block, src, "struct fields cannot be 'noreturn'", .{});
|
||||
errdefer msg.destroy(sema.gpa);
|
||||
|
||||
try sema.addDeclaredHereNote(msg, field_ty);
|
||||
break :msg msg;
|
||||
};
|
||||
return sema.failWithOwnedErrorMsg(msg);
|
||||
}
|
||||
if (struct_obj.layout == .Extern and !try sema.validateExternType(field_ty, .struct_field)) {
|
||||
const msg = msg: {
|
||||
const msg = try sema.errMsg(block, src, "extern structs cannot contain fields of type '{}'", .{field_ty.fmt(sema.mod)});
|
||||
errdefer msg.destroy(sema.gpa);
|
||||
|
||||
const src_decl = sema.mod.declPtr(block.src_decl);
|
||||
try sema.explainWhyTypeIsNotExtern(msg, src.toSrcLoc(src_decl), field_ty, .struct_field);
|
||||
|
||||
try sema.addDeclaredHereNote(msg, field_ty);
|
||||
break :msg msg;
|
||||
};
|
||||
return sema.failWithOwnedErrorMsg(msg);
|
||||
} else if (struct_obj.layout == .Packed and !(validatePackedType(field_ty))) {
|
||||
const msg = msg: {
|
||||
const msg = try sema.errMsg(block, src, "packed structs cannot contain fields of type '{}'", .{field_ty.fmt(sema.mod)});
|
||||
errdefer msg.destroy(sema.gpa);
|
||||
|
||||
const src_decl = sema.mod.declPtr(block.src_decl);
|
||||
try sema.explainWhyTypeIsNotPacked(msg, src.toSrcLoc(src_decl), field_ty);
|
||||
|
||||
try sema.addDeclaredHereNote(msg, field_ty);
|
||||
break :msg msg;
|
||||
};
|
||||
return sema.failWithOwnedErrorMsg(msg);
|
||||
}
|
||||
}
|
||||
|
||||
if (layout == .Packed) {
|
||||
@ -21544,7 +21739,7 @@ fn zirPrefetch(
|
||||
const options = sema.resolvePrefetchOptions(block, .unneeded, extra.rhs) catch |err| switch (err) {
|
||||
error.NeededSourceLocation => {
|
||||
_ = try sema.resolvePrefetchOptions(block, opts_src, extra.rhs);
|
||||
return error.AnalysisFail;
|
||||
unreachable;
|
||||
},
|
||||
else => |e| return e,
|
||||
};
|
||||
@ -21637,7 +21832,7 @@ fn zirBuiltinExtern(
|
||||
const options = sema.resolveExternOptions(block, .unneeded, extra.rhs) catch |err| switch (err) {
|
||||
error.NeededSourceLocation => {
|
||||
_ = try sema.resolveExternOptions(block, options_src, extra.rhs);
|
||||
return error.AnalysisFail;
|
||||
unreachable;
|
||||
},
|
||||
else => |e| return e,
|
||||
};
|
||||
@ -24493,7 +24688,7 @@ fn coerceExtra(
|
||||
}
|
||||
if (try sema.resolveMaybeUndefVal(inst)) |val| {
|
||||
const result_val = try val.floatCast(sema.arena, dest_ty, target);
|
||||
if (!val.eql(result_val, dest_ty, sema.mod)) {
|
||||
if (!val.eql(result_val, inst_ty, sema.mod)) {
|
||||
return sema.fail(
|
||||
block,
|
||||
inst_src,
|
||||
@ -24987,7 +25182,7 @@ const InMemoryCoercionResult = union(enum) {
|
||||
cur = param.child;
|
||||
},
|
||||
.fn_cc => |cc| {
|
||||
try sema.errNote(block, src, msg, "calling convention {s} cannot cast into calling convention {s}", .{ @tagName(cc.actual), @tagName(cc.wanted) });
|
||||
try sema.errNote(block, src, msg, "calling convention '{s}' cannot cast into calling convention '{s}'", .{ @tagName(cc.actual), @tagName(cc.wanted) });
|
||||
break;
|
||||
},
|
||||
.fn_return_type => |pair| {
|
||||
@ -26842,6 +27037,9 @@ fn coerceCompatiblePtrs(
|
||||
) !Air.Inst.Ref {
|
||||
const inst_ty = sema.typeOf(inst);
|
||||
if (try sema.resolveMaybeUndefVal(inst)) |val| {
|
||||
if (!val.isUndef() and val.isNull() and !dest_ty.isAllowzeroPtr()) {
|
||||
return sema.fail(block, inst_src, "null pointer casted to type '{}'", .{dest_ty.fmt(sema.mod)});
|
||||
}
|
||||
// The comptime Value representation is compatible with both types.
|
||||
return sema.addConstant(dest_ty, val);
|
||||
}
|
||||
@ -30177,7 +30375,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void
|
||||
const tree = try sema.getAstTree(&block_scope);
|
||||
const init_src = containerFieldInitSrcLoc(decl, tree.*, 0, i);
|
||||
_ = try sema.coerce(&block_scope, field.ty, init, init_src);
|
||||
return error.AnalysisFail;
|
||||
unreachable;
|
||||
},
|
||||
else => |e| return e,
|
||||
};
|
||||
@ -30304,6 +30502,25 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {
|
||||
if (int_tag_ty.zigTypeTag() != .Int and int_tag_ty.zigTypeTag() != .ComptimeInt) {
|
||||
return sema.fail(&block_scope, tag_ty_src, "expected integer tag type, found '{}'", .{int_tag_ty.fmt(sema.mod)});
|
||||
}
|
||||
|
||||
if (fields_len > 0) {
|
||||
var field_count_val: Value.Payload.U64 = .{
|
||||
.base = .{ .tag = .int_u64 },
|
||||
.data = fields_len - 1,
|
||||
};
|
||||
if (!(try sema.intFitsInType(Value.initPayload(&field_count_val.base), int_tag_ty, null))) {
|
||||
const msg = msg: {
|
||||
const msg = try sema.errMsg(&block_scope, tag_ty_src, "specified integer tag type cannot represent every field", .{});
|
||||
errdefer msg.destroy(sema.gpa);
|
||||
try sema.errNote(&block_scope, tag_ty_src, msg, "type '{}' cannot fit values in range 0...{d}", .{
|
||||
int_tag_ty.fmt(sema.mod),
|
||||
fields_len - 1,
|
||||
});
|
||||
break :msg msg;
|
||||
};
|
||||
return sema.failWithOwnedErrorMsg(msg);
|
||||
}
|
||||
}
|
||||
union_obj.tag_ty = try sema.generateUnionTagTypeNumbered(&block_scope, fields_len, provided_ty, union_obj);
|
||||
const enum_obj = union_obj.tag_ty.castTag(.enum_numbered).?.data;
|
||||
enum_field_names = &enum_obj.fields;
|
||||
@ -30379,7 +30596,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {
|
||||
} else .none;
|
||||
|
||||
if (enum_value_map) |map| {
|
||||
if (tag_ref != .none) {
|
||||
const copied_val = if (tag_ref != .none) blk: {
|
||||
const tag_src = src; // TODO better source location
|
||||
const coerced = try sema.coerce(&block_scope, int_tag_ty, tag_ref, tag_src);
|
||||
const val = try sema.resolveConstValue(&block_scope, tag_src, coerced, "enum tag value must be comptime-known");
|
||||
@ -30387,23 +30604,31 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {
|
||||
|
||||
// This puts the memory into the union arena, not the enum arena, but
|
||||
// it is OK since they share the same lifetime.
|
||||
const copied_val = try val.copy(decl_arena_allocator);
|
||||
map.putAssumeCapacityContext(copied_val, {}, .{
|
||||
.ty = int_tag_ty,
|
||||
.mod = mod,
|
||||
});
|
||||
} else {
|
||||
break :blk try val.copy(decl_arena_allocator);
|
||||
} else blk: {
|
||||
const val = if (last_tag_val) |val|
|
||||
try sema.intAdd(val, Value.one, int_tag_ty)
|
||||
else
|
||||
Value.zero;
|
||||
last_tag_val = val;
|
||||
|
||||
const copied_val = try val.copy(decl_arena_allocator);
|
||||
map.putAssumeCapacityContext(copied_val, {}, .{
|
||||
.ty = int_tag_ty,
|
||||
.mod = mod,
|
||||
});
|
||||
break :blk try val.copy(decl_arena_allocator);
|
||||
};
|
||||
const gop = map.getOrPutAssumeCapacityContext(copied_val, .{
|
||||
.ty = int_tag_ty,
|
||||
.mod = mod,
|
||||
});
|
||||
if (gop.found_existing) {
|
||||
const tree = try sema.getAstTree(&block_scope);
|
||||
const field_src = enumFieldSrcLoc(sema.mod.declPtr(block_scope.src_decl), tree.*, src.node_offset.x, field_i);
|
||||
const other_field_src = enumFieldSrcLoc(sema.mod.declPtr(block_scope.src_decl), tree.*, src.node_offset.x, gop.index);
|
||||
const msg = msg: {
|
||||
const msg = try sema.errMsg(&block_scope, field_src, "enum tag value {} already taken", .{copied_val.fmtValue(int_tag_ty, sema.mod)});
|
||||
errdefer msg.destroy(gpa);
|
||||
try sema.errNote(&block_scope, other_field_src, msg, "other occurrence here", .{});
|
||||
break :msg msg;
|
||||
};
|
||||
return sema.failWithOwnedErrorMsg(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@ -30574,16 +30799,17 @@ fn generateUnionTagTypeNumbered(
|
||||
new_decl.name_fully_qualified = true;
|
||||
errdefer mod.abortAnonDecl(new_decl_index);
|
||||
|
||||
const copied_int_ty = try int_ty.copy(new_decl_arena_allocator);
|
||||
enum_obj.* = .{
|
||||
.owner_decl = new_decl_index,
|
||||
.tag_ty = int_ty,
|
||||
.tag_ty = copied_int_ty,
|
||||
.fields = .{},
|
||||
.values = .{},
|
||||
};
|
||||
// Here we pre-allocate the maps using the decl arena.
|
||||
try enum_obj.fields.ensureTotalCapacity(new_decl_arena_allocator, fields_len);
|
||||
try enum_obj.values.ensureTotalCapacityContext(new_decl_arena_allocator, fields_len, .{
|
||||
.ty = int_ty,
|
||||
.ty = copied_int_ty,
|
||||
.mod = mod,
|
||||
});
|
||||
try new_decl.finalizeNewArena(&new_decl_arena);
|
||||
|
||||
@ -1897,13 +1897,13 @@ pub const OffsetOfNode_Kind = enum(c_int) {
|
||||
Base,
|
||||
};
|
||||
|
||||
pub const Stage2ErrorMsg = extern struct {
|
||||
pub const ErrorMsg = extern struct {
|
||||
filename_ptr: ?[*]const u8,
|
||||
filename_len: usize,
|
||||
msg_ptr: [*]const u8,
|
||||
msg_len: usize,
|
||||
// valid until the ASTUnit is freed
|
||||
source: ?[*]const u8,
|
||||
source: ?[*:0]const u8,
|
||||
// 0 based
|
||||
line: c_uint,
|
||||
// 0 based
|
||||
@ -1912,14 +1912,14 @@ pub const Stage2ErrorMsg = extern struct {
|
||||
offset: c_uint,
|
||||
|
||||
pub const delete = ZigClangErrorMsg_delete;
|
||||
extern fn ZigClangErrorMsg_delete(ptr: [*]Stage2ErrorMsg, len: usize) void;
|
||||
extern fn ZigClangErrorMsg_delete(ptr: [*]ErrorMsg, len: usize) void;
|
||||
};
|
||||
|
||||
pub const LoadFromCommandLine = ZigClangLoadFromCommandLine;
|
||||
extern fn ZigClangLoadFromCommandLine(
|
||||
args_begin: [*]?[*]const u8,
|
||||
args_end: [*]?[*]const u8,
|
||||
errors_ptr: *[*]Stage2ErrorMsg,
|
||||
errors_ptr: *[*]ErrorMsg,
|
||||
errors_len: *usize,
|
||||
resources_path: [*:0]const u8,
|
||||
) ?*ASTUnit;
|
||||
|
||||
@ -19,6 +19,7 @@ const introspect = @import("introspect.zig");
|
||||
const LibCInstallation = @import("libc_installation.zig").LibCInstallation;
|
||||
const wasi_libc = @import("wasi_libc.zig");
|
||||
const translate_c = @import("translate_c.zig");
|
||||
const clang = @import("clang.zig");
|
||||
const Cache = @import("Cache.zig");
|
||||
const target_util = @import("target.zig");
|
||||
const ThreadPool = @import("ThreadPool.zig");
|
||||
@ -3552,7 +3553,7 @@ fn cmdTranslateC(comp: *Compilation, arena: Allocator, enable_cache: bool) !void
|
||||
|
||||
const c_headers_dir_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{"include"});
|
||||
const c_headers_dir_path_z = try arena.dupeZ(u8, c_headers_dir_path);
|
||||
var clang_errors: []translate_c.ClangErrMsg = &[0]translate_c.ClangErrMsg{};
|
||||
var clang_errors: []clang.ErrorMsg = &[0]clang.ErrorMsg{};
|
||||
var tree = translate_c.translate(
|
||||
comp.gpa,
|
||||
new_argv.ptr,
|
||||
|
||||
@ -13,8 +13,6 @@ const Tag = Node.Tag;
|
||||
|
||||
const CallingConvention = std.builtin.CallingConvention;
|
||||
|
||||
pub const ClangErrMsg = clang.Stage2ErrorMsg;
|
||||
|
||||
pub const Error = std.mem.Allocator.Error;
|
||||
const MacroProcessingError = Error || error{UnexpectedMacroToken};
|
||||
const TypeError = Error || error{UnsupportedType};
|
||||
@ -350,7 +348,7 @@ pub fn translate(
|
||||
gpa: mem.Allocator,
|
||||
args_begin: [*]?[*]const u8,
|
||||
args_end: [*]?[*]const u8,
|
||||
errors: *[]ClangErrMsg,
|
||||
errors: *[]clang.ErrorMsg,
|
||||
resources_path: [*:0]const u8,
|
||||
) !std.zig.Ast {
|
||||
// TODO stage2 bug
|
||||
@ -5115,10 +5113,6 @@ pub fn failDecl(c: *Context, loc: clang.SourceLocation, name: []const u8, compti
|
||||
try c.global_scope.nodes.append(try Tag.warning.create(c.arena, location_comment));
|
||||
}
|
||||
|
||||
pub fn freeErrors(errors: []ClangErrMsg) void {
|
||||
errors.ptr.delete(errors.len);
|
||||
}
|
||||
|
||||
const PatternList = struct {
|
||||
patterns: []Pattern,
|
||||
|
||||
|
||||
@ -177,9 +177,10 @@ pub const Type = extern union {
|
||||
.Float,
|
||||
.ComptimeFloat,
|
||||
.ComptimeInt,
|
||||
.Vector, // TODO some vectors require is_equality_cmp==true
|
||||
=> true,
|
||||
|
||||
.Vector => ty.elemType2().isSelfComparable(is_equality_cmp),
|
||||
|
||||
.Bool,
|
||||
.Type,
|
||||
.Void,
|
||||
|
||||
@ -1465,3 +1465,12 @@ test "Namespace-like union" {
|
||||
var a: DepType.Version.Git = .tag;
|
||||
try expect(a.frozen());
|
||||
}
|
||||
|
||||
test "union int tag type is properly managed" {
|
||||
const Bar = union(enum(u2)) {
|
||||
x: bool,
|
||||
y: u8,
|
||||
z: u8,
|
||||
};
|
||||
try expect(@sizeOf(Bar) + 1 == 3);
|
||||
}
|
||||
|
||||
@ -0,0 +1,12 @@
|
||||
export fn a() void {
|
||||
var x: [10]u8 = undefined;
|
||||
var y: []align(16) u8 = &x;
|
||||
_ = y;
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// :3:29: error: expected type '[]align(16) u8', found '*[10]u8'
|
||||
// :3:29: note: pointer alignment '1' cannot cast into pointer alignment '16'
|
||||
@ -8,8 +8,8 @@ export fn entry2() void {
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// tmp.zig:2:20: error: expected type 'u29', found 'bool'
|
||||
// tmp.zig:6:19: error: fractional component prevents float value 12.340000 from being casted to type 'u29'
|
||||
// :2:20: error: expected type 'u32', found 'bool'
|
||||
// :6:19: error: fractional component prevents float value '12.34' from coercion to type 'u32'
|
||||
@ -2,8 +2,8 @@ const c = @cImport(@cInclude("bogus.h"));
|
||||
export fn entry() usize { return @sizeOf(@TypeOf(c.bogo)); }
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// backend=llvm
|
||||
// target=native
|
||||
//
|
||||
// tmp.zig:1:11: error: C import failed
|
||||
// .h:1:10: note: 'bogus.h' file not found
|
||||
// :1:11: error: C import failed
|
||||
// :1:10: error: 'bogus.h' file not found
|
||||
@ -0,0 +1,37 @@
|
||||
export fn inconsistentChildType() void {
|
||||
var x: ?i32 = undefined;
|
||||
const y: comptime_int = 10;
|
||||
_ = (x == y);
|
||||
}
|
||||
export fn optionalToOptional() void {
|
||||
var x: ?i32 = undefined;
|
||||
var y: ?i32 = undefined;
|
||||
_ = (x == y);
|
||||
}
|
||||
export fn optionalVector() void {
|
||||
var x: ?@Vector(10, i32) = undefined;
|
||||
var y: @Vector(10, i32) = undefined;
|
||||
_ = (x == y);
|
||||
}
|
||||
export fn optionalVector2() void {
|
||||
var x: ?@Vector(10, i32) = undefined;
|
||||
var y: @Vector(11, i32) = undefined;
|
||||
_ = (x == y);
|
||||
}
|
||||
export fn invalidChildType() void {
|
||||
var x: ?[3]i32 = undefined;
|
||||
var y: [3]i32 = undefined;
|
||||
_ = (x == y);
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=llvm
|
||||
// target=native
|
||||
//
|
||||
// :4:12: error: incompatible types: '?i32' and 'comptime_int'
|
||||
// :4:10: note: type '?i32' here
|
||||
// :4:15: note: type 'comptime_int' here
|
||||
// :19:12: error: incompatible types: '?@Vector(10, i32)' and '@Vector(11, i32)'
|
||||
// :19:10: note: type '?@Vector(10, i32)' here
|
||||
// :19:15: note: type '@Vector(11, i32)' here
|
||||
// :24:12: error: operator == not allowed for type '?[3]i32'
|
||||
@ -5,7 +5,7 @@ export fn entry() void {
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// tmp.zig:3:20: error: cast of value 16777217.000000 to type 'f32' loses information
|
||||
// :3:20: error: type 'f32' cannot represent float value '16777217'
|
||||
@ -11,7 +11,7 @@ export fn entry() void {
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// tmp.zig:2:19: error: expected type 'i32', found 'type'
|
||||
// :2:19: error: expected type 'i32', found 'type'
|
||||
@ -6,7 +6,8 @@ export fn c(x: i32) i32 {return x + 2;}
|
||||
export fn entry() usize { return @sizeOf(@TypeOf(fns)); }
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// tmp.zig:1:37: error: expected type 'fn(i32) i32', found 'fn(i32) callconv(.C) i32'
|
||||
// :1:37: error: expected type 'fn(i32) i32', found 'fn(i32) callconv(.C) i32'
|
||||
// :1:37: note: calling convention 'C' cannot cast into calling convention 'Unspecified'
|
||||
17
test/cases/compile_errors/floatToInt_comptime_safety.zig
Normal file
17
test/cases/compile_errors/floatToInt_comptime_safety.zig
Normal file
@ -0,0 +1,17 @@
|
||||
comptime {
|
||||
_ = @floatToInt(i8, @as(f32, -129.1));
|
||||
}
|
||||
comptime {
|
||||
_ = @floatToInt(u8, @as(f32, -1.1));
|
||||
}
|
||||
comptime {
|
||||
_ = @floatToInt(u8, @as(f32, 256.1));
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// :2:25: error: float value '-129.10000610351562' cannot be stored in integer type 'i8'
|
||||
// :5:25: error: float value '-1.100000023841858' cannot be stored in integer type 'u8'
|
||||
// :8:25: error: float value '256.1000061035156' cannot be stored in integer type 'u8'
|
||||
@ -5,7 +5,7 @@ comptime {
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// tmp.zig:3:24: error: null pointer casted to type '*u8'
|
||||
// :3:24: error: null pointer casted to type '*u8'
|
||||
10
test/cases/compile_errors/implicit_dependency_on_libc.zig
Normal file
10
test/cases/compile_errors/implicit_dependency_on_libc.zig
Normal file
@ -0,0 +1,10 @@
|
||||
extern "c" fn exit(u8) void;
|
||||
export fn entry() void {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage2
|
||||
// target=native-linux
|
||||
//
|
||||
// :1:8: error: dependency on libc must be explicitly specified in the build command
|
||||
@ -4,7 +4,7 @@ comptime {
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// tmp.zig:3:10: error: index 0 outside slice of size 0
|
||||
// :3:10: error: use of undefined value here causes undefined behavior
|
||||
@ -20,12 +20,12 @@ export fn entry4() void {
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// tmp.zig:3:18: error: cast from 'u16' to 'u8' truncates bits
|
||||
// tmp.zig:8:22: error: integer value 300 cannot be coerced to type 'u8'
|
||||
// tmp.zig:13:20: error: expected type 'u8', found 'u16'
|
||||
// tmp.zig:13:20: note: unsigned 8-bit int cannot represent all possible unsigned 16-bit values
|
||||
// tmp.zig:18:25: error: expected type 'u64', found 'i8'
|
||||
// tmp.zig:18:25: note: unsigned 64-bit int cannot represent all possible signed 8-bit values
|
||||
// :3:31: error: type 'u8' cannot represent integer value '300'
|
||||
// :8:22: error: type 'u8' cannot represent integer value '300'
|
||||
// :13:20: error: expected type 'u8', found 'u16'
|
||||
// :13:20: note: unsigned 8-bit int cannot represent all possible unsigned 16-bit values
|
||||
// :18:25: error: expected type 'u64', found 'i8'
|
||||
// :18:25: note: unsigned 64-bit int cannot represent all possible signed 8-bit values
|
||||
@ -4,8 +4,9 @@ export fn foo() [*:0]const u8 {
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// :3:18: error: expected type '[*:0]const u8', found '*[64]u8'
|
||||
// :3:18: note: destination pointer requires a terminating '0' sentinel
|
||||
// :3:18: note: destination pointer requires '0' sentinel
|
||||
// :1:18: note: function return type declared here
|
||||
@ -1,14 +1,14 @@
|
||||
export fn foo_slice_len_increment_beyond_bounds() void {
|
||||
comptime {
|
||||
var buf_storage: [8]u8 = undefined;
|
||||
var buf: []const u8 = buf_storage[0..];
|
||||
var buf: []u8 = buf_storage[0..];
|
||||
buf.len += 1;
|
||||
buf[8] = 42;
|
||||
}
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// :6:12: error: out of bounds slice
|
||||
// :6:16: error: comptime store of index 8 out of bounds of array length 8
|
||||
@ -6,7 +6,7 @@ export fn foo() void {
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// :3:28: error: use of undefined value here causes undefined behavior
|
||||
@ -0,0 +1,9 @@
|
||||
|
||||
|
||||
// error
|
||||
// backend=llvm
|
||||
// target=x86_64-linux
|
||||
// output_mode=Exe
|
||||
//
|
||||
// :?:?: error: root struct of file 'tmp' has no member named 'main'
|
||||
// :?:?: note: called from here
|
||||
@ -6,7 +6,7 @@ export fn entry() void {
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// tmp.zig:5:17: error: integer value 0 cannot be coerced to type 'void'
|
||||
// :5:11: error: incompatible types: 'void' and 'comptime_int'
|
||||
@ -2,7 +2,7 @@ fn f(noalias x: i32) void { _ = x; }
|
||||
export fn entry() void { f(1234); }
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// tmp.zig:1:6: error: noalias on non-pointer parameter
|
||||
// :1:6: error: non-pointer parameter declared noalias
|
||||
@ -0,0 +1,14 @@
|
||||
export fn entry() void {
|
||||
testImplicitlyDecreaseFnAlign(alignedSmall, 1234);
|
||||
}
|
||||
fn testImplicitlyDecreaseFnAlign(ptr: *const fn () align(8) i32, answer: i32) void {
|
||||
if (ptr() != answer) unreachable;
|
||||
}
|
||||
fn alignedSmall() align(4) i32 { return 1234; }
|
||||
|
||||
// error
|
||||
// backend=stage2
|
||||
// target=x86_64-linux
|
||||
//
|
||||
// :2:35: error: expected type '*const fn() align(8) i32', found '*const fn() align(4) i32'
|
||||
// :2:35: note: pointer alignment '4' cannot cast into pointer alignment '8'
|
||||
10
test/cases/compile_errors/private_main_fn.zig
Normal file
10
test/cases/compile_errors/private_main_fn.zig
Normal file
@ -0,0 +1,10 @@
|
||||
fn main() void {}
|
||||
|
||||
// error
|
||||
// backend=llvm
|
||||
// target=x86_64-linux
|
||||
// output_mode=Exe
|
||||
//
|
||||
// :?:?: error: 'main' is not marked 'pub'
|
||||
// :1:1: note: declared here
|
||||
// :?:?: note: called from here
|
||||
@ -13,7 +13,8 @@ export fn entry() usize {
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// tmp.zig:1:25: error: opaque types have unknown size and therefore cannot be directly embedded in unions
|
||||
// :1:18: error: opaque types have unknown size and therefore cannot be directly embedded in unions
|
||||
// :6:45: note: opaque declared here
|
||||
@ -9,7 +9,8 @@ export fn f() void {
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// tmp.zig:7:23: error: unable to evaluate constant expression
|
||||
// :7:30: error: unable to resolve comptime value
|
||||
// :7:30: note: initializer of comptime only struct must be comptime-known
|
||||
@ -9,7 +9,8 @@ export fn f() void {
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// tmp.zig:7:23: error: unable to evaluate constant expression
|
||||
// :7:30: error: unable to resolve comptime value
|
||||
// :7:30: note: initializer of comptime only union must be comptime-known
|
||||
@ -6,7 +6,7 @@ export fn a() void {
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// error: shift by negative value -2
|
||||
// :4:14: error: shift by negative amount '-2'
|
||||
@ -3,7 +3,7 @@ export fn a() void {
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// error: shift by negative value -2
|
||||
// :2:25: error: shift by negative amount '-2'
|
||||
@ -0,0 +1,10 @@
|
||||
export fn entry() void {
|
||||
const x = 1 << &@as(u8, 10);
|
||||
_ = x;
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// :2:20: error: expected type 'comptime_int', found '*const u8'
|
||||
@ -4,7 +4,7 @@ comptime {
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// tmp.zig:2:18: error: shift by negative value -1
|
||||
// :2:18: error: shift by negative amount '-1'
|
||||
11
test/cases/compile_errors/slice_sentinel_mismatch-1.zig
Normal file
11
test/cases/compile_errors/slice_sentinel_mismatch-1.zig
Normal file
@ -0,0 +1,11 @@
|
||||
export fn entry() void {
|
||||
const y: [:1]const u8 = &[_:2]u8{ 1, 2 };
|
||||
_ = y;
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// :2:29: error: expected type '[:1]const u8', found '*const [2:2]u8'
|
||||
// :2:29: note: pointer sentinel '2' cannot cast into pointer sentinel '1'
|
||||
@ -1,8 +0,0 @@
|
||||
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// target=native
|
||||
// output_mode=Exe
|
||||
//
|
||||
// error: root source file has no member called 'main'
|
||||
@ -1,9 +0,0 @@
|
||||
fn main() void {}
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// target=native
|
||||
// output_mode=Exe
|
||||
//
|
||||
// error: 'main' is private
|
||||
// tmp.zig:1:1: note: declared here
|
||||
@ -1,16 +0,0 @@
|
||||
const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
pub const io_mode = .evented;
|
||||
pub fn main() !void {
|
||||
if (builtin.os.tag == .windows) {
|
||||
_ = try (std.net.StreamServer.init(.{})).accept();
|
||||
} else {
|
||||
@compileError("Unsupported OS");
|
||||
}
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// target=native
|
||||
//
|
||||
// error: Unsupported OS
|
||||
@ -1,11 +0,0 @@
|
||||
export fn a() void {
|
||||
var x: [10]u8 = undefined;
|
||||
var y: []align(16) u8 = &x;
|
||||
_ = y;
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// target=native
|
||||
//
|
||||
// tmp.zig:3:30: error: expected type '[]align(16) u8', found '*[10]u8'
|
||||
@ -1,14 +0,0 @@
|
||||
var foos = [_]fn(anytype) void { foo1, foo2 };
|
||||
|
||||
fn foo1(arg: anytype) void {_ = arg;}
|
||||
fn foo2(arg: anytype) void {_ = arg;}
|
||||
|
||||
pub fn main() !void {
|
||||
foos[0](true);
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// target=native
|
||||
//
|
||||
// tmp.zig:7:9: error: calling a generic function requires compile-time known function value
|
||||
@ -1,35 +0,0 @@
|
||||
export fn inconsistentChildType() void {
|
||||
var x: ?i32 = undefined;
|
||||
const y: comptime_int = 10;
|
||||
_ = (x == y);
|
||||
}
|
||||
|
||||
export fn optionalToOptional() void {
|
||||
var x: ?i32 = undefined;
|
||||
var y: ?i32 = undefined;
|
||||
_ = (x == y);
|
||||
}
|
||||
|
||||
export fn optionalVector() void {
|
||||
var x: ?@Vector(10, i32) = undefined;
|
||||
var y: @Vector(10, i32) = undefined;
|
||||
_ = (x == y);
|
||||
}
|
||||
|
||||
export fn invalidChildType() void {
|
||||
var x: ?[3]i32 = undefined;
|
||||
var y: [3]i32 = undefined;
|
||||
_ = (x == y);
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// target=native
|
||||
//
|
||||
// :4:12: error: cannot compare types '?i32' and 'comptime_int'
|
||||
// :4:12: note: optional child type 'i32' must be the same as non-optional type 'comptime_int'
|
||||
// :10:12: error: cannot compare types '?i32' and '?i32'
|
||||
// :10:12: note: optional to optional comparison is only supported for optional pointer types
|
||||
// :16:12: error: TODO add comparison of optional vector
|
||||
// :22:12: error: cannot compare types '?[3]i32' and '[3]i32'
|
||||
// :22:12: note: operator not supported for type '[3]i32'
|
||||
@ -1,9 +0,0 @@
|
||||
export fn foo() void {
|
||||
asm volatile ("" : : [bar]"r"(3.17) : "");
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// target=native
|
||||
//
|
||||
// tmp.zig:2:35: error: expected sized integer or sized float, found comptime_float
|
||||
@ -1,9 +0,0 @@
|
||||
export fn foo() void {
|
||||
asm volatile ("" : : [bar]"r"(3) : "");
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// target=native
|
||||
//
|
||||
// tmp.zig:2:35: error: expected sized integer or sized float, found comptime_int
|
||||
@ -1,8 +0,0 @@
|
||||
pub fn main() ??void {
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// target=native
|
||||
//
|
||||
// error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'
|
||||
@ -1,17 +0,0 @@
|
||||
comptime {
|
||||
_ = @floatToInt(i8, @as(f32, -129.1));
|
||||
}
|
||||
comptime {
|
||||
_ = @floatToInt(u8, @as(f32, -1.1));
|
||||
}
|
||||
comptime {
|
||||
_ = @floatToInt(u8, @as(f32, 256.1));
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// target=native
|
||||
//
|
||||
// tmp.zig:2:9: error: integer value '-129' cannot be stored in type 'i8'
|
||||
// tmp.zig:5:9: error: integer value '-1' cannot be stored in type 'u8'
|
||||
// tmp.zig:8:9: error: integer value '256' cannot be stored in type 'u8'
|
||||
@ -1,10 +0,0 @@
|
||||
comptime {
|
||||
const a = 0x1.0p18495;
|
||||
_ = a;
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// target=native
|
||||
//
|
||||
// tmp.zig:2:15: error: float literal out of range of any type
|
||||
@ -1,10 +0,0 @@
|
||||
comptime {
|
||||
const a = 0x1.0p-19000;
|
||||
_ = a;
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// target=native
|
||||
//
|
||||
// tmp.zig:2:15: error: float literal out of range of any type
|
||||
@ -1,16 +0,0 @@
|
||||
export fn a() void {
|
||||
var ptr: [*c]u8 = (1 << 64) + 1;
|
||||
_ = ptr;
|
||||
}
|
||||
export fn b() void {
|
||||
var x: u65 = 0x1234;
|
||||
var ptr: [*c]u8 = x;
|
||||
_ = ptr;
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// target=native
|
||||
//
|
||||
// tmp.zig:2:33: error: integer value 18446744073709551617 cannot be coerced to type 'usize'
|
||||
// tmp.zig:7:23: error: integer type 'u65' too big for implicit @intToPtr to type '[*c]u8'
|
||||
@ -1,11 +0,0 @@
|
||||
extern "c" fn exit(u8) void;
|
||||
export fn entry() void {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// target=native-linux
|
||||
// is_test=1
|
||||
//
|
||||
// tmp.zig:3:5: error: dependency on libc must be explicitly specified in the build command
|
||||
@ -1,12 +0,0 @@
|
||||
const c = @cImport(@cInclude("stdio.h"));
|
||||
export fn entry() void {
|
||||
_ = c.printf("hello, world!\n");
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// is_test=1
|
||||
// target=native-linux
|
||||
//
|
||||
// tmp.zig:1:11: error: C import failed
|
||||
// tmp.zig:1:11: note: libc headers not available; compilation does not link against libc
|
||||
@ -1,31 +0,0 @@
|
||||
const Foo = struct {
|
||||
a: i32,
|
||||
b: i32,
|
||||
|
||||
fn member_a(foo: *const Foo) i32 {
|
||||
return foo.a;
|
||||
}
|
||||
fn member_b(foo: *const Foo) i32 {
|
||||
return foo.b;
|
||||
}
|
||||
};
|
||||
|
||||
const member_fn_type = @TypeOf(Foo.member_a);
|
||||
const members = [_]member_fn_type {
|
||||
Foo.member_a,
|
||||
Foo.member_b,
|
||||
};
|
||||
|
||||
fn f(foo: *const Foo, index: usize) void {
|
||||
const result = members[index]();
|
||||
_ = foo;
|
||||
_ = result;
|
||||
}
|
||||
|
||||
export fn entry() usize { return @sizeOf(@TypeOf(f)); }
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// target=native
|
||||
//
|
||||
// tmp.zig:20:34: error: expected 1 argument(s), found 0
|
||||
@ -1,13 +0,0 @@
|
||||
export fn entry() void {
|
||||
testImplicitlyDecreaseFnAlign(alignedSmall, 1234);
|
||||
}
|
||||
fn testImplicitlyDecreaseFnAlign(ptr: fn () align(8) i32, answer: i32) void {
|
||||
if (ptr() != answer) unreachable;
|
||||
}
|
||||
fn alignedSmall() align(4) i32 { return 1234; }
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// target=native
|
||||
//
|
||||
// tmp.zig:2:35: error: expected type 'fn() align(8) i32', found 'fn() align(4) i32'
|
||||
@ -1,11 +0,0 @@
|
||||
export fn foo() void {
|
||||
@setFloatMode(@import("std").builtin.FloatMode.Optimized);
|
||||
@setFloatMode(@import("std").builtin.FloatMode.Optimized);
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// target=native
|
||||
//
|
||||
// tmp.zig:3:5: error: float mode set twice for same scope
|
||||
// tmp.zig:2:5: note: first set here
|
||||
@ -1,11 +0,0 @@
|
||||
export fn foo() void {
|
||||
@setRuntimeSafety(false);
|
||||
@setRuntimeSafety(false);
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// target=native
|
||||
//
|
||||
// tmp.zig:3:5: error: runtime safety set twice for same scope
|
||||
// tmp.zig:2:5: note: first set here
|
||||
@ -1,10 +0,0 @@
|
||||
export fn entry() void {
|
||||
const x = 1 << &@as(u8, 10);
|
||||
_ = x;
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// target=native
|
||||
//
|
||||
// tmp.zig:2:21: error: shift amount has to be an integer type, but found '*const u8'
|
||||
@ -1,10 +0,0 @@
|
||||
export fn entry() void {
|
||||
const y: [:1]const u8 = &[_:2]u8{ 1, 2 };
|
||||
_ = y;
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// target=native
|
||||
//
|
||||
// tmp.zig:2:37: error: expected type '[:1]const u8', found '*const [2:2]u8'
|
||||
@ -1,49 +0,0 @@
|
||||
const Mode = @import("std").builtin.Mode;
|
||||
|
||||
fn Free(comptime filename: []const u8) TestCase {
|
||||
return TestCase {
|
||||
.filename = filename,
|
||||
.problem_type = ProblemType.Free,
|
||||
};
|
||||
}
|
||||
|
||||
fn LibC(comptime filename: []const u8) TestCase {
|
||||
return TestCase {
|
||||
.filename = filename,
|
||||
.problem_type = ProblemType.LinkLibC,
|
||||
};
|
||||
}
|
||||
|
||||
const TestCase = struct {
|
||||
filename: []const u8,
|
||||
problem_type: ProblemType,
|
||||
};
|
||||
|
||||
const ProblemType = enum {
|
||||
Free,
|
||||
LinkLibC,
|
||||
};
|
||||
|
||||
export fn entry() void {
|
||||
const tests = [_]TestCase {
|
||||
Free("001"),
|
||||
Free("002"),
|
||||
LibC("078"),
|
||||
Free("116"),
|
||||
Free("117"),
|
||||
};
|
||||
|
||||
for ([_]Mode { Mode.Debug, Mode.ReleaseSafe, Mode.ReleaseFast }) |mode| {
|
||||
_ = mode;
|
||||
inline for (tests) |test_case| {
|
||||
const foo = test_case.filename ++ ".zig";
|
||||
_ = foo;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// target=native
|
||||
//
|
||||
// tmp.zig:38:29: error: cannot store runtime value in compile time variable
|
||||
@ -1,13 +0,0 @@
|
||||
const Empty = struct {
|
||||
val: void,
|
||||
};
|
||||
export fn foo() void {
|
||||
const fieldOffset = @bitOffsetOf(Empty, "val",);
|
||||
_ = fieldOffset;
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// target=native
|
||||
//
|
||||
// tmp.zig:5:45: error: zero-bit field 'val' in struct 'Empty' has no offset
|
||||
@ -1,13 +0,0 @@
|
||||
const Empty = struct {
|
||||
val: void,
|
||||
};
|
||||
export fn foo() void {
|
||||
const fieldOffset = @offsetOf(Empty, "val",);
|
||||
_ = fieldOffset;
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// target=native
|
||||
//
|
||||
// tmp.zig:5:42: error: zero-bit field 'val' in struct 'Empty' has no offset
|
||||
@ -1,16 +0,0 @@
|
||||
const U = union(enum(i2)) {
|
||||
A: u8,
|
||||
B: u8,
|
||||
C: u8,
|
||||
D: u8,
|
||||
};
|
||||
export fn entry() void {
|
||||
_ = U{ .D = 1 };
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// target=native
|
||||
//
|
||||
// tmp.zig:1:22: error: specified integer tag type cannot represent every field
|
||||
// tmp.zig:1:22: note: type i2 cannot fit values in range 0...3
|
||||
@ -1,12 +0,0 @@
|
||||
pub fn panic(comptime msg: []const u8, error_return_trace: ?*builtin.StackTrace, _: ?usize) noreturn {
|
||||
_ = msg; _ = error_return_trace;
|
||||
while (true) {}
|
||||
}
|
||||
const builtin = @import("std").builtin;
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// target=native
|
||||
//
|
||||
// error: expected type 'fn([]const u8, ?*std.builtin.StackTrace, ?usize) noreturn', found 'fn([]const u8,anytype,anytype) anytype'
|
||||
// note: only one of the functions is generic
|
||||
@ -1,10 +0,0 @@
|
||||
test {}
|
||||
|
||||
pub fn panic() void {}
|
||||
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// target=native
|
||||
//
|
||||
// error: expected type 'fn([]const u8, ?*std.builtin.StackTrace, ?usize) noreturn', found 'fn() void'
|
||||
@ -1,7 +0,0 @@
|
||||
pub fn main() f32 { }
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// target=native
|
||||
//
|
||||
// error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'
|
||||
@ -11,8 +11,8 @@ export fn entry() void {
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// tmp.zig:6:9: error: enum tag value 60 already taken
|
||||
// tmp.zig:4:9: note: other occurrence here
|
||||
// :6:5: error: enum tag value 60 already taken
|
||||
// :4:5: note: other occurrence here
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user