zig/test/behavior/bugs/3046.zig
Jakub Konka e8eb9778cc codegen: lower field_ptr to memory across linking backends
This requires generating an addend for the target relocation as
the field pointer might point at a field inner to the container.
2022-03-01 22:03:18 +01:00

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);
}