authorgravatar for lgustaf1@binghamton.eduLayne Gustafson <lgustaf1@binghamton.edu> 2020-01-15 18:12:32-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-01-19 20:53:20-05:00
loga5c93975394af6638e04f6a8a8c4f060bc4887d1
tree0f40bd96aa9d512a4ca922d15122a58fe8dec7ea
parent40ff35948625e47964d2adbc3bdec8bd6a40d2db
signaturelock-open Commit is signed but in an unrecognized format.

No allocations for n.t. empty strings


1 files changed, 8 insertions(+), 6 deletions(-)

src-self-hosted/stage1.zig+8-6
...@@ -617,6 +617,8 @@ fn printCpusForArch(arch_name: []const u8, show_dependencies: bool) !void {...@@ -617,6 +617,8 @@ fn printCpusForArch(arch_name: []const u8, show_dependencies: bool) !void {
617 }617 }
618}618}
619619
620const null_terminated_empty_string = (&[_]u8 { 0 })[0..0 :0];
621
620fn toNullTerminatedStringAlloc(allocator: *std.mem.Allocator, str: []const u8) ![:0]const u8 {622fn toNullTerminatedStringAlloc(allocator: *std.mem.Allocator, str: []const u8) ![:0]const u8 {
621 var buffer = try std.Buffer.init(allocator, str);623 var buffer = try std.Buffer.init(allocator, str);
622 624
...@@ -653,7 +655,7 @@ const Stage2TargetDetails = struct {...@@ -653,7 +655,7 @@ const Stage2TargetDetails = struct {
653 .cpu = cpu,655 .cpu = cpu,
654 },656 },
655 .llvm_cpu_str = try toNullTerminatedStringAlloc(allocator, cpu.name),657 .llvm_cpu_str = try toNullTerminatedStringAlloc(allocator, cpu.name),
656 .llvm_features_str = try toNullTerminatedStringAlloc(allocator, ""),658 .llvm_features_str = null_terminated_empty_string,
657 .builtin_str = builtin_str_buffer.toOwnedSlice(),659 .builtin_str = builtin_str_buffer.toOwnedSlice(),
658 };660 };
659 }661 }
...@@ -697,7 +699,7 @@ const Stage2TargetDetails = struct {...@@ -697,7 +699,7 @@ const Stage2TargetDetails = struct {
697 .target_details = std.target.TargetDetails{699 .target_details = std.target.TargetDetails{
698 .features = features,700 .features = features,
699 },701 },
700 .llvm_cpu_str = try toNullTerminatedStringAlloc(allocator, ""),702 .llvm_cpu_str = null_terminated_empty_string,
701 .llvm_features_str = llvm_features_buffer.toOwnedSlice()[0..llvm_features_buffer_len :0],703 .llvm_features_str = llvm_features_buffer.toOwnedSlice()[0..llvm_features_buffer_len :0],
702 .builtin_str = builtin_str_buffer.toOwnedSlice(),704 .builtin_str = builtin_str_buffer.toOwnedSlice(),
703 };705 };
...@@ -801,7 +803,7 @@ export fn stage2_target_details_get_cache_str(target_details: ?*const Stage2Targ...@@ -801,7 +803,7 @@ export fn stage2_target_details_get_cache_str(target_details: ?*const Stage2Targ
801 });803 });
802 }804 }
803805
804 return @as([*:0]const u8, "");806 return @as([*:0]const u8, null_terminated_empty_string);
805}807}
806808
807// ABI warning809// ABI warning
...@@ -810,7 +812,7 @@ export fn stage2_target_details_get_llvm_cpu(target_details: ?*const Stage2Targe...@@ -810,7 +812,7 @@ export fn stage2_target_details_get_llvm_cpu(target_details: ?*const Stage2Targe
810 return @as([*:0]const u8, td.llvm_cpu_str);812 return @as([*:0]const u8, td.llvm_cpu_str);
811 }813 }
812814
813 return @as([*:0]const u8, "");815 return @as([*:0]const u8, null_terminated_empty_string);
814}816}
815817
816// ABI warning818// ABI warning
...@@ -819,7 +821,7 @@ export fn stage2_target_details_get_llvm_features(target_details: ?*const Stage2...@@ -819,7 +821,7 @@ export fn stage2_target_details_get_llvm_features(target_details: ?*const Stage2
819 return @as([*:0]const u8, td.llvm_features_str);821 return @as([*:0]const u8, td.llvm_features_str);
820 }822 }
821823
822 return @as([*:0]const u8, "");824 return @as([*:0]const u8, null_terminated_empty_string);
823}825}
824826
825// ABI warning827// ABI warning
...@@ -828,7 +830,7 @@ export fn stage2_target_details_get_builtin_str(target_details: ?*const Stage2Ta...@@ -828,7 +830,7 @@ export fn stage2_target_details_get_builtin_str(target_details: ?*const Stage2Ta
828 return @as([*:0]const u8, td.builtin_str);830 return @as([*:0]const u8, td.builtin_str);
829 }831 }
830832
831 return @as([*:0]const u8, "");833 return @as([*:0]const u8, null_terminated_empty_string);
832}834}
833835
834const riscv_default_features: []*const std.target.Feature = &[_]*const std.target.Feature {836const riscv_default_features: []*const std.target.Feature = &[_]*const std.target.Feature {