| author | |
| committer | |
| log | 7edd69d8aade6da2339cb0d9a027c52b3015bc31 |
| tree | c6b512d777288c062712c2980b788216e6338d9c |
| parent | b87fa93500380068b0fd1db6cd73623f3fbfa284 |
- tests/standalone/extern wasn't running its test step
- add compile error tests for thread local / dll import @extern in a comptime scope5 files changed, 46 insertions(+), 7 deletions(-)
src/InternPool.zig+2-2| ... | ... | @@ -2676,8 +2676,8 @@ pub const Key = union(enum) { |
| 2676 | 2676 | asBytes(&e.ty) ++ asBytes(&e.lib_name) ++ |
| 2677 | 2677 | asBytes(&e.is_const) ++ asBytes(&e.is_threadlocal) ++ |
| 2678 | 2678 | asBytes(&e.is_weak_linkage) ++ asBytes(&e.alignment) ++ |
| 2679 | asBytes(&e.is_dll_import) ++ asBytes(&e.alignment) ++ | |
| 2680 | asBytes(&e.@"addrspace") ++ asBytes(&e.zir_index)), | |
| 2679 | asBytes(&e.is_dll_import) ++ asBytes(&e.@"addrspace") ++ | |
| 2680 | asBytes(&e.zir_index)), | |
| 2681 | 2681 | }; |
| 2682 | 2682 | } |
| 2683 | 2683 |
test/cases/compile_errors/builtin_extern_in_comptime_scope.zig created+18| ... | ... | @@ -0,0 +1,18 @@ |
| 1 | const foo_tl = @extern(*i32, .{ .name = "foo", .is_thread_local = true }); | |
| 2 | const foo_dll = @extern(*i32, .{ .name = "foo", .is_dll_import = true }); | |
| 3 | pub export fn entry() void { | |
| 4 | _ = foo_tl; | |
| 5 | } | |
| 6 | pub export fn entry2() void { | |
| 7 | _ = foo_dll; | |
| 8 | } | |
| 9 | // error | |
| 10 | // backend=stage2 | |
| 11 | // target=native | |
| 12 | // | |
| 13 | // :1:16: error: unable to resolve comptime value | |
| 14 | // :1:16: note: global variable initializer must be comptime-known | |
| 15 | // :1:16: note: thread local and dll imported variables have runtime-known addresses | |
| 16 | // :2:17: error: unable to resolve comptime value | |
| 17 | // :2:17: note: global variable initializer must be comptime-known | |
| 18 | // :2:17: note: thread local and dll imported variables have runtime-known addresses |
test/standalone/extern/build.zig+15-4| ... | ... | @@ -1,6 +1,9 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | |
| 3 | 3 | pub fn build(b: *std.Build) void { |
| 4 | const test_step = b.step("test", "Test it"); | |
| 5 | b.default_step = test_step; | |
| 6 | ||
| 4 | 7 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 5 | 8 | |
| 6 | 9 | const obj = b.addObject(.{ |
| ... | ... | @@ -9,12 +12,20 @@ pub fn build(b: *std.Build) void { |
| 9 | 12 | .target = b.graph.host, |
| 10 | 13 | .optimize = optimize, |
| 11 | 14 | }); |
| 12 | const main = b.addTest(.{ | |
| 15 | const shared = b.addSharedLibrary(.{ | |
| 16 | .name = "shared", | |
| 17 | .target = b.graph.host, | |
| 18 | .optimize = optimize, | |
| 19 | .link_libc = true, | |
| 20 | }); | |
| 21 | if (b.graph.host.result.abi == .msvc) shared.defineCMacro("API", "__declspec(dllexport)"); | |
| 22 | shared.addCSourceFile(.{ .file = b.path("shared.c"), .flags = &.{} }); | |
| 23 | const test_exe = b.addTest(.{ | |
| 13 | 24 | .root_source_file = b.path("main.zig"), |
| 14 | 25 | .optimize = optimize, |
| 15 | 26 | }); |
| 16 | main.addObject(obj); | |
| 27 | test_exe.addObject(obj); | |
| 28 | test_exe.linkLibrary(shared); | |
| 17 | 29 | |
| 18 | const test_step = b.step("test", "Test it"); | |
| 19 | test_step.dependOn(&main.step); | |
| 30 | test_step.dependOn(&b.addRunArtifact(test_exe).step); | |
| 20 | 31 | } |
test/standalone/extern/main.zig+6-1| ... | ... | @@ -1,4 +1,5 @@ |
| 1 | 1 | const assert = @import("std").debug.assert; |
| 2 | const testing = @import("std").testing; | |
| 2 | 3 | |
| 3 | 4 | const updateHidden = @extern(*const fn (u32) callconv(.C) void, .{ .name = "updateHidden" }); |
| 4 | 5 | const getHidden = @extern(*const fn () callconv(.C) u32, .{ .name = "getHidden" }); |
| ... | ... | @@ -8,14 +9,18 @@ const T = extern struct { x: u32 }; |
| 8 | 9 | test { |
| 9 | 10 | const mut_val_ptr = @extern(*f64, .{ .name = "mut_val" }); |
| 10 | 11 | const const_val_ptr = @extern(*const T, .{ .name = "const_val" }); |
| 12 | const shared_val_ptr = @extern(*c_int, .{ .name = "shared_val", .is_dll_import = true }); | |
| 11 | 13 | |
| 12 | 14 | assert(getHidden() == 0); |
| 13 | 15 | updateHidden(123); |
| 14 | 16 | assert(getHidden() == 123); |
| 15 | ||
| 16 | 17 | assert(mut_val_ptr.* == 1.23); |
| 17 | 18 | mut_val_ptr.* = 10.0; |
| 18 | 19 | assert(mut_val_ptr.* == 10.0); |
| 19 | 20 | |
| 20 | 21 | assert(const_val_ptr.x == 42); |
| 22 | ||
| 23 | assert(shared_val_ptr.* == 1234); | |
| 24 | shared_val_ptr.* = 1235; | |
| 25 | assert(shared_val_ptr.* == 1235); | |
| 21 | 26 | } |
test/standalone/extern/shared.c created+5| ... | ... | @@ -0,0 +1,5 @@ |
| 1 | #ifndef API | |
| 2 | #define API | |
| 3 | #endif | |
| 4 | ||
| 5 | API int shared_val = 1234; |