mirror of
https://github.com/ziglang/zig.git
synced 2024-11-15 00:26:57 +00:00
parent
aba8d4f62c
commit
30688c341b
@ -3256,7 +3256,12 @@ pub const Object = struct {
|
||||
128 => .fp128,
|
||||
else => unreachable,
|
||||
},
|
||||
.anyopaque_type => unreachable,
|
||||
.anyopaque_type => {
|
||||
// This is unreachable except when used as the type for an extern global.
|
||||
// For example: `@extern(*anyopaque, .{ .name = "foo"})` should produce
|
||||
// @foo = external global i8
|
||||
return .i8;
|
||||
},
|
||||
.bool_type => .i1,
|
||||
.void_type => .void,
|
||||
.type_type => unreachable,
|
||||
|
@ -32,6 +32,7 @@ test {
|
||||
_ = @import("behavior/eval.zig");
|
||||
_ = @import("behavior/export_builtin.zig");
|
||||
_ = @import("behavior/export_self_referential_type_info.zig");
|
||||
_ = @import("behavior/extern.zig");
|
||||
_ = @import("behavior/field_parent_ptr.zig");
|
||||
_ = @import("behavior/floatop.zig");
|
||||
_ = @import("behavior/fn.zig");
|
||||
|
14
test/behavior/extern.zig
Normal file
14
test/behavior/extern.zig
Normal file
@ -0,0 +1,14 @@
|
||||
const builtin = @import("builtin");
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
|
||||
test "anyopaque extern symbol" {
|
||||
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
|
||||
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
|
||||
|
||||
const a = @extern(*anyopaque, .{ .name = "a_mystery_symbol" });
|
||||
const b: *i32 = @alignCast(@ptrCast(a));
|
||||
try expect(b.* == 1234);
|
||||
}
|
||||
|
||||
export var a_mystery_symbol: i32 = 1234;
|
Loading…
Reference in New Issue
Block a user