aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-06-28 01:34:46 -0400
committerGitHub <noreply@github.com>2022-06-28 01:34:46 -0400
commit975a66080790956bb5591dc8aaef6e7725e72e56 (patch)
tree53d36639292305eef06d624aa496f47d9687598a /src
parent1188415f4cb73440fde05047cd8e6b79a2255efa (diff)
parenta71d00a4d504edfdb09cd169d29ca1bbc0b909c4 (diff)
downloadzig-975a66080790956bb5591dc8aaef6e7725e72e56.tar.gz
zig-975a66080790956bb5591dc8aaef6e7725e72e56.zip
Merge pull request #11945 from ziglang/stage2-std
stage2 fixes towards standard library tests passing
Diffstat (limited to 'src')
-rw-r--r--src/Module.zig21
-rw-r--r--src/codegen/llvm.zig33
-rw-r--r--src/stage1/codegen.cpp4
-rw-r--r--src/target.zig8
4 files changed, 51 insertions, 15 deletions
diff --git a/src/Module.zig b/src/Module.zig
index bcf6491ce6..bdf206490d 100644
--- a/src/Module.zig
+++ b/src/Module.zig
@@ -4607,6 +4607,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) SemaError!voi
DeclAdapter{ .mod = mod },
Namespace.DeclContext{ .module = mod },
);
+ const comp = mod.comp;
if (!gop.found_existing) {
const new_decl_index = try mod.allocateNewDecl(namespace, decl_node, iter.parent_decl.src_scope);
const new_decl = mod.declPtr(new_decl_index);
@@ -4625,7 +4626,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) SemaError!voi
1 => blk: {
// test decl with no name. Skip the part where we check against
// the test name filter.
- if (!mod.comp.bin_file.options.is_test) break :blk false;
+ if (!comp.bin_file.options.is_test) break :blk false;
if (decl_pkg != mod.main_pkg) {
if (!mod.main_pkg_in_std) break :blk false;
const std_pkg = mod.main_pkg.table.get("std").?;
@@ -4636,19 +4637,23 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) SemaError!voi
},
else => blk: {
if (!is_named_test) break :blk false;
- if (!mod.comp.bin_file.options.is_test) break :blk false;
+ if (!comp.bin_file.options.is_test) break :blk false;
if (decl_pkg != mod.main_pkg) {
if (!mod.main_pkg_in_std) break :blk false;
const std_pkg = mod.main_pkg.table.get("std").?;
if (std_pkg != decl_pkg) break :blk false;
}
- // TODO check the name against --test-filter
+ if (comp.test_filter) |test_filter| {
+ if (mem.indexOf(u8, decl_name, test_filter) == null) {
+ break :blk false;
+ }
+ }
try mod.test_functions.put(gpa, new_decl_index, {});
break :blk true;
},
};
if (want_analysis) {
- mod.comp.work_queue.writeItemAssumeCapacity(.{ .analyze_decl = new_decl_index });
+ comp.work_queue.writeItemAssumeCapacity(.{ .analyze_decl = new_decl_index });
}
new_decl.is_pub = is_pub;
new_decl.is_exported = is_exported;
@@ -4675,24 +4680,24 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) SemaError!voi
decl.has_linksection_or_addrspace = has_linksection_or_addrspace;
decl.zir_decl_index = @intCast(u32, decl_sub_index);
if (decl.getFunction()) |_| {
- switch (mod.comp.bin_file.tag) {
+ switch (comp.bin_file.tag) {
.coff => {
// TODO Implement for COFF
},
.elf => if (decl.fn_link.elf.len != 0) {
// TODO Look into detecting when this would be unnecessary by storing enough state
// in `Decl` to notice that the line number did not change.
- mod.comp.work_queue.writeItemAssumeCapacity(.{ .update_line_number = decl_index });
+ comp.work_queue.writeItemAssumeCapacity(.{ .update_line_number = decl_index });
},
.macho => if (decl.fn_link.macho.len != 0) {
// TODO Look into detecting when this would be unnecessary by storing enough state
// in `Decl` to notice that the line number did not change.
- mod.comp.work_queue.writeItemAssumeCapacity(.{ .update_line_number = decl_index });
+ comp.work_queue.writeItemAssumeCapacity(.{ .update_line_number = decl_index });
},
.plan9 => {
// TODO Look into detecting when this would be unnecessary by storing enough state
// in `Decl` to notice that the line number did not change.
- mod.comp.work_queue.writeItemAssumeCapacity(.{ .update_line_number = decl_index });
+ comp.work_queue.writeItemAssumeCapacity(.{ .update_line_number = decl_index });
},
.c, .wasm, .spirv, .nvptx => {},
}
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig
index bf09ec0f35..2b320923ad 100644
--- a/src/codegen/llvm.zig
+++ b/src/codegen/llvm.zig
@@ -4197,7 +4197,7 @@ pub const FuncGen = struct {
}
var it = iterateParamTypes(self.dg, fn_info);
- while (it.next()) |lowering| switch (lowering) {
+ while (it.nextCall(self, args)) |lowering| switch (lowering) {
.no_bits => continue,
.byval => {
const arg = args[it.zig_index - 1];
@@ -7212,11 +7212,17 @@ pub const FuncGen = struct {
fn airRetAddr(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value {
if (self.liveness.isUnused(inst)) return null;
+ const llvm_usize = try self.dg.lowerType(Type.usize);
+ const target = self.dg.module.getTarget();
+ if (!target_util.supportsReturnAddress(target)) {
+ // https://github.com/ziglang/zig/issues/11946
+ return llvm_usize.constNull();
+ }
+
const llvm_i32 = self.context.intType(32);
const llvm_fn = self.getIntrinsic("llvm.returnaddress", &.{});
const params = [_]*const llvm.Value{llvm_i32.constNull()};
const ptr_val = self.builder.buildCall(llvm_fn, &params, params.len, .Fast, .Auto, "");
- const llvm_usize = try self.dg.lowerType(Type.usize);
return self.builder.buildPtrToInt(ptr_val, llvm_usize, "");
}
@@ -8021,7 +8027,6 @@ pub const FuncGen = struct {
assert(union_obj.haveFieldTypes());
const field = union_obj.fields.values()[extra.field_index];
const field_llvm_ty = try self.dg.lowerType(field.ty);
- const tag_llvm_ty = try self.dg.lowerType(union_obj.tag_ty);
const field_size = field.ty.abiSize(target);
const field_align = field.normalAlignment(target);
@@ -8044,6 +8049,7 @@ pub const FuncGen = struct {
const fields: [1]*const llvm.Type = .{payload};
break :t self.context.structType(&fields, fields.len, .False);
}
+ const tag_llvm_ty = try self.dg.lowerType(union_obj.tag_ty);
var fields: [3]*const llvm.Type = undefined;
var fields_len: c_uint = 2;
if (layout.tag_align >= layout.payload_align) {
@@ -8100,6 +8106,7 @@ pub const FuncGen = struct {
index_type.constInt(@boolToInt(layout.tag_align < layout.payload_align), .False),
};
const field_ptr = self.builder.buildInBoundsGEP(casted_ptr, &indices, indices.len, "");
+ const tag_llvm_ty = try self.dg.lowerType(union_obj.tag_ty);
const llvm_tag = tag_llvm_ty.constInt(extra.field_index, .False);
const store_inst = self.builder.buildStore(llvm_tag, field_ptr);
store_inst.setAlignment(union_obj.tag_ty.abiAlignment(target));
@@ -9004,10 +9011,26 @@ const ParamTypeIterator = struct {
slice,
};
- fn next(it: *ParamTypeIterator) ?Lowering {
+ pub fn next(it: *ParamTypeIterator) ?Lowering {
if (it.zig_index >= it.fn_info.param_types.len) return null;
-
const ty = it.fn_info.param_types[it.zig_index];
+ return nextInner(it, ty);
+ }
+
+ /// `airCall` uses this instead of `next` so that it can take into account variadic functions.
+ pub fn nextCall(it: *ParamTypeIterator, fg: *FuncGen, args: []const Air.Inst.Ref) ?Lowering {
+ if (it.zig_index >= it.fn_info.param_types.len) {
+ if (it.zig_index >= args.len) {
+ return null;
+ } else {
+ return nextInner(it, fg.air.typeOf(args[it.zig_index]));
+ }
+ } else {
+ return nextInner(it, it.fn_info.param_types[it.zig_index]);
+ }
+ }
+
+ fn nextInner(it: *ParamTypeIterator, ty: Type) ?Lowering {
if (!ty.hasRuntimeBitsIgnoreComptime()) {
it.zig_index += 1;
return .no_bits;
diff --git a/src/stage1/codegen.cpp b/src/stage1/codegen.cpp
index d6fb6d4753..318a90732c 100644
--- a/src/stage1/codegen.cpp
+++ b/src/stage1/codegen.cpp
@@ -6764,8 +6764,8 @@ static LLVMValueRef ir_render_return_address(CodeGen *g, Stage1Air *executable,
Stage1AirInstReturnAddress *instruction)
{
if ((target_is_wasm(g->zig_target) && g->zig_target->os != OsEmscripten) || target_is_bpf(g->zig_target)) {
- // I got this error from LLVM 10:
- // "Non-Emscripten WebAssembly hasn't implemented __builtin_return_address"
+ // LLVM 13 reports "Non-Emscripten WebAssembly hasn't implemented __builtin_return_address"
+ // https://github.com/ziglang/zig/issues/11946
return LLVMConstNull(get_llvm_type(g, instruction->base.value->type));
}
diff --git a/src/target.zig b/src/target.zig
index 14af2675d2..93c179b7f0 100644
--- a/src/target.zig
+++ b/src/target.zig
@@ -283,6 +283,14 @@ pub fn supportsStackProbing(target: std.Target) bool {
(target.cpu.arch == .i386 or target.cpu.arch == .x86_64);
}
+pub fn supportsReturnAddress(target: std.Target) bool {
+ return switch (target.cpu.arch) {
+ .wasm32, .wasm64 => target.os.tag == .emscripten,
+ .bpfel, .bpfeb => false,
+ else => true,
+ };
+}
+
pub fn osToLLVM(os_tag: std.Target.Os.Tag) llvm.OSType {
return switch (os_tag) {
.freestanding, .other, .opencl, .glsl450, .vulkan, .plan9 => .UnknownOS,