mirror of
https://github.com/ziglang/zig.git
synced 2025-12-10 16:23:07 +00:00
This requires generating an addend for the target relocation as the field pointer might point at a field inner to the container.
25 lines
592 B
Zig
25 lines
592 B
Zig
const std = @import("std");
|
|
const builtin = @import("builtin");
|
|
const expect = std.testing.expect;
|
|
|
|
const SomeStruct = struct {
|
|
field: i32,
|
|
};
|
|
|
|
fn couldFail() anyerror!i32 {
|
|
return 1;
|
|
}
|
|
|
|
var some_struct: SomeStruct = undefined;
|
|
|
|
test "fixed" {
|
|
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
|
|
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
|
|
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
|
|
|
|
some_struct = SomeStruct{
|
|
.field = couldFail() catch @as(i32, 0),
|
|
};
|
|
try expect(some_struct.field == 1);
|
|
}
|