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 {...@@ -2657,6 +2657,8 @@ pub fn dumpStackPointerAddr(prefix: []const u8) void {
2657}2657}
26582658
2659test "manage resources correctly" {2659test "manage resources correctly" {
2660 if (builtin.strip_debug_info) return error.SkipZigTest;
2661
2660 if (builtin.os.tag == .wasi) return error.SkipZigTest;2662 if (builtin.os.tag == .wasi) return error.SkipZigTest;
26612663
2662 if (builtin.os.tag == .windows) {2664 if (builtin.os.tag == .windows) {
src/Sema.zig+1
...@@ -27865,6 +27865,7 @@ fn coerceExtra(...@@ -27865,6 +27865,7 @@ fn coerceExtra(
27865 return sema.coerceInMemory(val, dest_ty);27865 return sema.coerceInMemory(val, dest_ty);
27866 }27866 }
27867 try sema.requireRuntimeBlock(block, inst_src, null);27867 try sema.requireRuntimeBlock(block, inst_src, null);
27868 try sema.queueFullTypeResolution(dest_ty);
27868 const new_val = try block.addBitCast(dest_ty, inst);27869 const new_val = try block.addBitCast(dest_ty, inst);
27869 try sema.checkKnownAllocPtr(inst, new_val);27870 try sema.checkKnownAllocPtr(inst, new_val);
27870 return new_val;27871 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...@@ -7083,15 +7083,14 @@ fn fieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, index: u32
7083 const ptr_container_ty_info = ptr_container_ty.ptrInfo(mod);7083 const ptr_container_ty_info = ptr_container_ty.ptrInfo(mod);
7084 const container_ty = ptr_container_ty.childType(mod);7084 const container_ty = ptr_container_ty.childType(mod);
70857085
7086 const field_offset: i32 = blk: {7086 const field_offset: i32 = if (mod.typeToPackedStruct(container_ty)) |struct_obj|
7087 if (mod.typeToPackedStruct(container_ty)) |struct_type| {7087 if (ptr_field_ty.ptrInfo(mod).packed_offset.host_size == 0)
7088 break :blk if (ptr_field_ty.ptrInfo(mod).packed_offset.host_size == 0)7088 @divExact(mod.structPackedFieldBitOffset(struct_obj, index) +
7089 @divExact(mod.structPackedFieldBitOffset(struct_type, index) + ptr_container_ty_info.packed_offset.bit_offset, 8)7089 ptr_container_ty_info.packed_offset.bit_offset, 8)
7090 else7090 else
7091 0;7091 0
7092 }7092 else
7093 break :blk @intCast(container_ty.structFieldOffset(index, mod));7093 @intCast(container_ty.structFieldOffset(index, mod));
7094 };
70957094
7096 const src_mcv = try self.resolveInst(operand);7095 const src_mcv = try self.resolveInst(operand);
7097 const dst_mcv = if (switch (src_mcv) {7096 const dst_mcv = if (switch (src_mcv) {
src/codegen.zig+14-12
...@@ -657,14 +657,15 @@ fn lowerParentPtr(...@@ -657,14 +657,15 @@ fn lowerParentPtr(
657 Type.fromInterned(mod.intern_pool.typeOf(elem.base)).elemType2(mod).abiSize(mod)))),657 Type.fromInterned(mod.intern_pool.typeOf(elem.base)).elemType2(mod).abiSize(mod)))),
658 ),658 ),
659 .field => |field| {659 .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;
661 return lowerParentPtr(662 return lowerParentPtr(
662 bin_file,663 bin_file,
663 src_loc,664 src_loc,
664 field.base,665 field.base,
665 code,666 code,
666 debug_output,667 debug_output,
667 reloc_info.offset(switch (mod.intern_pool.indexToKey(base_type)) {668 reloc_info.offset(switch (mod.intern_pool.indexToKey(base_ty)) {
668 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {669 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {
669 .One, .Many, .C => unreachable,670 .One, .Many, .C => unreachable,
670 .Slice => switch (field.index) {671 .Slice => switch (field.index) {
...@@ -676,19 +677,20 @@ fn lowerParentPtr(...@@ -676,19 +677,20 @@ fn lowerParentPtr(
676 .struct_type,677 .struct_type,
677 .anon_struct_type,678 .anon_struct_type,
678 .union_type,679 .union_type,
679 => switch (Type.fromInterned(base_type).containerLayout(mod)) {680 => switch (Type.fromInterned(base_ty).containerLayout(mod)) {
680 .Auto, .Extern => @intCast(Type.fromInterned(base_type).structFieldOffset(681 .Auto, .Extern => @intCast(Type.fromInterned(base_ty).structFieldOffset(
681 @intCast(field.index),682 @intCast(field.index),
682 mod,683 mod,
683 )),684 )),
684 .Packed => if (mod.typeToStruct(Type.fromInterned(base_type))) |struct_type|685 .Packed => if (mod.typeToStruct(Type.fromInterned(base_ty))) |struct_obj|
685 math.divExact(u16, mod.structPackedFieldBitOffset(686 if (Type.fromInterned(ptr.ty).ptrInfo(mod).packed_offset.host_size == 0)
686 struct_type,687 @divExact(Type.fromInterned(base_ptr_ty).ptrInfo(mod)
687 @intCast(field.index),688 .packed_offset.bit_offset + mod.structPackedFieldBitOffset(
688 ), 8) catch |err| switch (err) {689 struct_obj,
689 error.UnexpectedRemainder => 0,690 @intCast(field.index),
690 error.DivisionByZero => unreachable,691 ), 8)
691 }692 else
693 0
692 else694 else
693 0,695 0,
694 },696 },
test/behavior/bitcast.zig+1-1
...@@ -331,11 +331,11 @@ test "@bitCast packed struct of floats" {...@@ -331,11 +331,11 @@ test "@bitCast packed struct of floats" {
331test "comptime @bitCast packed struct to int and back" {331test "comptime @bitCast packed struct to int and back" {
332 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;332 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
333 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;333 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
334 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
335 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;334 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
336 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;335 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
337 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO336 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
338 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;337 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
340 if (builtin.zig_backend == .stage2_llvm and native_endian == .big) {340 if (builtin.zig_backend == .stage2_llvm and native_endian == .big) {
341 // https://github.com/ziglang/zig/issues/13782341 // https://github.com/ziglang/zig/issues/13782
test/behavior/packed-struct.zig-2
...@@ -432,7 +432,6 @@ test "nested packed struct field pointers" {...@@ -432,7 +432,6 @@ test "nested packed struct field pointers" {
432 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO432 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
433 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;433 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
434 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // ubsan unaligned pointer access434 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // ubsan unaligned pointer access
435 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
436 if (native_endian != .little) return error.SkipZigTest; // Byte aligned packed struct field pointers have not been implemented yet435 if (native_endian != .little) return error.SkipZigTest; // Byte aligned packed struct field pointers have not been implemented yet
437436
438 const S2 = packed struct {437 const S2 = packed struct {
...@@ -513,7 +512,6 @@ test "@intFromPtr on a packed struct field unaligned and nested" {...@@ -513,7 +512,6 @@ test "@intFromPtr on a packed struct field unaligned and nested" {
513 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;512 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
514 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO513 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
515 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;514 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
516 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
517 if (native_endian != .little) return error.SkipZigTest; // Byte aligned packed struct field pointers have not been implemented yet515 if (native_endian != .little) return error.SkipZigTest; // Byte aligned packed struct field pointers have not been implemented yet
518516
519 const S1 = packed struct {517 const S1 = packed struct {
test/tests.zig+6
...@@ -29,6 +29,7 @@ const TestTarget = struct {...@@ -29,6 +29,7 @@ const TestTarget = struct {
29 use_llvm: ?bool = null,29 use_llvm: ?bool = null,
30 use_lld: ?bool = null,30 use_lld: ?bool = null,
31 force_pic: ?bool = null,31 force_pic: ?bool = null,
32 strip: ?bool = null,
32};33};
3334
34const test_targets = blk: {35const test_targets = blk: {
...@@ -115,6 +116,7 @@ const test_targets = blk: {...@@ -115,6 +116,7 @@ const test_targets = blk: {
115 },116 },
116 .use_llvm = false,117 .use_llvm = false,
117 .use_lld = false,118 .use_lld = false,
119 .strip = true,
118 },120 },
119 // Doesn't support new liveness121 // Doesn't support new liveness
120 //.{122 //.{
...@@ -497,6 +499,7 @@ const CAbiTarget = struct {...@@ -497,6 +499,7 @@ const CAbiTarget = struct {
497 use_llvm: ?bool = null,499 use_llvm: ?bool = null,
498 use_lld: ?bool = null,500 use_lld: ?bool = null,
499 force_pic: ?bool = null,501 force_pic: ?bool = null,
502 strip: ?bool = null,
500 c_defines: []const []const u8 = &.{},503 c_defines: []const []const u8 = &.{},
501};504};
502505
...@@ -528,6 +531,7 @@ const c_abi_targets = [_]CAbiTarget{...@@ -528,6 +531,7 @@ const c_abi_targets = [_]CAbiTarget{
528 },531 },
529 .use_llvm = false,532 .use_llvm = false,
530 .use_lld = false,533 .use_lld = false,
534 .strip = true,
531 .c_defines = &.{"ZIG_BACKEND_STAGE2_X86_64"},535 .c_defines = &.{"ZIG_BACKEND_STAGE2_X86_64"},
532 },536 },
533 .{537 .{
...@@ -1111,6 +1115,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {...@@ -1111,6 +1115,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
1111 .zig_lib_dir = .{ .path = "lib" },1115 .zig_lib_dir = .{ .path = "lib" },
1112 });1116 });
1113 these_tests.force_pic = test_target.force_pic;1117 these_tests.force_pic = test_target.force_pic;
1118 these_tests.strip = test_target.strip;
1114 const single_threaded_suffix = if (test_target.single_threaded == true) "-single" else "";1119 const single_threaded_suffix = if (test_target.single_threaded == true) "-single" else "";
1115 const backend_suffix = if (test_target.use_llvm == true)1120 const backend_suffix = if (test_target.use_llvm == true)
1116 "-llvm"1121 "-llvm"
...@@ -1253,6 +1258,7 @@ pub fn addCAbiTests(b: *std.Build, skip_non_native: bool, skip_release: bool) *S...@@ -1253,6 +1258,7 @@ pub fn addCAbiTests(b: *std.Build, skip_non_native: bool, skip_release: bool) *S
1253 .use_lld = c_abi_target.use_lld,1258 .use_lld = c_abi_target.use_lld,
1254 });1259 });
1255 test_step.force_pic = c_abi_target.force_pic;1260 test_step.force_pic = c_abi_target.force_pic;
1261 test_step.strip = c_abi_target.strip;
1256 if (c_abi_target.target.abi != null and c_abi_target.target.abi.?.isMusl()) {1262 if (c_abi_target.target.abi != null and c_abi_target.target.abi.?.isMusl()) {
1257 // TODO NativeTargetInfo insists on dynamically linking musl1263 // TODO NativeTargetInfo insists on dynamically linking musl
1258 // for some reason?1264 // for some reason?