Skip to content

Commit

Permalink
Merge pull request ziglang#18431 from jacobly0/cbe-extern
Browse files Browse the repository at this point in the history
cbe: fix non-msvc externs and exports
  • Loading branch information
andrewrk authored Jan 3, 2024
2 parents 9a56228 + 047d6d9 commit a9337be
Show file tree
Hide file tree
Showing 14 changed files with 506 additions and 223 deletions.
11 changes: 5 additions & 6 deletions ci/x86_64-windows-debug.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,8 @@ Enter-VsDevShell -VsInstallPath "C:\Program Files\Microsoft Visual Studio\2022\E
CheckLastExitCode

Write-Output "Build and run behavior tests with msvc..."
Write-Output "Skipped due to https://github.com/ziglang/zig/issues/17817"
#& cl.exe -I..\lib test-x86_64-windows-msvc.c compiler_rt-x86_64-windows-msvc.c /W3 /Z7 -link -nologo -debug -subsystem:console kernel32.lib ntdll.lib libcmt.lib
#CheckLastExitCode
#
#& .\test-x86_64-windows-msvc.exe
#CheckLastExitCode
& cl.exe -I..\lib test-x86_64-windows-msvc.c compiler_rt-x86_64-windows-msvc.c /W3 /Z7 -link -nologo -debug -subsystem:console kernel32.lib ntdll.lib libcmt.lib
CheckLastExitCode

& .\test-x86_64-windows-msvc.exe
CheckLastExitCode
11 changes: 5 additions & 6 deletions ci/x86_64-windows-release.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,8 @@ Enter-VsDevShell -VsInstallPath "C:\Program Files\Microsoft Visual Studio\2022\E
CheckLastExitCode

Write-Output "Build and run behavior tests with msvc..."
Write-Output "Skipped due to https://github.com/ziglang/zig/issues/17817"
#& cl.exe -I..\lib test-x86_64-windows-msvc.c compiler_rt-x86_64-windows-msvc.c /W3 /Z7 -link -nologo -debug -subsystem:console kernel32.lib ntdll.lib libcmt.lib
#CheckLastExitCode
#
#& .\test-x86_64-windows-msvc.exe
#CheckLastExitCode
& cl.exe -I..\lib test-x86_64-windows-msvc.c compiler_rt-x86_64-windows-msvc.c /W3 /Z7 -link -nologo -debug -subsystem:console kernel32.lib ntdll.lib libcmt.lib
CheckLastExitCode

& .\test-x86_64-windows-msvc.exe
CheckLastExitCode
1 change: 1 addition & 0 deletions lib/std/math.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,7 @@ pub fn lerp(a: anytype, b: anytype, t: anytype) @TypeOf(a, b, t) {
}

test "lerp" {
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/17884
if (builtin.zig_backend == .stage2_x86_64 and
!comptime std.Target.x86.featureSetHas(builtin.cpu.features, .fma)) return error.SkipZigTest;

Expand Down
249 changes: 157 additions & 92 deletions lib/zig.h

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/AstGen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4456,6 +4456,7 @@ fn globalVarDecl(
.align_inst = .none, // passed via the decls data
.init = init_inst,
.is_extern = false,
.is_const = !is_mutable,
.is_threadlocal = is_threadlocal,
});
break :vi var_inst;
Expand All @@ -4474,6 +4475,7 @@ fn globalVarDecl(
.align_inst = .none, // passed via the decls data
.init = .none,
.is_extern = true,
.is_const = !is_mutable,
.is_threadlocal = is_threadlocal,
});
break :vi var_inst;
Expand Down Expand Up @@ -11495,6 +11497,7 @@ const GenZir = struct {
var_type: Zir.Inst.Ref,
init: Zir.Inst.Ref,
is_extern: bool,
is_const: bool,
is_threadlocal: bool,
}) !Zir.Inst.Ref {
const astgen = gz.astgen;
Expand Down Expand Up @@ -11533,6 +11536,7 @@ const GenZir = struct {
.has_align = args.align_inst != .none,
.has_init = args.init != .none,
.is_extern = args.is_extern,
.is_const = args.is_const,
.is_threadlocal = args.is_threadlocal,
}),
.operand = payload_index,
Expand Down
10 changes: 5 additions & 5 deletions src/InternPool.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1005,11 +1005,11 @@ pub const Key = union(enum) {
ty: Index,
init: Index,
decl: DeclIndex,
lib_name: OptionalNullTerminatedString = .none,
is_extern: bool = false,
is_const: bool = false,
is_threadlocal: bool = false,
is_weak_linkage: bool = false,
lib_name: OptionalNullTerminatedString,
is_extern: bool,
is_const: bool,
is_threadlocal: bool,
is_weak_linkage: bool,
};

pub const ExternFunc = struct {
Expand Down
10 changes: 7 additions & 3 deletions src/Sema.zig
Original file line number Diff line number Diff line change
Expand Up @@ -24760,7 +24760,9 @@ fn zirVarExtended(
.decl = sema.owner_decl_index,
.lib_name = try mod.intern_pool.getOrPutStringOpt(sema.gpa, lib_name),
.is_extern = small.is_extern,
.is_const = small.is_const,
.is_threadlocal = small.is_threadlocal,
.is_weak_linkage = false,
} })));
}

Expand Down Expand Up @@ -25264,6 +25266,7 @@ fn zirBuiltinExtern(
if (options.linkage == .Weak and !ty.ptrAllowsZero(mod)) {
ty = try mod.optionalType(ty.toIntern());
}
const ptr_info = ty.ptrInfo(mod);

// TODO check duplicate extern

Expand All @@ -25274,19 +25277,20 @@ fn zirBuiltinExtern(

{
const new_var = try mod.intern(.{ .variable = .{
.ty = ty.toIntern(),
.ty = ptr_info.child,
.init = .none,
.decl = sema.owner_decl_index,
.lib_name = options.library_name,
.is_extern = true,
.is_const = true,
.is_const = ptr_info.flags.is_const,
.is_threadlocal = options.is_thread_local,
.is_weak_linkage = options.linkage == .Weak,
} });

new_decl.src_line = sema.owner_decl.src_line;
// We only access this decl through the decl_ref with the correct type created
// below, so this type doesn't matter
new_decl.ty = ty;
new_decl.ty = Type.fromInterned(ptr_info.child);
new_decl.val = Value.fromInterned(new_var);
new_decl.alignment = .none;
new_decl.@"linksection" = .none;
Expand Down
3 changes: 2 additions & 1 deletion src/Zir.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2610,8 +2610,9 @@ pub const Inst = struct {
has_align: bool,
has_init: bool,
is_extern: bool,
is_const: bool,
is_threadlocal: bool,
_: u11 = undefined,
_: u10 = undefined,
};
};

Expand Down
Loading

0 comments on commit a9337be

Please sign in to comment.