authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-11-30 14:27:18-05:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2023-12-01 04:34:50+00:00
logbf5ab54510fd8fbd300ddc22f9af4767477be0e5
tree94fb2ce98befdd0a8b80abaf54280e83a748b652
parent39a966b0a496b683d0ac0d1b04dc851caa655a23

test: test with `-fstrip` and fix failures

Closes #17513

7 files changed, 32 insertions(+), 24 deletions(-)

lib/std/debug.zig+2
......@@ -2657,6 +2657,8 @@ pub fn dumpStackPointerAddr(prefix: []const u8) void {
26572657}
26582658
26592659test "manage resources correctly" {
2660 if (builtin.strip_debug_info) return error.SkipZigTest;
2661
26602662 if (builtin.os.tag == .wasi) return error.SkipZigTest;
26612663
26622664 if (builtin.os.tag == .windows) {
src/Sema.zig+1
......@@ -27865,6 +27865,7 @@ fn coerceExtra(
2786527865 return sema.coerceInMemory(val, dest_ty);
2786627866 }
2786727867 try sema.requireRuntimeBlock(block, inst_src, null);
27868 try sema.queueFullTypeResolution(dest_ty);
2786827869 const new_val = try block.addBitCast(dest_ty, inst);
2786927870 try sema.checkKnownAllocPtr(inst, new_val);
2787027871 return new_val;
src/arch/x86_64/CodeGen.zig+8-9
......@@ -7083,15 +7083,14 @@ fn fieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, index: u32
70837083 const ptr_container_ty_info = ptr_container_ty.ptrInfo(mod);
70847084 const container_ty = ptr_container_ty.childType(mod);
70857085
7086 const field_offset: i32 = blk: {
7087 if (mod.typeToPackedStruct(container_ty)) |struct_type| {
7088 break :blk if (ptr_field_ty.ptrInfo(mod).packed_offset.host_size == 0)
7089 @divExact(mod.structPackedFieldBitOffset(struct_type, index) + ptr_container_ty_info.packed_offset.bit_offset, 8)
7090 else
7091 0;
7092 }
7093 break :blk @intCast(container_ty.structFieldOffset(index, mod));
7094 };
7086 const field_offset: i32 = if (mod.typeToPackedStruct(container_ty)) |struct_obj|
7087 if (ptr_field_ty.ptrInfo(mod).packed_offset.host_size == 0)
7088 @divExact(mod.structPackedFieldBitOffset(struct_obj, index) +
7089 ptr_container_ty_info.packed_offset.bit_offset, 8)
7090 else
7091 0
7092 else
7093 @intCast(container_ty.structFieldOffset(index, mod));
70957094
70967095 const src_mcv = try self.resolveInst(operand);
70977096 const dst_mcv = if (switch (src_mcv) {
src/codegen.zig+14-12
......@@ -657,14 +657,15 @@ fn lowerParentPtr(
657657 Type.fromInterned(mod.intern_pool.typeOf(elem.base)).elemType2(mod).abiSize(mod)))),
658658 ),
659659 .field => |field| {
660 const base_type = mod.intern_pool.indexToKey(mod.intern_pool.typeOf(field.base)).ptr_type.child;
660 const base_ptr_ty = mod.intern_pool.typeOf(field.base);
661 const base_ty = mod.intern_pool.indexToKey(base_ptr_ty).ptr_type.child;
661662 return lowerParentPtr(
662663 bin_file,
663664 src_loc,
664665 field.base,
665666 code,
666667 debug_output,
667 reloc_info.offset(switch (mod.intern_pool.indexToKey(base_type)) {
668 reloc_info.offset(switch (mod.intern_pool.indexToKey(base_ty)) {
668669 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {
669670 .One, .Many, .C => unreachable,
670671 .Slice => switch (field.index) {
......@@ -676,19 +677,20 @@ fn lowerParentPtr(
676677 .struct_type,
677678 .anon_struct_type,
678679 .union_type,
679 => switch (Type.fromInterned(base_type).containerLayout(mod)) {
680 .Auto, .Extern => @intCast(Type.fromInterned(base_type).structFieldOffset(
680 => switch (Type.fromInterned(base_ty).containerLayout(mod)) {
681 .Auto, .Extern => @intCast(Type.fromInterned(base_ty).structFieldOffset(
681682 @intCast(field.index),
682683 mod,
683684 )),
684 .Packed => if (mod.typeToStruct(Type.fromInterned(base_type))) |struct_type|
685 math.divExact(u16, mod.structPackedFieldBitOffset(
686 struct_type,
687 @intCast(field.index),
688 ), 8) catch |err| switch (err) {
689 error.UnexpectedRemainder => 0,
690 error.DivisionByZero => unreachable,
691 }
685 .Packed => if (mod.typeToStruct(Type.fromInterned(base_ty))) |struct_obj|
686 if (Type.fromInterned(ptr.ty).ptrInfo(mod).packed_offset.host_size == 0)
687 @divExact(Type.fromInterned(base_ptr_ty).ptrInfo(mod)
688 .packed_offset.bit_offset + mod.structPackedFieldBitOffset(
689 struct_obj,
690 @intCast(field.index),
691 ), 8)
692 else
693 0
692694 else
693695 0,
694696 },
test/behavior/bitcast.zig+1-1
......@@ -331,11 +331,11 @@ test "@bitCast packed struct of floats" {
331331test "comptime @bitCast packed struct to int and back" {
332332 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
333333 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
334 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
335334 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
336335 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
337336 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
338337 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
338 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest;
339339
340340 if (builtin.zig_backend == .stage2_llvm and native_endian == .big) {
341341 // https://github.com/ziglang/zig/issues/13782
test/behavior/packed-struct.zig-2
......@@ -432,7 +432,6 @@ test "nested packed struct field pointers" {
432432 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
433433 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
434434 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // ubsan unaligned pointer access
435 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
436435 if (native_endian != .little) return error.SkipZigTest; // Byte aligned packed struct field pointers have not been implemented yet
437436
438437 const S2 = packed struct {
......@@ -513,7 +512,6 @@ test "@intFromPtr on a packed struct field unaligned and nested" {
513512 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
514513 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
515514 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
516 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
517515 if (native_endian != .little) return error.SkipZigTest; // Byte aligned packed struct field pointers have not been implemented yet
518516
519517 const S1 = packed struct {
test/tests.zig+6
......@@ -29,6 +29,7 @@ const TestTarget = struct {
2929 use_llvm: ?bool = null,
3030 use_lld: ?bool = null,
3131 force_pic: ?bool = null,
32 strip: ?bool = null,
3233};
3334
3435const test_targets = blk: {
......@@ -115,6 +116,7 @@ const test_targets = blk: {
115116 },
116117 .use_llvm = false,
117118 .use_lld = false,
119 .strip = true,
118120 },
119121 // Doesn't support new liveness
120122 //.{
......@@ -497,6 +499,7 @@ const CAbiTarget = struct {
497499 use_llvm: ?bool = null,
498500 use_lld: ?bool = null,
499501 force_pic: ?bool = null,
502 strip: ?bool = null,
500503 c_defines: []const []const u8 = &.{},
501504};
502505
......@@ -528,6 +531,7 @@ const c_abi_targets = [_]CAbiTarget{
528531 },
529532 .use_llvm = false,
530533 .use_lld = false,
534 .strip = true,
531535 .c_defines = &.{"ZIG_BACKEND_STAGE2_X86_64"},
532536 },
533537 .{
......@@ -1111,6 +1115,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
11111115 .zig_lib_dir = .{ .path = "lib" },
11121116 });
11131117 these_tests.force_pic = test_target.force_pic;
1118 these_tests.strip = test_target.strip;
11141119 const single_threaded_suffix = if (test_target.single_threaded == true) "-single" else "";
11151120 const backend_suffix = if (test_target.use_llvm == true)
11161121 "-llvm"
......@@ -1253,6 +1258,7 @@ pub fn addCAbiTests(b: *std.Build, skip_non_native: bool, skip_release: bool) *S
12531258 .use_lld = c_abi_target.use_lld,
12541259 });
12551260 test_step.force_pic = c_abi_target.force_pic;
1261 test_step.strip = c_abi_target.strip;
12561262 if (c_abi_target.target.abi != null and c_abi_target.target.abi.?.isMusl()) {
12571263 // TODO NativeTargetInfo insists on dynamically linking musl
12581264 // for some reason?