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 {
617617 }
618618}
619619
620const null_terminated_empty_string = (&[_]u8 { 0 })[0..0 :0];
621
620622fn toNullTerminatedStringAlloc(allocator: *std.mem.Allocator, str: []const u8) ![:0]const u8 {
621623 var buffer = try std.Buffer.init(allocator, str);
622624
......@@ -653,7 +655,7 @@ const Stage2TargetDetails = struct {
653655 .cpu = cpu,
654656 },
655657 .llvm_cpu_str = try toNullTerminatedStringAlloc(allocator, cpu.name),
656 .llvm_features_str = try toNullTerminatedStringAlloc(allocator, ""),
658 .llvm_features_str = null_terminated_empty_string,
657659 .builtin_str = builtin_str_buffer.toOwnedSlice(),
658660 };
659661 }
......@@ -697,7 +699,7 @@ const Stage2TargetDetails = struct {
697699 .target_details = std.target.TargetDetails{
698700 .features = features,
699701 },
700 .llvm_cpu_str = try toNullTerminatedStringAlloc(allocator, ""),
702 .llvm_cpu_str = null_terminated_empty_string,
701703 .llvm_features_str = llvm_features_buffer.toOwnedSlice()[0..llvm_features_buffer_len :0],
702704 .builtin_str = builtin_str_buffer.toOwnedSlice(),
703705 };
......@@ -801,7 +803,7 @@ export fn stage2_target_details_get_cache_str(target_details: ?*const Stage2Targ
801803 });
802804 }
803805
804 return @as([*:0]const u8, "");
806 return @as([*:0]const u8, null_terminated_empty_string);
805807}
806808
807809// ABI warning
......@@ -810,7 +812,7 @@ export fn stage2_target_details_get_llvm_cpu(target_details: ?*const Stage2Targe
810812 return @as([*:0]const u8, td.llvm_cpu_str);
811813 }
812814
813 return @as([*:0]const u8, "");
815 return @as([*:0]const u8, null_terminated_empty_string);
814816}
815817
816818// ABI warning
......@@ -819,7 +821,7 @@ export fn stage2_target_details_get_llvm_features(target_details: ?*const Stage2
819821 return @as([*:0]const u8, td.llvm_features_str);
820822 }
821823
822 return @as([*:0]const u8, "");
824 return @as([*:0]const u8, null_terminated_empty_string);
823825}
824826
825827// ABI warning
......@@ -828,7 +830,7 @@ export fn stage2_target_details_get_builtin_str(target_details: ?*const Stage2Ta
828830 return @as([*:0]const u8, td.builtin_str);
829831 }
830832
831 return @as([*:0]const u8, "");
833 return @as([*:0]const u8, null_terminated_empty_string);
832834}
833835
834836const riscv_default_features: []*const std.target.Feature = &[_]*const std.target.Feature {