| ... | @@ -617,6 +617,15 @@ fn printCpusForArch(arch_name: []const u8, show_dependencies: bool) !void { | ... | @@ -617,6 +617,15 @@ fn printCpusForArch(arch_name: []const u8, show_dependencies: bool) !void { |
| 617 | } | 617 | } |
| 618 | } | 618 | } |
| 619 | | 619 | |
| | 620 | fn toNullTerminatedStringAlloc(allocator: *std.mem.Allocator, str: []const u8) ![:0]const u8 { |
| | 621 | var buffer = try std.Buffer.init(allocator, str); |
| | 622 | |
| | 623 | const len = buffer.len(); |
| | 624 | |
| | 625 | // Don't deinit since we steal all the buffer's memory here. |
| | 626 | return buffer.list.toOwnedSlice()[0..len :0]; |
| | 627 | } |
| | 628 | |
| 620 | const Stage2TargetDetails = struct { | 629 | const Stage2TargetDetails = struct { |
| 621 | allocator: *std.mem.Allocator, | 630 | allocator: *std.mem.Allocator, |
| 622 | target_details: std.target.TargetDetails, | 631 | target_details: std.target.TargetDetails, |
| ... | @@ -643,8 +652,8 @@ const Stage2TargetDetails = struct { | ... | @@ -643,8 +652,8 @@ const Stage2TargetDetails = struct { |
| 643 | .target_details = .{ | 652 | .target_details = .{ |
| 644 | .cpu = cpu, | 653 | .cpu = cpu, |
| 645 | }, | 654 | }, |
| 646 | .llvm_cpu_str = cpu.name, | 655 | .llvm_cpu_str = try toNullTerminatedStringAlloc(allocator, cpu.name), |
| 647 | .llvm_features_str = "", | 656 | .llvm_features_str = try toNullTerminatedStringAlloc(allocator, ""), |
| 648 | .builtin_str = builtin_str_buffer.toOwnedSlice(), | 657 | .builtin_str = builtin_str_buffer.toOwnedSlice(), |
| 649 | }; | 658 | }; |
| 650 | } | 659 | } |
| ... | @@ -672,13 +681,16 @@ const Stage2TargetDetails = struct { | ... | @@ -672,13 +681,16 @@ const Stage2TargetDetails = struct { |
| 672 | | 681 | |
| 673 | try builtin_str_buffer.append("}};"); | 682 | try builtin_str_buffer.append("}};"); |
| 674 | | 683 | |
| | 684 | // This is needed here because llvm_features_buffer.len() is no longer valid after toOwnedSlice(). |
| | 685 | const llvm_features_buffer_len = llvm_features_buffer.len(); |
| | 686 | |
| 675 | return Self{ | 687 | return Self{ |
| 676 | .allocator = allocator, | 688 | .allocator = allocator, |
| 677 | .target_details = std.target.TargetDetails{ | 689 | .target_details = std.target.TargetDetails{ |
| 678 | .features = features, | 690 | .features = features, |
| 679 | }, | 691 | }, |
| 680 | .llvm_cpu_str = "", | 692 | .llvm_cpu_str = try toNullTerminatedStringAlloc(allocator, ""), |
| 681 | .llvm_features_str = llvm_features_buffer.toOwnedSlice(), | 693 | .llvm_features_str = llvm_features_buffer.toOwnedSlice()[0..llvm_features_buffer_len :0], |
| 682 | .builtin_str = builtin_str_buffer.toOwnedSlice(), | 694 | .builtin_str = builtin_str_buffer.toOwnedSlice(), |
| 683 | }; | 695 | }; |
| 684 | } | 696 | } |