mirror of
https://github.com/ziglang/zig.git
synced 2024-11-27 15:42:49 +00:00
tests: use a more portable way of determining the return address in the test code
This commit is contained in:
parent
b18031335a
commit
06bf2e048b
@ -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:
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user