| ... | ... | @@ -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 | 629 | const Stage2TargetDetails = struct { |
| 621 | 630 | allocator: *std.mem.Allocator, |
| 622 | 631 | target_details: std.target.TargetDetails, |
| ... | ... | @@ -643,8 +652,8 @@ const Stage2TargetDetails = struct { |
| 643 | 652 | .target_details = .{ |
| 644 | 653 | .cpu = cpu, |
| 645 | 654 | }, |
| 646 | | .llvm_cpu_str = cpu.name, |
| 647 | | .llvm_features_str = "", |
| 655 | .llvm_cpu_str = try toNullTerminatedStringAlloc(allocator, cpu.name), |
| 656 | .llvm_features_str = try toNullTerminatedStringAlloc(allocator, ""), |
| 648 | 657 | .builtin_str = builtin_str_buffer.toOwnedSlice(), |
| 649 | 658 | }; |
| 650 | 659 | } |
| ... | ... | @@ -672,13 +681,16 @@ const Stage2TargetDetails = struct { |
| 672 | 681 | |
| 673 | 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 | 687 | return Self{ |
| 676 | 688 | .allocator = allocator, |
| 677 | 689 | .target_details = std.target.TargetDetails{ |
| 678 | 690 | .features = features, |
| 679 | 691 | }, |
| 680 | | .llvm_cpu_str = "", |
| 681 | | .llvm_features_str = llvm_features_buffer.toOwnedSlice(), |
| 692 | .llvm_cpu_str = try toNullTerminatedStringAlloc(allocator, ""), |
| 693 | .llvm_features_str = llvm_features_buffer.toOwnedSlice()[0..llvm_features_buffer_len :0], |
| 682 | 694 | .builtin_str = builtin_str_buffer.toOwnedSlice(), |
| 683 | 695 | }; |
| 684 | 696 | } |