From 06bf2e048b24dcba28bcb7b00236b3cdb2504cc4 Mon Sep 17 00:00:00 2001 From: kcbanner Date: Wed, 12 Jul 2023 18:41:53 -0400 Subject: [PATCH] tests: use a more portable way of determining the return address in the test code --- test/standalone/dwarf_unwinding/shared_lib.c | 6 ++---- .../dwarf_unwinding/shared_lib_unwind.zig | 17 +++++++++-------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/test/standalone/dwarf_unwinding/shared_lib.c b/test/standalone/dwarf_unwinding/shared_lib.c index 2329fedda9..c3170f2dc0 100644 --- a/test/standalone/dwarf_unwinding/shared_lib.c +++ b/test/standalone/dwarf_unwinding/shared_lib.c @@ -8,17 +8,15 @@ __attribute__((noinline)) void frame1( void** expected, void** unwound, void (*frame2)(void** expected, void** unwound)) { - expected[2] = &&frame_2_ret; + expected[3] = __builtin_extract_return_addr(__builtin_return_address(0)); frame2(expected, unwound); - frame_2_ret: } LIB_API void frame0( void** expected, void** unwound, void (*frame2)(void** expected, void** unwound)) { - expected[3] = &&frame_1_ret; + expected[4] = __builtin_extract_return_addr(__builtin_return_address(0)); frame1(expected, unwound, frame2); - frame_1_ret: } diff --git a/test/standalone/dwarf_unwinding/shared_lib_unwind.zig b/test/standalone/dwarf_unwinding/shared_lib_unwind.zig index 543654d24f..22f0081744 100644 --- a/test/standalone/dwarf_unwinding/shared_lib_unwind.zig +++ b/test/standalone/dwarf_unwinding/shared_lib_unwind.zig @@ -2,7 +2,7 @@ const std = @import("std"); const debug = std.debug; const testing = std.testing; -noinline fn frame4(expected: *[4]usize, unwound: *[4]usize) void { +noinline fn frame4(expected: *[5]usize, unwound: *[5]usize) void { expected[0] = @returnAddress(); var context: debug.ThreadContext = undefined; @@ -17,26 +17,27 @@ noinline fn frame4(expected: *[4]usize, unwound: *[4]usize) void { } } -noinline fn frame3(expected: *[4]usize, unwound: *[4]usize) void { +noinline fn frame3(expected: *[5]usize, unwound: *[5]usize) void { expected[1] = @returnAddress(); frame4(expected, unwound); } -fn frame2(expected: *[4]usize, unwound: *[4]usize) callconv(.C) void { +fn frame2(expected: *[5]usize, unwound: *[5]usize) callconv(.C) void { + expected[2] = @returnAddress(); frame3(expected, unwound); } extern fn frame0( - expected: *[4]usize, - unwound: *[4]usize, - frame_2: *const fn (expected: *[4]usize, unwound: *[4]usize) callconv(.C) void, + expected: *[5]usize, + unwound: *[5]usize, + frame_2: *const fn (expected: *[5]usize, unwound: *[5]usize) callconv(.C) void, ) void; pub fn main() !void { if (!std.debug.have_ucontext or !std.debug.have_getcontext) return; - var expected: [4]usize = undefined; - var unwound: [4]usize = undefined; + var expected: [5]usize = undefined; + var unwound: [5]usize = undefined; frame0(&expected, &unwound, &frame2); try testing.expectEqual(expected, unwound); }