authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-11-18 16:44:12-08:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-11-18 16:44:12-08:00
logfbcb00fbb38715cede40fb4af6b6f99b771ff02a
tree53709862fe67e2eba89bb08da1866391d11db3a0
parente6d2e1641363c97f53d4168b319b4dca6224e25e
parent41282e7fb2874c3c838e2b00761d6e8b174a7beb
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #22004 from jacobly0/fix-self-llvm

fix llvm-enabled compiler builds with the self-hosted backend

5 files changed, 32 insertions(+), 13 deletions(-)

build.zig+4
......@@ -861,6 +861,10 @@ fn addCxxKnownPath(
861861 }
862862 return error.RequiredLibraryNotFound;
863863 }
864 // By default, explicit library paths are not checked for being linker scripts,
865 // but libc++ may very well be one, so force all inputs to be checked when passing
866 // an explicit path to libc++.
867 exe.allow_so_scripts = true;
864868 exe.addObjectFile(.{ .cwd_relative = path_unpadded });
865869
866870 // TODO a way to integrate with system c++ include files here
src/Sema.zig+15-11
......@@ -35010,6 +35010,7 @@ fn resolvePeerTypesInner(
3501035010 // if there were no actual slices. Else, we want the slice index to report a conflict.
3501135011 var opt_slice_idx: ?usize = null;
3501235012
35013 var any_abi_aligned = false;
3501335014 var opt_ptr_info: ?InternPool.Key.PtrType = null;
3501435015 var first_idx: usize = undefined;
3501535016 var other_idx: usize = undefined; // We sometimes need a second peer index to report a generic error
......@@ -35054,17 +35055,14 @@ fn resolvePeerTypesInner(
3505435055 } };
3505535056
3505635057 // Note that the align can be always non-zero; Type.ptr will canonicalize it
35057 ptr_info.flags.alignment = Alignment.min(
35058 if (ptr_info.flags.alignment != .none)
35059 ptr_info.flags.alignment
35060 else
35061 try Type.fromInterned(ptr_info.child).abiAlignmentSema(pt),
35062
35063 if (peer_info.flags.alignment != .none)
35064 peer_info.flags.alignment
35065 else
35066 try Type.fromInterned(peer_info.child).abiAlignmentSema(pt),
35067 );
35058 if (peer_info.flags.alignment == .none) {
35059 any_abi_aligned = true;
35060 } else if (ptr_info.flags.alignment == .none) {
35061 any_abi_aligned = true;
35062 ptr_info.flags.alignment = peer_info.flags.alignment;
35063 } else {
35064 ptr_info.flags.alignment = ptr_info.flags.alignment.minStrict(peer_info.flags.alignment);
35065 }
3506835066
3506935067 if (ptr_info.flags.address_space != peer_info.flags.address_space) {
3507035068 return generic_err;
......@@ -35312,6 +35310,12 @@ fn resolvePeerTypesInner(
3531235310 },
3531335311 }
3531435312
35313 if (any_abi_aligned and opt_ptr_info.?.flags.alignment != .none) {
35314 opt_ptr_info.?.flags.alignment = opt_ptr_info.?.flags.alignment.minStrict(
35315 try Type.fromInterned(pointee).abiAlignmentSema(pt),
35316 );
35317 }
35318
3531535319 return .{ .success = try pt.ptrTypeSema(opt_ptr_info.?) };
3531635320 },
3531735321
src/link/Elf/SharedObject.zig+1
......@@ -72,6 +72,7 @@ pub const Parsed = struct {
7272
7373 pub fn deinit(p: *Parsed, gpa: Allocator) void {
7474 gpa.free(p.strtab);
75 gpa.free(p.sections);
7576 gpa.free(p.symtab);
7677 gpa.free(p.versyms);
7778 gpa.free(p.symbols);
src/main.zig+4-2
......@@ -984,6 +984,7 @@ fn buildOutputType(
984984 .libc_paths_file = try EnvVar.ZIG_LIBC.get(arena),
985985 .native_system_include_paths = &.{},
986986 };
987 defer create_module.link_inputs.deinit(gpa);
987988
988989 // before arg parsing, check for the NO_COLOR and CLICOLOR_FORCE environment variables
989990 // if set, default the color setting to .off or .on, respectively
......@@ -3682,7 +3683,7 @@ const CreateModule = struct {
36823683 /// This one is used while collecting CLI options. The set of libs is used
36833684 /// directly after computing the target and used to compute link_libc,
36843685 /// link_libcpp, and then the libraries are filtered into
3685 /// `unresolved_linker_inputs` and `windows_libs`.
3686 /// `unresolved_link_inputs` and `windows_libs`.
36863687 cli_link_inputs: std.ArrayListUnmanaged(link.UnresolvedInput),
36873688 windows_libs: std.StringArrayHashMapUnmanaged(void),
36883689 /// The local variable `unresolved_link_inputs` is fed into library
......@@ -3816,7 +3817,8 @@ fn createModule(
38163817 // to decide whether to trigger native path detection logic.
38173818 // Preserves linker input order.
38183819 var unresolved_link_inputs: std.ArrayListUnmanaged(link.UnresolvedInput) = .empty;
3819 try unresolved_link_inputs.ensureUnusedCapacity(arena, create_module.cli_link_inputs.items.len);
3820 defer unresolved_link_inputs.deinit(gpa);
3821 try unresolved_link_inputs.ensureUnusedCapacity(gpa, create_module.cli_link_inputs.items.len);
38203822 var any_name_queries_remaining = false;
38213823 for (create_module.cli_link_inputs.items) |cli_link_input| switch (cli_link_input) {
38223824 .name_query => |nq| {
test/behavior/slice.zig+8
......@@ -995,3 +995,11 @@ test "sentinel-terminated 0-length slices" {
995995 try expect(comptime_known_array_value[0] == 2);
996996 try expect(runtime_array_value[0] == 2);
997997}
998
999test "peer slices keep abi alignment with empty struct" {
1000 var cond: bool = undefined;
1001 cond = false;
1002 const slice = if (cond) &[1]u32{42} else &.{};
1003 comptime assert(@TypeOf(slice) == []const u32);
1004 try expect(slice.len == 0);
1005}