authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-11-19 20:29:08-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-11-21 20:43:41-05:00
log47f06be36943f808aa9798c19172363afe6ae35c
tree79ede48ae2cbbbbe2e2489b2733df4e907bfe968
parent21f344b3b903b41fd4793faa82a4ac26ad2544aa
signaturelock-open Commit is signed but in an unrecognized format.

string literals are now null terminated

this also deletes C string literals from the language, and then makes the std lib changes and compiler changes necessary to get the behavior tests and std lib tests passing again.

51 files changed, 986 insertions(+), 716 deletions(-)

lib/std/child_process.zig+1-1
......@@ -328,7 +328,7 @@ pub const ChildProcess = struct {
328328
329329 const any_ignore = (self.stdin_behavior == StdIo.Ignore or self.stdout_behavior == StdIo.Ignore or self.stderr_behavior == StdIo.Ignore);
330330 const dev_null_fd = if (any_ignore)
331 os.openC(c"/dev/null", os.O_RDWR, 0) catch |err| switch (err) {
331 os.openC("/dev/null", os.O_RDWR, 0) catch |err| switch (err) {
332332 error.PathAlreadyExists => unreachable,
333333 error.NoSpaceLeft => unreachable,
334334 error.FileTooBig => unreachable,
lib/std/crypto/x25519.zig+6-6
......@@ -610,8 +610,8 @@ test "x25519 rfc7748 vector2" {
610610}
611611
612612test "x25519 rfc7748 one iteration" {
613 const initial_value = "\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
614 const expected_output = "\x42\x2c\x8e\x7a\x62\x27\xd7\xbc\xa1\x35\x0b\x3e\x2b\xb7\x27\x9f\x78\x97\xb8\x7b\xb6\x85\x4b\x78\x3c\x60\xe8\x03\x11\xae\x30\x79";
613 const initial_value = "\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".*;
614 const expected_output = "\x42\x2c\x8e\x7a\x62\x27\xd7\xbc\xa1\x35\x0b\x3e\x2b\xb7\x27\x9f\x78\x97\xb8\x7b\xb6\x85\x4b\x78\x3c\x60\xe8\x03\x11\xae\x30\x79".*;
615615
616616 var k: [32]u8 = initial_value;
617617 var u: [32]u8 = initial_value;
......@@ -634,8 +634,8 @@ test "x25519 rfc7748 1,000 iterations" {
634634 return error.SkipZigTest;
635635 }
636636
637 const initial_value = "\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
638 const expected_output = "\x68\x4c\xf5\x9b\xa8\x33\x09\x55\x28\x00\xef\x56\x6f\x2f\x4d\x3c\x1c\x38\x87\xc4\x93\x60\xe3\x87\x5f\x2e\xb9\x4d\x99\x53\x2c\x51";
637 const initial_value = "\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".*;
638 const expected_output = "\x68\x4c\xf5\x9b\xa8\x33\x09\x55\x28\x00\xef\x56\x6f\x2f\x4d\x3c\x1c\x38\x87\xc4\x93\x60\xe3\x87\x5f\x2e\xb9\x4d\x99\x53\x2c\x51".*;
639639
640640 var k: [32]u8 = initial_value;
641641 var u: [32]u8 = initial_value;
......@@ -657,8 +657,8 @@ test "x25519 rfc7748 1,000,000 iterations" {
657657 return error.SkipZigTest;
658658 }
659659
660 const initial_value = "\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
661 const expected_output = "\x7c\x39\x11\xe0\xab\x25\x86\xfd\x86\x44\x97\x29\x7e\x57\x5e\x6f\x3b\xc6\x01\xc0\x88\x3c\x30\xdf\x5f\x4d\xd2\xd2\x4f\x66\x54\x24";
660 const initial_value = "\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".*;
661 const expected_output = "\x7c\x39\x11\xe0\xab\x25\x86\xfd\x86\x44\x97\x29\x7e\x57\x5e\x6f\x3b\xc6\x01\xc0\x88\x3c\x30\xdf\x5f\x4d\xd2\xd2\x4f\x66\x54\x24".*;
662662
663663 var k: [32]u8 = initial_value;
664664 var u: [32]u8 = initial_value;
lib/std/cstr.zig+2-2
......@@ -27,8 +27,8 @@ test "cstr fns" {
2727}
2828
2929fn testCStrFnsImpl() void {
30 testing.expect(cmp(c"aoeu", c"aoez") == -1);
31 testing.expect(mem.len(u8, c"123456789") == 9);
30 testing.expect(cmp("aoeu", "aoez") == -1);
31 testing.expect(mem.len(u8, "123456789") == 9);
3232}
3333
3434/// Returns a mutable slice with 1 more byte of length which is a null byte.
lib/std/fmt.zig+55-57
......@@ -1,8 +1,6 @@
11const std = @import("std.zig");
22const math = std.math;
3const debug = std.debug;
4const assert = debug.assert;
5const testing = std.testing;
3const assert = std.debug.assert;
64const mem = std.mem;
75const builtin = @import("builtin");
86const errol = @import("fmt/errol.zig");
......@@ -36,7 +34,7 @@ fn nextArg(comptime used_pos_args: *u32, comptime maybe_pos_arg: ?comptime_int,
3634
3735fn peekIsAlign(comptime fmt: []const u8) bool {
3836 // Should only be called during a state transition to the format segment.
39 std.debug.assert(fmt[0] == ':');
37 comptime assert(fmt[0] == ':');
4038
4139 inline for (([_]u8{ 1, 2 })[0..]) |i| {
4240 if (fmt.len > i and (fmt[i] == '<' or fmt[i] == '^' or fmt[i] == '>')) {
......@@ -1009,13 +1007,13 @@ pub fn parseInt(comptime T: type, buf: []const u8, radix: u8) !T {
10091007}
10101008
10111009test "parseInt" {
1012 testing.expect((parseInt(i32, "-10", 10) catch unreachable) == -10);
1013 testing.expect((parseInt(i32, "+10", 10) catch unreachable) == 10);
1014 testing.expect(if (parseInt(i32, " 10", 10)) |_| false else |err| err == error.InvalidCharacter);
1015 testing.expect(if (parseInt(i32, "10 ", 10)) |_| false else |err| err == error.InvalidCharacter);
1016 testing.expect(if (parseInt(u32, "-10", 10)) |_| false else |err| err == error.InvalidCharacter);
1017 testing.expect((parseInt(u8, "255", 10) catch unreachable) == 255);
1018 testing.expect(if (parseInt(u8, "256", 10)) |_| false else |err| err == error.Overflow);
1010 std.testing.expect((parseInt(i32, "-10", 10) catch unreachable) == -10);
1011 std.testing.expect((parseInt(i32, "+10", 10) catch unreachable) == 10);
1012 std.testing.expect(if (parseInt(i32, " 10", 10)) |_| false else |err| err == error.InvalidCharacter);
1013 std.testing.expect(if (parseInt(i32, "10 ", 10)) |_| false else |err| err == error.InvalidCharacter);
1014 std.testing.expect(if (parseInt(u32, "-10", 10)) |_| false else |err| err == error.InvalidCharacter);
1015 std.testing.expect((parseInt(u8, "255", 10) catch unreachable) == 255);
1016 std.testing.expect(if (parseInt(u8, "256", 10)) |_| false else |err| err == error.Overflow);
10191017}
10201018
10211019const ParseUnsignedError = error{
......@@ -1040,30 +1038,30 @@ pub fn parseUnsigned(comptime T: type, buf: []const u8, radix: u8) ParseUnsigned
10401038}
10411039
10421040test "parseUnsigned" {
1043 testing.expect((try parseUnsigned(u16, "050124", 10)) == 50124);
1044 testing.expect((try parseUnsigned(u16, "65535", 10)) == 65535);
1045 testing.expectError(error.Overflow, parseUnsigned(u16, "65536", 10));
1041 std.testing.expect((try parseUnsigned(u16, "050124", 10)) == 50124);
1042 std.testing.expect((try parseUnsigned(u16, "65535", 10)) == 65535);
1043 std.testing.expectError(error.Overflow, parseUnsigned(u16, "65536", 10));
10461044
1047 testing.expect((try parseUnsigned(u64, "0ffffffffffffffff", 16)) == 0xffffffffffffffff);
1048 testing.expectError(error.Overflow, parseUnsigned(u64, "10000000000000000", 16));
1045 std.testing.expect((try parseUnsigned(u64, "0ffffffffffffffff", 16)) == 0xffffffffffffffff);
1046 std.testing.expectError(error.Overflow, parseUnsigned(u64, "10000000000000000", 16));
10491047
1050 testing.expect((try parseUnsigned(u32, "DeadBeef", 16)) == 0xDEADBEEF);
1048 std.testing.expect((try parseUnsigned(u32, "DeadBeef", 16)) == 0xDEADBEEF);
10511049
1052 testing.expect((try parseUnsigned(u7, "1", 10)) == 1);
1053 testing.expect((try parseUnsigned(u7, "1000", 2)) == 8);
1050 std.testing.expect((try parseUnsigned(u7, "1", 10)) == 1);
1051 std.testing.expect((try parseUnsigned(u7, "1000", 2)) == 8);
10541052
1055 testing.expectError(error.InvalidCharacter, parseUnsigned(u32, "f", 10));
1056 testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "109", 8));
1053 std.testing.expectError(error.InvalidCharacter, parseUnsigned(u32, "f", 10));
1054 std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "109", 8));
10571055
1058 testing.expect((try parseUnsigned(u32, "NUMBER", 36)) == 1442151747);
1056 std.testing.expect((try parseUnsigned(u32, "NUMBER", 36)) == 1442151747);
10591057
10601058 // these numbers should fit even though the radix itself doesn't fit in the destination type
1061 testing.expect((try parseUnsigned(u1, "0", 10)) == 0);
1062 testing.expect((try parseUnsigned(u1, "1", 10)) == 1);
1063 testing.expectError(error.Overflow, parseUnsigned(u1, "2", 10));
1064 testing.expect((try parseUnsigned(u1, "001", 16)) == 1);
1065 testing.expect((try parseUnsigned(u2, "3", 16)) == 3);
1066 testing.expectError(error.Overflow, parseUnsigned(u2, "4", 16));
1059 std.testing.expect((try parseUnsigned(u1, "0", 10)) == 0);
1060 std.testing.expect((try parseUnsigned(u1, "1", 10)) == 1);
1061 std.testing.expectError(error.Overflow, parseUnsigned(u1, "2", 10));
1062 std.testing.expect((try parseUnsigned(u1, "001", 16)) == 1);
1063 std.testing.expect((try parseUnsigned(u2, "3", 16)) == 3);
1064 std.testing.expectError(error.Overflow, parseUnsigned(u2, "4", 16));
10671065}
10681066
10691067pub const parseFloat = @import("fmt/parse_float.zig").parseFloat;
......@@ -1134,19 +1132,19 @@ fn countSize(size: *usize, bytes: []const u8) (error{}!void) {
11341132test "bufPrintInt" {
11351133 var buffer: [100]u8 = undefined;
11361134 const buf = buffer[0..];
1137 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, -12345678), 2, false, FormatOptions{}), "-101111000110000101001110"));
1138 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, -12345678), 10, false, FormatOptions{}), "-12345678"));
1139 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, -12345678), 16, false, FormatOptions{}), "-bc614e"));
1140 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, -12345678), 16, true, FormatOptions{}), "-BC614E"));
1135 std.testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, -12345678), 2, false, FormatOptions{}), "-101111000110000101001110"));
1136 std.testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, -12345678), 10, false, FormatOptions{}), "-12345678"));
1137 std.testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, -12345678), 16, false, FormatOptions{}), "-bc614e"));
1138 std.testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, -12345678), 16, true, FormatOptions{}), "-BC614E"));
11411139
1142 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(u32, 12345678), 10, true, FormatOptions{}), "12345678"));
1140 std.testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(u32, 12345678), 10, true, FormatOptions{}), "12345678"));
11431141
1144 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(u32, 666), 10, false, FormatOptions{ .width = 6 }), " 666"));
1145 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(u32, 0x1234), 16, false, FormatOptions{ .width = 6 }), " 1234"));
1146 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(u32, 0x1234), 16, false, FormatOptions{ .width = 1 }), "1234"));
1142 std.testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(u32, 666), 10, false, FormatOptions{ .width = 6 }), " 666"));
1143 std.testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(u32, 0x1234), 16, false, FormatOptions{ .width = 6 }), " 1234"));
1144 std.testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(u32, 0x1234), 16, false, FormatOptions{ .width = 1 }), "1234"));
11471145
1148 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, 42), 10, false, FormatOptions{ .width = 3 }), "+42"));
1149 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, -42), 10, false, FormatOptions{ .width = 3 }), "-42"));
1146 std.testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, 42), 10, false, FormatOptions{ .width = 3 }), "+42"));
1147 std.testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, -42), 10, false, FormatOptions{ .width = 3 }), "-42"));
11501148}
11511149
11521150fn bufPrintIntToSlice(buf: []u8, value: var, base: u8, uppercase: bool, options: FormatOptions) []u8 {
......@@ -1163,7 +1161,7 @@ test "parse u64 digit too big" {
11631161
11641162test "parse unsigned comptime" {
11651163 comptime {
1166 testing.expect((try parseUnsigned(usize, "2", 10)) == 2);
1164 std.testing.expect((try parseUnsigned(usize, "2", 10)) == 2);
11671165 }
11681166}
11691167
......@@ -1218,23 +1216,23 @@ test "buffer" {
12181216 var context = BufPrintContext{ .remaining = buf1[0..] };
12191217 try formatType(1234, "", FormatOptions{}, &context, error{BufferTooSmall}, bufPrintWrite, default_max_depth);
12201218 var res = buf1[0 .. buf1.len - context.remaining.len];
1221 testing.expect(mem.eql(u8, res, "1234"));
1219 std.testing.expect(mem.eql(u8, res, "1234"));
12221220
12231221 context = BufPrintContext{ .remaining = buf1[0..] };
12241222 try formatType('a', "c", FormatOptions{}, &context, error{BufferTooSmall}, bufPrintWrite, default_max_depth);
12251223 res = buf1[0 .. buf1.len - context.remaining.len];
1226 testing.expect(mem.eql(u8, res, "a"));
1224 std.testing.expect(mem.eql(u8, res, "a"));
12271225
12281226 context = BufPrintContext{ .remaining = buf1[0..] };
12291227 try formatType(0b1100, "b", FormatOptions{}, &context, error{BufferTooSmall}, bufPrintWrite, default_max_depth);
12301228 res = buf1[0 .. buf1.len - context.remaining.len];
1231 testing.expect(mem.eql(u8, res, "1100"));
1229 std.testing.expect(mem.eql(u8, res, "1100"));
12321230 }
12331231}
12341232
12351233test "array" {
12361234 {
1237 const value: [3]u8 = "abc";
1235 const value: [3]u8 = "abc".*;
12381236 try testFmt("array: abc\n", "array: {}\n", value);
12391237 try testFmt("array: abc\n", "array: {}\n", &value);
12401238
......@@ -1278,8 +1276,8 @@ test "pointer" {
12781276}
12791277
12801278test "cstr" {
1281 try testFmt("cstr: Test C\n", "cstr: {s}\n", c"Test C");
1282 try testFmt("cstr: Test C \n", "cstr: {s:10}\n", c"Test C");
1279 try testFmt("cstr: Test C\n", "cstr: {s}\n", "Test C");
1280 try testFmt("cstr: Test C \n", "cstr: {s:10}\n", "Test C");
12831281}
12841282
12851283test "filesize" {
......@@ -1479,10 +1477,10 @@ test "union" {
14791477
14801478 var buf: [100]u8 = undefined;
14811479 const uu_result = try bufPrint(buf[0..], "{}", uu_inst);
1482 testing.expect(mem.eql(u8, uu_result[0..3], "UU@"));
1480 std.testing.expect(mem.eql(u8, uu_result[0..3], "UU@"));
14831481
14841482 const eu_result = try bufPrint(buf[0..], "{}", eu_inst);
1485 testing.expect(mem.eql(u8, uu_result[0..3], "EU@"));
1483 std.testing.expect(mem.eql(u8, uu_result[0..3], "EU@"));
14861484}
14871485
14881486test "enum" {
......@@ -1569,11 +1567,11 @@ pub fn trim(buf: []const u8) []const u8 {
15691567}
15701568
15711569test "trim" {
1572 testing.expect(mem.eql(u8, "abc", trim("\n abc \t")));
1573 testing.expect(mem.eql(u8, "", trim(" ")));
1574 testing.expect(mem.eql(u8, "", trim("")));
1575 testing.expect(mem.eql(u8, "abc", trim(" abc")));
1576 testing.expect(mem.eql(u8, "abc", trim("abc ")));
1570 std.testing.expect(mem.eql(u8, "abc", trim("\n abc \t")));
1571 std.testing.expect(mem.eql(u8, "", trim(" ")));
1572 std.testing.expect(mem.eql(u8, "", trim("")));
1573 std.testing.expect(mem.eql(u8, "abc", trim(" abc")));
1574 std.testing.expect(mem.eql(u8, "abc", trim("abc ")));
15771575}
15781576
15791577pub fn isWhiteSpace(byte: u8) bool {
......@@ -1607,7 +1605,7 @@ test "formatIntValue with comptime_int" {
16071605
16081606 var buf = try std.Buffer.init(std.debug.global_allocator, "");
16091607 try formatIntValue(value, "", FormatOptions{}, &buf, @typeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append);
1610 assert(mem.eql(u8, buf.toSlice(), "123456789123456789"));
1608 std.testing.expect(mem.eql(u8, buf.toSlice(), "123456789123456789"));
16111609}
16121610
16131611test "formatType max_depth" {
......@@ -1661,19 +1659,19 @@ test "formatType max_depth" {
16611659
16621660 var buf0 = try std.Buffer.init(std.debug.global_allocator, "");
16631661 try formatType(inst, "", FormatOptions{}, &buf0, @typeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append, 0);
1664 assert(mem.eql(u8, buf0.toSlice(), "S{ ... }"));
1662 std.testing.expect(mem.eql(u8, buf0.toSlice(), "S{ ... }"));
16651663
16661664 var buf1 = try std.Buffer.init(std.debug.global_allocator, "");
16671665 try formatType(inst, "", FormatOptions{}, &buf1, @typeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append, 1);
1668 assert(mem.eql(u8, buf1.toSlice(), "S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }"));
1666 std.testing.expect(mem.eql(u8, buf1.toSlice(), "S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }"));
16691667
16701668 var buf2 = try std.Buffer.init(std.debug.global_allocator, "");
16711669 try formatType(inst, "", FormatOptions{}, &buf2, @typeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append, 2);
1672 assert(mem.eql(u8, buf2.toSlice(), "S{ .a = S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ ... } }, .e = E.Two, .vec = (10.200,2.220) }"));
1670 std.testing.expect(mem.eql(u8, buf2.toSlice(), "S{ .a = S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ ... } }, .e = E.Two, .vec = (10.200,2.220) }"));
16731671
16741672 var buf3 = try std.Buffer.init(std.debug.global_allocator, "");
16751673 try formatType(inst, "", FormatOptions{}, &buf3, @typeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append, 3);
1676 assert(mem.eql(u8, buf3.toSlice(), "S{ .a = S{ .a = S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ ... } }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ .ptr = TU{ ... } } }, .e = E.Two, .vec = (10.200,2.220) }"));
1674 std.testing.expect(mem.eql(u8, buf3.toSlice(), "S{ .a = S{ .a = S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ ... } }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ .ptr = TU{ ... } } }, .e = E.Two, .vec = (10.200,2.220) }"));
16771675}
16781676
16791677test "positional" {
lib/std/fs.zig+3-3
......@@ -1240,7 +1240,7 @@ pub const OpenSelfExeError = os.OpenError || os.windows.CreateFileError || SelfE
12401240
12411241pub fn openSelfExe() OpenSelfExeError!File {
12421242 if (builtin.os == .linux) {
1243 return File.openReadC(c"/proc/self/exe");
1243 return File.openReadC("/proc/self/exe");
12441244 }
12451245 if (builtin.os == .windows) {
12461246 const wide_slice = selfExePathW();
......@@ -1280,7 +1280,7 @@ pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) SelfExePathError![]u8 {
12801280 return mem.toSlice(u8, out_buffer);
12811281 }
12821282 switch (builtin.os) {
1283 .linux => return os.readlinkC(c"/proc/self/exe", out_buffer),
1283 .linux => return os.readlinkC("/proc/self/exe", out_buffer),
12841284 .freebsd, .dragonfly => {
12851285 var mib = [4]c_int{ os.CTL_KERN, os.KERN_PROC, os.KERN_PROC_PATHNAME, -1 };
12861286 var out_len: usize = out_buffer.len;
......@@ -1326,7 +1326,7 @@ pub fn selfExeDirPath(out_buffer: *[MAX_PATH_BYTES]u8) SelfExePathError![]const
13261326 // the file path looks something like `/a/b/c/exe (deleted)`
13271327 // This path cannot be opened, but it's valid for determining the directory
13281328 // the executable was in when it was run.
1329 const full_exe_path = try os.readlinkC(c"/proc/self/exe", out_buffer);
1329 const full_exe_path = try os.readlinkC("/proc/self/exe", out_buffer);
13301330 // Assume that /proc/self/exe has an absolute path, and therefore dirname
13311331 // will not return null.
13321332 return path.dirname(full_exe_path).?;
lib/std/fs/file.zig+1-1
......@@ -172,7 +172,7 @@ pub const File = struct {
172172 if (self.isTty()) {
173173 if (self.handle == os.STDOUT_FILENO or self.handle == os.STDERR_FILENO) {
174174 // Use getenvC to workaround https://github.com/ziglang/zig/issues/3511
175 if (os.getenvC(c"TERM")) |term| {
175 if (os.getenvC("TERM")) |term| {
176176 if (std.mem.eql(u8, term, "dumb"))
177177 return false;
178178 }
lib/std/fs/path.zig+1-1
......@@ -394,7 +394,7 @@ pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {
394394 }
395395
396396 // determine which disk designator we will result with, if any
397 var result_drive_buf = "_:";
397 var result_drive_buf = "_:".*;
398398 var result_disk_designator: []const u8 = "";
399399 var have_drive_kind = WindowsPath.Kind.None;
400400 var have_abs_path = false;
lib/std/hash/siphash.zig+128-128
......@@ -202,70 +202,70 @@ const test_key = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x
202202
203203test "siphash64-2-4 sanity" {
204204 const vectors = [_][8]u8{
205 "\x31\x0e\x0e\xdd\x47\xdb\x6f\x72", // ""
206 "\xfd\x67\xdc\x93\xc5\x39\xf8\x74", // "\x00"
207 "\x5a\x4f\xa9\xd9\x09\x80\x6c\x0d", // "\x00\x01" ... etc
208 "\x2d\x7e\xfb\xd7\x96\x66\x67\x85",
209 "\xb7\x87\x71\x27\xe0\x94\x27\xcf",
210 "\x8d\xa6\x99\xcd\x64\x55\x76\x18",
211 "\xce\xe3\xfe\x58\x6e\x46\xc9\xcb",
212 "\x37\xd1\x01\x8b\xf5\x00\x02\xab",
213 "\x62\x24\x93\x9a\x79\xf5\xf5\x93",
214 "\xb0\xe4\xa9\x0b\xdf\x82\x00\x9e",
215 "\xf3\xb9\xdd\x94\xc5\xbb\x5d\x7a",
216 "\xa7\xad\x6b\x22\x46\x2f\xb3\xf4",
217 "\xfb\xe5\x0e\x86\xbc\x8f\x1e\x75",
218 "\x90\x3d\x84\xc0\x27\x56\xea\x14",
219 "\xee\xf2\x7a\x8e\x90\xca\x23\xf7",
220 "\xe5\x45\xbe\x49\x61\xca\x29\xa1",
221 "\xdb\x9b\xc2\x57\x7f\xcc\x2a\x3f",
222 "\x94\x47\xbe\x2c\xf5\xe9\x9a\x69",
223 "\x9c\xd3\x8d\x96\xf0\xb3\xc1\x4b",
224 "\xbd\x61\x79\xa7\x1d\xc9\x6d\xbb",
225 "\x98\xee\xa2\x1a\xf2\x5c\xd6\xbe",
226 "\xc7\x67\x3b\x2e\xb0\xcb\xf2\xd0",
227 "\x88\x3e\xa3\xe3\x95\x67\x53\x93",
228 "\xc8\xce\x5c\xcd\x8c\x03\x0c\xa8",
229 "\x94\xaf\x49\xf6\xc6\x50\xad\xb8",
230 "\xea\xb8\x85\x8a\xde\x92\xe1\xbc",
231 "\xf3\x15\xbb\x5b\xb8\x35\xd8\x17",
232 "\xad\xcf\x6b\x07\x63\x61\x2e\x2f",
233 "\xa5\xc9\x1d\xa7\xac\xaa\x4d\xde",
234 "\x71\x65\x95\x87\x66\x50\xa2\xa6",
235 "\x28\xef\x49\x5c\x53\xa3\x87\xad",
236 "\x42\xc3\x41\xd8\xfa\x92\xd8\x32",
237 "\xce\x7c\xf2\x72\x2f\x51\x27\x71",
238 "\xe3\x78\x59\xf9\x46\x23\xf3\xa7",
239 "\x38\x12\x05\xbb\x1a\xb0\xe0\x12",
240 "\xae\x97\xa1\x0f\xd4\x34\xe0\x15",
241 "\xb4\xa3\x15\x08\xbe\xff\x4d\x31",
242 "\x81\x39\x62\x29\xf0\x90\x79\x02",
243 "\x4d\x0c\xf4\x9e\xe5\xd4\xdc\xca",
244 "\x5c\x73\x33\x6a\x76\xd8\xbf\x9a",
245 "\xd0\xa7\x04\x53\x6b\xa9\x3e\x0e",
246 "\x92\x59\x58\xfc\xd6\x42\x0c\xad",
247 "\xa9\x15\xc2\x9b\xc8\x06\x73\x18",
248 "\x95\x2b\x79\xf3\xbc\x0a\xa6\xd4",
249 "\xf2\x1d\xf2\xe4\x1d\x45\x35\xf9",
250 "\x87\x57\x75\x19\x04\x8f\x53\xa9",
251 "\x10\xa5\x6c\xf5\xdf\xcd\x9a\xdb",
252 "\xeb\x75\x09\x5c\xcd\x98\x6c\xd0",
253 "\x51\xa9\xcb\x9e\xcb\xa3\x12\xe6",
254 "\x96\xaf\xad\xfc\x2c\xe6\x66\xc7",
255 "\x72\xfe\x52\x97\x5a\x43\x64\xee",
256 "\x5a\x16\x45\xb2\x76\xd5\x92\xa1",
257 "\xb2\x74\xcb\x8e\xbf\x87\x87\x0a",
258 "\x6f\x9b\xb4\x20\x3d\xe7\xb3\x81",
259 "\xea\xec\xb2\xa3\x0b\x22\xa8\x7f",
260 "\x99\x24\xa4\x3c\xc1\x31\x57\x24",
261 "\xbd\x83\x8d\x3a\xaf\xbf\x8d\xb7",
262 "\x0b\x1a\x2a\x32\x65\xd5\x1a\xea",
263 "\x13\x50\x79\xa3\x23\x1c\xe6\x60",
264 "\x93\x2b\x28\x46\xe4\xd7\x06\x66",
265 "\xe1\x91\x5f\x5c\xb1\xec\xa4\x6c",
266 "\xf3\x25\x96\x5c\xa1\x6d\x62\x9f",
267 "\x57\x5f\xf2\x8e\x60\x38\x1b\xe5",
268 "\x72\x45\x06\xeb\x4c\x32\x8a\x95",
205 "\x31\x0e\x0e\xdd\x47\xdb\x6f\x72".*, // ""
206 "\xfd\x67\xdc\x93\xc5\x39\xf8\x74".*, // "\x00"
207 "\x5a\x4f\xa9\xd9\x09\x80\x6c\x0d".*, // "\x00\x01" ... etc
208 "\x2d\x7e\xfb\xd7\x96\x66\x67\x85".*,
209 "\xb7\x87\x71\x27\xe0\x94\x27\xcf".*,
210 "\x8d\xa6\x99\xcd\x64\x55\x76\x18".*,
211 "\xce\xe3\xfe\x58\x6e\x46\xc9\xcb".*,
212 "\x37\xd1\x01\x8b\xf5\x00\x02\xab".*,
213 "\x62\x24\x93\x9a\x79\xf5\xf5\x93".*,
214 "\xb0\xe4\xa9\x0b\xdf\x82\x00\x9e".*,
215 "\xf3\xb9\xdd\x94\xc5\xbb\x5d\x7a".*,
216 "\xa7\xad\x6b\x22\x46\x2f\xb3\xf4".*,
217 "\xfb\xe5\x0e\x86\xbc\x8f\x1e\x75".*,
218 "\x90\x3d\x84\xc0\x27\x56\xea\x14".*,
219 "\xee\xf2\x7a\x8e\x90\xca\x23\xf7".*,
220 "\xe5\x45\xbe\x49\x61\xca\x29\xa1".*,
221 "\xdb\x9b\xc2\x57\x7f\xcc\x2a\x3f".*,
222 "\x94\x47\xbe\x2c\xf5\xe9\x9a\x69".*,
223 "\x9c\xd3\x8d\x96\xf0\xb3\xc1\x4b".*,
224 "\xbd\x61\x79\xa7\x1d\xc9\x6d\xbb".*,
225 "\x98\xee\xa2\x1a\xf2\x5c\xd6\xbe".*,
226 "\xc7\x67\x3b\x2e\xb0\xcb\xf2\xd0".*,
227 "\x88\x3e\xa3\xe3\x95\x67\x53\x93".*,
228 "\xc8\xce\x5c\xcd\x8c\x03\x0c\xa8".*,
229 "\x94\xaf\x49\xf6\xc6\x50\xad\xb8".*,
230 "\xea\xb8\x85\x8a\xde\x92\xe1\xbc".*,
231 "\xf3\x15\xbb\x5b\xb8\x35\xd8\x17".*,
232 "\xad\xcf\x6b\x07\x63\x61\x2e\x2f".*,
233 "\xa5\xc9\x1d\xa7\xac\xaa\x4d\xde".*,
234 "\x71\x65\x95\x87\x66\x50\xa2\xa6".*,
235 "\x28\xef\x49\x5c\x53\xa3\x87\xad".*,
236 "\x42\xc3\x41\xd8\xfa\x92\xd8\x32".*,
237 "\xce\x7c\xf2\x72\x2f\x51\x27\x71".*,
238 "\xe3\x78\x59\xf9\x46\x23\xf3\xa7".*,
239 "\x38\x12\x05\xbb\x1a\xb0\xe0\x12".*,
240 "\xae\x97\xa1\x0f\xd4\x34\xe0\x15".*,
241 "\xb4\xa3\x15\x08\xbe\xff\x4d\x31".*,
242 "\x81\x39\x62\x29\xf0\x90\x79\x02".*,
243 "\x4d\x0c\xf4\x9e\xe5\xd4\xdc\xca".*,
244 "\x5c\x73\x33\x6a\x76\xd8\xbf\x9a".*,
245 "\xd0\xa7\x04\x53\x6b\xa9\x3e\x0e".*,
246 "\x92\x59\x58\xfc\xd6\x42\x0c\xad".*,
247 "\xa9\x15\xc2\x9b\xc8\x06\x73\x18".*,
248 "\x95\x2b\x79\xf3\xbc\x0a\xa6\xd4".*,
249 "\xf2\x1d\xf2\xe4\x1d\x45\x35\xf9".*,
250 "\x87\x57\x75\x19\x04\x8f\x53\xa9".*,
251 "\x10\xa5\x6c\xf5\xdf\xcd\x9a\xdb".*,
252 "\xeb\x75\x09\x5c\xcd\x98\x6c\xd0".*,
253 "\x51\xa9\xcb\x9e\xcb\xa3\x12\xe6".*,
254 "\x96\xaf\xad\xfc\x2c\xe6\x66\xc7".*,
255 "\x72\xfe\x52\x97\x5a\x43\x64\xee".*,
256 "\x5a\x16\x45\xb2\x76\xd5\x92\xa1".*,
257 "\xb2\x74\xcb\x8e\xbf\x87\x87\x0a".*,
258 "\x6f\x9b\xb4\x20\x3d\xe7\xb3\x81".*,
259 "\xea\xec\xb2\xa3\x0b\x22\xa8\x7f".*,
260 "\x99\x24\xa4\x3c\xc1\x31\x57\x24".*,
261 "\xbd\x83\x8d\x3a\xaf\xbf\x8d\xb7".*,
262 "\x0b\x1a\x2a\x32\x65\xd5\x1a\xea".*,
263 "\x13\x50\x79\xa3\x23\x1c\xe6\x60".*,
264 "\x93\x2b\x28\x46\xe4\xd7\x06\x66".*,
265 "\xe1\x91\x5f\x5c\xb1\xec\xa4\x6c".*,
266 "\xf3\x25\x96\x5c\xa1\x6d\x62\x9f".*,
267 "\x57\x5f\xf2\x8e\x60\x38\x1b\xe5".*,
268 "\x72\x45\x06\xeb\x4c\x32\x8a\x95".*,
269269 };
270270
271271 const siphash = SipHash64(2, 4);
......@@ -281,70 +281,70 @@ test "siphash64-2-4 sanity" {
281281
282282test "siphash128-2-4 sanity" {
283283 const vectors = [_][16]u8{
284 "\xa3\x81\x7f\x04\xba\x25\xa8\xe6\x6d\xf6\x72\x14\xc7\x55\x02\x93",
285 "\xda\x87\xc1\xd8\x6b\x99\xaf\x44\x34\x76\x59\x11\x9b\x22\xfc\x45",
286 "\x81\x77\x22\x8d\xa4\xa4\x5d\xc7\xfc\xa3\x8b\xde\xf6\x0a\xff\xe4",
287 "\x9c\x70\xb6\x0c\x52\x67\xa9\x4e\x5f\x33\xb6\xb0\x29\x85\xed\x51",
288 "\xf8\x81\x64\xc1\x2d\x9c\x8f\xaf\x7d\x0f\x6e\x7c\x7b\xcd\x55\x79",
289 "\x13\x68\x87\x59\x80\x77\x6f\x88\x54\x52\x7a\x07\x69\x0e\x96\x27",
290 "\x14\xee\xca\x33\x8b\x20\x86\x13\x48\x5e\xa0\x30\x8f\xd7\xa1\x5e",
291 "\xa1\xf1\xeb\xbe\xd8\xdb\xc1\x53\xc0\xb8\x4a\xa6\x1f\xf0\x82\x39",
292 "\x3b\x62\xa9\xba\x62\x58\xf5\x61\x0f\x83\xe2\x64\xf3\x14\x97\xb4",
293 "\x26\x44\x99\x06\x0a\xd9\xba\xab\xc4\x7f\x8b\x02\xbb\x6d\x71\xed",
294 "\x00\x11\x0d\xc3\x78\x14\x69\x56\xc9\x54\x47\xd3\xf3\xd0\xfb\xba",
295 "\x01\x51\xc5\x68\x38\x6b\x66\x77\xa2\xb4\xdc\x6f\x81\xe5\xdc\x18",
296 "\xd6\x26\xb2\x66\x90\x5e\xf3\x58\x82\x63\x4d\xf6\x85\x32\xc1\x25",
297 "\x98\x69\xe2\x47\xe9\xc0\x8b\x10\xd0\x29\x93\x4f\xc4\xb9\x52\xf7",
298 "\x31\xfc\xef\xac\x66\xd7\xde\x9c\x7e\xc7\x48\x5f\xe4\x49\x49\x02",
299 "\x54\x93\xe9\x99\x33\xb0\xa8\x11\x7e\x08\xec\x0f\x97\xcf\xc3\xd9",
300 "\x6e\xe2\xa4\xca\x67\xb0\x54\xbb\xfd\x33\x15\xbf\x85\x23\x05\x77",
301 "\x47\x3d\x06\xe8\x73\x8d\xb8\x98\x54\xc0\x66\xc4\x7a\xe4\x77\x40",
302 "\xa4\x26\xe5\xe4\x23\xbf\x48\x85\x29\x4d\xa4\x81\xfe\xae\xf7\x23",
303 "\x78\x01\x77\x31\xcf\x65\xfa\xb0\x74\xd5\x20\x89\x52\x51\x2e\xb1",
304 "\x9e\x25\xfc\x83\x3f\x22\x90\x73\x3e\x93\x44\xa5\xe8\x38\x39\xeb",
305 "\x56\x8e\x49\x5a\xbe\x52\x5a\x21\x8a\x22\x14\xcd\x3e\x07\x1d\x12",
306 "\x4a\x29\xb5\x45\x52\xd1\x6b\x9a\x46\x9c\x10\x52\x8e\xff\x0a\xae",
307 "\xc9\xd1\x84\xdd\xd5\xa9\xf5\xe0\xcf\x8c\xe2\x9a\x9a\xbf\x69\x1c",
308 "\x2d\xb4\x79\xae\x78\xbd\x50\xd8\x88\x2a\x8a\x17\x8a\x61\x32\xad",
309 "\x8e\xce\x5f\x04\x2d\x5e\x44\x7b\x50\x51\xb9\xea\xcb\x8d\x8f\x6f",
310 "\x9c\x0b\x53\xb4\xb3\xc3\x07\xe8\x7e\xae\xe0\x86\x78\x14\x1f\x66",
311 "\xab\xf2\x48\xaf\x69\xa6\xea\xe4\xbf\xd3\xeb\x2f\x12\x9e\xeb\x94",
312 "\x06\x64\xda\x16\x68\x57\x4b\x88\xb9\x35\xf3\x02\x73\x58\xae\xf4",
313 "\xaa\x4b\x9d\xc4\xbf\x33\x7d\xe9\x0c\xd4\xfd\x3c\x46\x7c\x6a\xb7",
314 "\xea\x5c\x7f\x47\x1f\xaf\x6b\xde\x2b\x1a\xd7\xd4\x68\x6d\x22\x87",
315 "\x29\x39\xb0\x18\x32\x23\xfa\xfc\x17\x23\xde\x4f\x52\xc4\x3d\x35",
316 "\x7c\x39\x56\xca\x5e\xea\xfc\x3e\x36\x3e\x9d\x55\x65\x46\xeb\x68",
317 "\x77\xc6\x07\x71\x46\xf0\x1c\x32\xb6\xb6\x9d\x5f\x4e\xa9\xff\xcf",
318 "\x37\xa6\x98\x6c\xb8\x84\x7e\xdf\x09\x25\xf0\xf1\x30\x9b\x54\xde",
319 "\xa7\x05\xf0\xe6\x9d\xa9\xa8\xf9\x07\x24\x1a\x2e\x92\x3c\x8c\xc8",
320 "\x3d\xc4\x7d\x1f\x29\xc4\x48\x46\x1e\x9e\x76\xed\x90\x4f\x67\x11",
321 "\x0d\x62\xbf\x01\xe6\xfc\x0e\x1a\x0d\x3c\x47\x51\xc5\xd3\x69\x2b",
322 "\x8c\x03\x46\x8b\xca\x7c\x66\x9e\xe4\xfd\x5e\x08\x4b\xbe\xe7\xb5",
323 "\x52\x8a\x5b\xb9\x3b\xaf\x2c\x9c\x44\x73\xcc\xe5\xd0\xd2\x2b\xd9",
324 "\xdf\x6a\x30\x1e\x95\xc9\x5d\xad\x97\xae\x0c\xc8\xc6\x91\x3b\xd8",
325 "\x80\x11\x89\x90\x2c\x85\x7f\x39\xe7\x35\x91\x28\x5e\x70\xb6\xdb",
326 "\xe6\x17\x34\x6a\xc9\xc2\x31\xbb\x36\x50\xae\x34\xcc\xca\x0c\x5b",
327 "\x27\xd9\x34\x37\xef\xb7\x21\xaa\x40\x18\x21\xdc\xec\x5a\xdf\x89",
328 "\x89\x23\x7d\x9d\xed\x9c\x5e\x78\xd8\xb1\xc9\xb1\x66\xcc\x73\x42",
329 "\x4a\x6d\x80\x91\xbf\x5e\x7d\x65\x11\x89\xfa\x94\xa2\x50\xb1\x4c",
330 "\x0e\x33\xf9\x60\x55\xe7\xae\x89\x3f\xfc\x0e\x3d\xcf\x49\x29\x02",
331 "\xe6\x1c\x43\x2b\x72\x0b\x19\xd1\x8e\xc8\xd8\x4b\xdc\x63\x15\x1b",
332 "\xf7\xe5\xae\xf5\x49\xf7\x82\xcf\x37\x90\x55\xa6\x08\x26\x9b\x16",
333 "\x43\x8d\x03\x0f\xd0\xb7\xa5\x4f\xa8\x37\xf2\xad\x20\x1a\x64\x03",
334 "\xa5\x90\xd3\xee\x4f\xbf\x04\xe3\x24\x7e\x0d\x27\xf2\x86\x42\x3f",
335 "\x5f\xe2\xc1\xa1\x72\xfe\x93\xc4\xb1\x5c\xd3\x7c\xae\xf9\xf5\x38",
336 "\x2c\x97\x32\x5c\xbd\x06\xb3\x6e\xb2\x13\x3d\xd0\x8b\x3a\x01\x7c",
337 "\x92\xc8\x14\x22\x7a\x6b\xca\x94\x9f\xf0\x65\x9f\x00\x2a\xd3\x9e",
338 "\xdc\xe8\x50\x11\x0b\xd8\x32\x8c\xfb\xd5\x08\x41\xd6\x91\x1d\x87",
339 "\x67\xf1\x49\x84\xc7\xda\x79\x12\x48\xe3\x2b\xb5\x92\x25\x83\xda",
340 "\x19\x38\xf2\xcf\x72\xd5\x4e\xe9\x7e\x94\x16\x6f\xa9\x1d\x2a\x36",
341 "\x74\x48\x1e\x96\x46\xed\x49\xfe\x0f\x62\x24\x30\x16\x04\x69\x8e",
342 "\x57\xfc\xa5\xde\x98\xa9\xd6\xd8\x00\x64\x38\xd0\x58\x3d\x8a\x1d",
343 "\x9f\xec\xde\x1c\xef\xdc\x1c\xbe\xd4\x76\x36\x74\xd9\x57\x53\x59",
344 "\xe3\x04\x0c\x00\xeb\x28\xf1\x53\x66\xca\x73\xcb\xd8\x72\xe7\x40",
345 "\x76\x97\x00\x9a\x6a\x83\x1d\xfe\xcc\xa9\x1c\x59\x93\x67\x0f\x7a",
346 "\x58\x53\x54\x23\x21\xf5\x67\xa0\x05\xd5\x47\xa4\xf0\x47\x59\xbd",
347 "\x51\x50\xd1\x77\x2f\x50\x83\x4a\x50\x3e\x06\x9a\x97\x3f\xbd\x7c",
284 "\xa3\x81\x7f\x04\xba\x25\xa8\xe6\x6d\xf6\x72\x14\xc7\x55\x02\x93".*,
285 "\xda\x87\xc1\xd8\x6b\x99\xaf\x44\x34\x76\x59\x11\x9b\x22\xfc\x45".*,
286 "\x81\x77\x22\x8d\xa4\xa4\x5d\xc7\xfc\xa3\x8b\xde\xf6\x0a\xff\xe4".*,
287 "\x9c\x70\xb6\x0c\x52\x67\xa9\x4e\x5f\x33\xb6\xb0\x29\x85\xed\x51".*,
288 "\xf8\x81\x64\xc1\x2d\x9c\x8f\xaf\x7d\x0f\x6e\x7c\x7b\xcd\x55\x79".*,
289 "\x13\x68\x87\x59\x80\x77\x6f\x88\x54\x52\x7a\x07\x69\x0e\x96\x27".*,
290 "\x14\xee\xca\x33\x8b\x20\x86\x13\x48\x5e\xa0\x30\x8f\xd7\xa1\x5e".*,
291 "\xa1\xf1\xeb\xbe\xd8\xdb\xc1\x53\xc0\xb8\x4a\xa6\x1f\xf0\x82\x39".*,
292 "\x3b\x62\xa9\xba\x62\x58\xf5\x61\x0f\x83\xe2\x64\xf3\x14\x97\xb4".*,
293 "\x26\x44\x99\x06\x0a\xd9\xba\xab\xc4\x7f\x8b\x02\xbb\x6d\x71\xed".*,
294 "\x00\x11\x0d\xc3\x78\x14\x69\x56\xc9\x54\x47\xd3\xf3\xd0\xfb\xba".*,
295 "\x01\x51\xc5\x68\x38\x6b\x66\x77\xa2\xb4\xdc\x6f\x81\xe5\xdc\x18".*,
296 "\xd6\x26\xb2\x66\x90\x5e\xf3\x58\x82\x63\x4d\xf6\x85\x32\xc1\x25".*,
297 "\x98\x69\xe2\x47\xe9\xc0\x8b\x10\xd0\x29\x93\x4f\xc4\xb9\x52\xf7".*,
298 "\x31\xfc\xef\xac\x66\xd7\xde\x9c\x7e\xc7\x48\x5f\xe4\x49\x49\x02".*,
299 "\x54\x93\xe9\x99\x33\xb0\xa8\x11\x7e\x08\xec\x0f\x97\xcf\xc3\xd9".*,
300 "\x6e\xe2\xa4\xca\x67\xb0\x54\xbb\xfd\x33\x15\xbf\x85\x23\x05\x77".*,
301 "\x47\x3d\x06\xe8\x73\x8d\xb8\x98\x54\xc0\x66\xc4\x7a\xe4\x77\x40".*,
302 "\xa4\x26\xe5\xe4\x23\xbf\x48\x85\x29\x4d\xa4\x81\xfe\xae\xf7\x23".*,
303 "\x78\x01\x77\x31\xcf\x65\xfa\xb0\x74\xd5\x20\x89\x52\x51\x2e\xb1".*,
304 "\x9e\x25\xfc\x83\x3f\x22\x90\x73\x3e\x93\x44\xa5\xe8\x38\x39\xeb".*,
305 "\x56\x8e\x49\x5a\xbe\x52\x5a\x21\x8a\x22\x14\xcd\x3e\x07\x1d\x12".*,
306 "\x4a\x29\xb5\x45\x52\xd1\x6b\x9a\x46\x9c\x10\x52\x8e\xff\x0a\xae".*,
307 "\xc9\xd1\x84\xdd\xd5\xa9\xf5\xe0\xcf\x8c\xe2\x9a\x9a\xbf\x69\x1c".*,
308 "\x2d\xb4\x79\xae\x78\xbd\x50\xd8\x88\x2a\x8a\x17\x8a\x61\x32\xad".*,
309 "\x8e\xce\x5f\x04\x2d\x5e\x44\x7b\x50\x51\xb9\xea\xcb\x8d\x8f\x6f".*,
310 "\x9c\x0b\x53\xb4\xb3\xc3\x07\xe8\x7e\xae\xe0\x86\x78\x14\x1f\x66".*,
311 "\xab\xf2\x48\xaf\x69\xa6\xea\xe4\xbf\xd3\xeb\x2f\x12\x9e\xeb\x94".*,
312 "\x06\x64\xda\x16\x68\x57\x4b\x88\xb9\x35\xf3\x02\x73\x58\xae\xf4".*,
313 "\xaa\x4b\x9d\xc4\xbf\x33\x7d\xe9\x0c\xd4\xfd\x3c\x46\x7c\x6a\xb7".*,
314 "\xea\x5c\x7f\x47\x1f\xaf\x6b\xde\x2b\x1a\xd7\xd4\x68\x6d\x22\x87".*,
315 "\x29\x39\xb0\x18\x32\x23\xfa\xfc\x17\x23\xde\x4f\x52\xc4\x3d\x35".*,
316 "\x7c\x39\x56\xca\x5e\xea\xfc\x3e\x36\x3e\x9d\x55\x65\x46\xeb\x68".*,
317 "\x77\xc6\x07\x71\x46\xf0\x1c\x32\xb6\xb6\x9d\x5f\x4e\xa9\xff\xcf".*,
318 "\x37\xa6\x98\x6c\xb8\x84\x7e\xdf\x09\x25\xf0\xf1\x30\x9b\x54\xde".*,
319 "\xa7\x05\xf0\xe6\x9d\xa9\xa8\xf9\x07\x24\x1a\x2e\x92\x3c\x8c\xc8".*,
320 "\x3d\xc4\x7d\x1f\x29\xc4\x48\x46\x1e\x9e\x76\xed\x90\x4f\x67\x11".*,
321 "\x0d\x62\xbf\x01\xe6\xfc\x0e\x1a\x0d\x3c\x47\x51\xc5\xd3\x69\x2b".*,
322 "\x8c\x03\x46\x8b\xca\x7c\x66\x9e\xe4\xfd\x5e\x08\x4b\xbe\xe7\xb5".*,
323 "\x52\x8a\x5b\xb9\x3b\xaf\x2c\x9c\x44\x73\xcc\xe5\xd0\xd2\x2b\xd9".*,
324 "\xdf\x6a\x30\x1e\x95\xc9\x5d\xad\x97\xae\x0c\xc8\xc6\x91\x3b\xd8".*,
325 "\x80\x11\x89\x90\x2c\x85\x7f\x39\xe7\x35\x91\x28\x5e\x70\xb6\xdb".*,
326 "\xe6\x17\x34\x6a\xc9\xc2\x31\xbb\x36\x50\xae\x34\xcc\xca\x0c\x5b".*,
327 "\x27\xd9\x34\x37\xef\xb7\x21\xaa\x40\x18\x21\xdc\xec\x5a\xdf\x89".*,
328 "\x89\x23\x7d\x9d\xed\x9c\x5e\x78\xd8\xb1\xc9\xb1\x66\xcc\x73\x42".*,
329 "\x4a\x6d\x80\x91\xbf\x5e\x7d\x65\x11\x89\xfa\x94\xa2\x50\xb1\x4c".*,
330 "\x0e\x33\xf9\x60\x55\xe7\xae\x89\x3f\xfc\x0e\x3d\xcf\x49\x29\x02".*,
331 "\xe6\x1c\x43\x2b\x72\x0b\x19\xd1\x8e\xc8\xd8\x4b\xdc\x63\x15\x1b".*,
332 "\xf7\xe5\xae\xf5\x49\xf7\x82\xcf\x37\x90\x55\xa6\x08\x26\x9b\x16".*,
333 "\x43\x8d\x03\x0f\xd0\xb7\xa5\x4f\xa8\x37\xf2\xad\x20\x1a\x64\x03".*,
334 "\xa5\x90\xd3\xee\x4f\xbf\x04\xe3\x24\x7e\x0d\x27\xf2\x86\x42\x3f".*,
335 "\x5f\xe2\xc1\xa1\x72\xfe\x93\xc4\xb1\x5c\xd3\x7c\xae\xf9\xf5\x38".*,
336 "\x2c\x97\x32\x5c\xbd\x06\xb3\x6e\xb2\x13\x3d\xd0\x8b\x3a\x01\x7c".*,
337 "\x92\xc8\x14\x22\x7a\x6b\xca\x94\x9f\xf0\x65\x9f\x00\x2a\xd3\x9e".*,
338 "\xdc\xe8\x50\x11\x0b\xd8\x32\x8c\xfb\xd5\x08\x41\xd6\x91\x1d\x87".*,
339 "\x67\xf1\x49\x84\xc7\xda\x79\x12\x48\xe3\x2b\xb5\x92\x25\x83\xda".*,
340 "\x19\x38\xf2\xcf\x72\xd5\x4e\xe9\x7e\x94\x16\x6f\xa9\x1d\x2a\x36".*,
341 "\x74\x48\x1e\x96\x46\xed\x49\xfe\x0f\x62\x24\x30\x16\x04\x69\x8e".*,
342 "\x57\xfc\xa5\xde\x98\xa9\xd6\xd8\x00\x64\x38\xd0\x58\x3d\x8a\x1d".*,
343 "\x9f\xec\xde\x1c\xef\xdc\x1c\xbe\xd4\x76\x36\x74\xd9\x57\x53\x59".*,
344 "\xe3\x04\x0c\x00\xeb\x28\xf1\x53\x66\xca\x73\xcb\xd8\x72\xe7\x40".*,
345 "\x76\x97\x00\x9a\x6a\x83\x1d\xfe\xcc\xa9\x1c\x59\x93\x67\x0f\x7a".*,
346 "\x58\x53\x54\x23\x21\xf5\x67\xa0\x05\xd5\x47\xa4\xf0\x47\x59\xbd".*,
347 "\x51\x50\xd1\x77\x2f\x50\x83\x4a\x50\x3e\x06\x9a\x97\x3f\xbd\x7c".*,
348348 };
349349
350350 const siphash = SipHash128(2, 4);
lib/std/io/test.zig+2-2
......@@ -595,8 +595,8 @@ test "Deserializer bad data" {
595595test "c out stream" {
596596 if (!builtin.link_libc) return error.SkipZigTest;
597597
598 const filename = c"tmp_io_test_file.txt";
599 const out_file = std.c.fopen(filename, c"w") orelse return error.UnableToOpenTestFile;
598 const filename = "tmp_io_test_file.txt";
599 const out_file = std.c.fopen(filename, "w") orelse return error.UnableToOpenTestFile;
600600 defer {
601601 _ = std.c.fclose(out_file);
602602 fs.deleteFileC(filename) catch {};
lib/std/mem.zig+10-8
......@@ -1408,7 +1408,9 @@ test "toBytes" {
14081408fn BytesAsValueReturnType(comptime T: type, comptime B: type) type {
14091409 const size = @as(usize, @sizeOf(T));
14101410
1411 if (comptime !trait.is(builtin.TypeId.Pointer)(B) or meta.Child(B) != [size]u8) {
1411 if (comptime !trait.is(builtin.TypeId.Pointer)(B) or
1412 (meta.Child(B) != [size]u8 and meta.Child(B) != [size]null u8))
1413 {
14121414 @compileError("expected *[N]u8 " ++ ", passed " ++ @typeName(B));
14131415 }
14141416
......@@ -1430,12 +1432,12 @@ test "bytesAsValue" {
14301432 builtin.Endian.Little => "\xEF\xBE\xAD\xDE",
14311433 };
14321434
1433 testing.expect(deadbeef == bytesAsValue(u32, &deadbeef_bytes).*);
1435 testing.expect(deadbeef == bytesAsValue(u32, deadbeef_bytes).*);
14341436
1435 var codeface_bytes = switch (builtin.endian) {
1437 var codeface_bytes: [4]u8 = switch (builtin.endian) {
14361438 builtin.Endian.Big => "\xC0\xDE\xFA\xCE",
14371439 builtin.Endian.Little => "\xCE\xFA\xDE\xC0",
1438 };
1440 }.*;
14391441 var codeface = bytesAsValue(u32, &codeface_bytes);
14401442 testing.expect(codeface.* == 0xC0DEFACE);
14411443 codeface.* = 0;
......@@ -1456,14 +1458,14 @@ test "bytesAsValue" {
14561458 .d = 0xA1,
14571459 };
14581460 const inst_bytes = "\xBE\xEF\xDE\xA1";
1459 const inst2 = bytesAsValue(S, &inst_bytes);
1461 const inst2 = bytesAsValue(S, inst_bytes);
14601462 testing.expect(meta.eql(inst, inst2.*));
14611463}
14621464
14631465///Given a pointer to an array of bytes, returns a value of the specified type backed by a
14641466/// copy of those bytes.
14651467pub fn bytesToValue(comptime T: type, bytes: var) T {
1466 return bytesAsValue(T, &bytes).*;
1468 return bytesAsValue(T, bytes).*;
14671469}
14681470test "bytesToValue" {
14691471 const deadbeef_bytes = switch (builtin.endian) {
......@@ -1491,11 +1493,11 @@ pub fn subArrayPtr(ptr: var, comptime start: usize, comptime length: usize) SubA
14911493}
14921494
14931495test "subArrayPtr" {
1494 const a1 = "abcdef";
1496 const a1: [6]u8 = "abcdef".*;
14951497 const sub1 = subArrayPtr(&a1, 2, 3);
14961498 testing.expect(eql(u8, sub1.*, "cde"));
14971499
1498 var a2 = "abcdef";
1500 var a2: [6]u8 = "abcdef".*;
14991501 var sub2 = subArrayPtr(&a2, 2, 3);
15001502
15011503 testing.expect(eql(u8, sub2, "cde"));
lib/std/meta.zig+6-7
......@@ -469,19 +469,19 @@ test "std.meta.eql" {
469469 const s_1 = S{
470470 .a = 134,
471471 .b = 123.3,
472 .c = "12345",
472 .c = "12345".*,
473473 };
474474
475475 const s_2 = S{
476476 .a = 1,
477477 .b = 123.3,
478 .c = "54321",
478 .c = "54321".*,
479479 };
480480
481481 const s_3 = S{
482482 .a = 134,
483483 .b = 123.3,
484 .c = "12345",
484 .c = "12345".*,
485485 };
486486
487487 const u_1 = U{ .f = 24 };
......@@ -494,9 +494,9 @@ test "std.meta.eql" {
494494 testing.expect(eql(u_1, u_3));
495495 testing.expect(!eql(u_1, u_2));
496496
497 var a1 = "abcdef";
498 var a2 = "abcdef";
499 var a3 = "ghijkl";
497 var a1 = "abcdef".*;
498 var a2 = "abcdef".*;
499 var a3 = "ghijkl".*;
500500
501501 testing.expect(eql(a1, a2));
502502 testing.expect(!eql(a1, a3));
......@@ -558,4 +558,3 @@ pub fn refAllDecls(comptime T: type) void {
558558 if (!builtin.is_test) return;
559559 _ = declarations(T);
560560}
561
lib/std/meta/trait.zig-2
......@@ -319,7 +319,6 @@ test "std.meta.trait.isNumber" {
319319 testing.expect(!isNumber(NotANumber));
320320}
321321
322///
323322pub fn isConstPtr(comptime T: type) bool {
324323 if (!comptime is(builtin.TypeId.Pointer)(T)) return false;
325324 const info = @typeInfo(T);
......@@ -335,7 +334,6 @@ test "std.meta.trait.isConstPtr" {
335334 testing.expect(!isConstPtr(@typeOf(6)));
336335}
337336
338///
339337pub fn isContainer(comptime T: type) bool {
340338 const info = @typeInfo(T);
341339 return switch (info) {
lib/std/net.zig+8-8
......@@ -666,35 +666,35 @@ const Policy = struct {
666666
667667const defined_policies = [_]Policy{
668668 Policy{
669 .addr = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01",
669 .addr = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01".*,
670670 .len = 15,
671671 .mask = 0xff,
672672 .prec = 50,
673673 .label = 0,
674674 },
675675 Policy{
676 .addr = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x00\x00\x00\x00",
676 .addr = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x00\x00\x00\x00".*,
677677 .len = 11,
678678 .mask = 0xff,
679679 .prec = 35,
680680 .label = 4,
681681 },
682682 Policy{
683 .addr = "\x20\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
683 .addr = "\x20\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".*,
684684 .len = 1,
685685 .mask = 0xff,
686686 .prec = 30,
687687 .label = 2,
688688 },
689689 Policy{
690 .addr = "\x20\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
690 .addr = "\x20\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".*,
691691 .len = 3,
692692 .mask = 0xff,
693693 .prec = 5,
694694 .label = 5,
695695 },
696696 Policy{
697 .addr = "\xfc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
697 .addr = "\xfc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".*,
698698 .len = 0,
699699 .mask = 0xfe,
700700 .prec = 3,
......@@ -708,7 +708,7 @@ const defined_policies = [_]Policy{
708708 // { "\x3f\xfe", 1, 0xff, 1, 12 },
709709 // Last rule must match all addresses to stop loop.
710710 Policy{
711 .addr = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
711 .addr = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".*,
712712 .len = 0,
713713 .mask = 0,
714714 .prec = 40,
......@@ -812,7 +812,7 @@ fn linuxLookupNameFromHosts(
812812 family: os.sa_family_t,
813813 port: u16,
814814) !void {
815 const file = fs.File.openReadC(c"/etc/hosts") catch |err| switch (err) {
815 const file = fs.File.openReadC("/etc/hosts") catch |err| switch (err) {
816816 error.FileNotFound,
817817 error.NotDir,
818818 error.AccessDenied,
......@@ -1006,7 +1006,7 @@ fn getResolvConf(allocator: *mem.Allocator, rc: *ResolvConf) !void {
10061006 };
10071007 errdefer rc.deinit();
10081008
1009 const file = fs.File.openReadC(c"/etc/resolv.conf") catch |err| switch (err) {
1009 const file = fs.File.openReadC("/etc/resolv.conf") catch |err| switch (err) {
10101010 error.FileNotFound,
10111011 error.NotDir,
10121012 error.AccessDenied,
lib/std/os.zig+2-2
......@@ -157,7 +157,7 @@ pub fn getrandom(buffer: []u8) GetRandomError!void {
157157}
158158
159159fn getRandomBytesDevURandom(buf: []u8) !void {
160 const fd = try openC(c"/dev/urandom", O_RDONLY | O_CLOEXEC, 0);
160 const fd = try openC("/dev/urandom", O_RDONLY | O_CLOEXEC, 0);
161161 defer close(fd);
162162
163163 const st = try fstat(fd);
......@@ -2674,7 +2674,7 @@ pub fn dl_iterate_phdr(
26742674 if (it.end()) {
26752675 var info = dl_phdr_info{
26762676 .dlpi_addr = elf_base,
2677 .dlpi_name = c"/proc/self/exe",
2677 .dlpi_name = "/proc/self/exe",
26782678 .dlpi_phdr = phdrs.ptr,
26792679 .dlpi_phnum = ehdr.e_phnum,
26802680 };
lib/std/os/linux.zig+1-1
......@@ -1053,7 +1053,7 @@ pub fn dl_iterate_phdr(comptime T: type, callback: extern fn (info: *dl_phdr_inf
10531053 if (it.end()) {
10541054 var info = dl_phdr_info{
10551055 .dlpi_addr = elf_base,
1056 .dlpi_name = c"/proc/self/exe",
1056 .dlpi_name = "/proc/self/exe",
10571057 .dlpi_phdr = @intToPtr([*]elf.Phdr, elf_base + __ehdr_start.e_phoff),
10581058 .dlpi_phnum = __ehdr_start.e_phnum,
10591059 };
lib/std/os/linux/test.zig+2-2
......@@ -56,7 +56,7 @@ test "statx" {
5656 }
5757
5858 var statx_buf: linux.Statx = undefined;
59 switch (linux.getErrno(linux.statx(file.handle, c"", linux.AT_EMPTY_PATH, linux.STATX_BASIC_STATS, &statx_buf))) {
59 switch (linux.getErrno(linux.statx(file.handle, "", linux.AT_EMPTY_PATH, linux.STATX_BASIC_STATS, &statx_buf))) {
6060 0 => {},
6161 // The statx syscall was only introduced in linux 4.11
6262 linux.ENOSYS => return error.SkipZigTest,
......@@ -64,7 +64,7 @@ test "statx" {
6464 }
6565
6666 var stat_buf: linux.Stat = undefined;
67 switch (linux.getErrno(linux.fstatat(file.handle, c"", &stat_buf, linux.AT_EMPTY_PATH))) {
67 switch (linux.getErrno(linux.fstatat(file.handle, "", &stat_buf, linux.AT_EMPTY_PATH))) {
6868 0 => {},
6969 else => unreachable,
7070 }
lib/std/process.zig+8-8
......@@ -473,14 +473,14 @@ pub fn argsFree(allocator: *mem.Allocator, args_alloc: []const []u8) void {
473473}
474474
475475test "windows arg parsing" {
476 testWindowsCmdLine(c"a b\tc d", [_][]const u8{ "a", "b", "c", "d" });
477 testWindowsCmdLine(c"\"abc\" d e", [_][]const u8{ "abc", "d", "e" });
478 testWindowsCmdLine(c"a\\\\\\b d\"e f\"g h", [_][]const u8{ "a\\\\\\b", "de fg", "h" });
479 testWindowsCmdLine(c"a\\\\\\\"b c d", [_][]const u8{ "a\\\"b", "c", "d" });
480 testWindowsCmdLine(c"a\\\\\\\\\"b c\" d e", [_][]const u8{ "a\\\\b c", "d", "e" });
481 testWindowsCmdLine(c"a b\tc \"d f", [_][]const u8{ "a", "b", "c", "\"d", "f" });
482
483 testWindowsCmdLine(c"\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\"", [_][]const u8{
476 testWindowsCmdLine("a b\tc d", [_][]const u8{ "a", "b", "c", "d" });
477 testWindowsCmdLine("\"abc\" d e", [_][]const u8{ "abc", "d", "e" });
478 testWindowsCmdLine("a\\\\\\b d\"e f\"g h", [_][]const u8{ "a\\\\\\b", "de fg", "h" });
479 testWindowsCmdLine("a\\\\\\\"b c d", [_][]const u8{ "a\\\"b", "c", "d" });
480 testWindowsCmdLine("a\\\\\\\\\"b c\" d e", [_][]const u8{ "a\\\\b c", "d", "e" });
481 testWindowsCmdLine("a b\tc \"d f", [_][]const u8{ "a", "b", "c", "\"d", "f" });
482
483 testWindowsCmdLine("\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\"", [_][]const u8{
484484 ".\\..\\zig-cache\\build",
485485 "bin\\zig.exe",
486486 ".\\..",
lib/std/special/c.zig+5-5
......@@ -66,14 +66,14 @@ extern fn strncmp(_l: [*]const u8, _r: [*]const u8, _n: usize) c_int {
6666}
6767
6868extern fn strerror(errnum: c_int) [*]const u8 {
69 return c"TODO strerror implementation";
69 return "TODO strerror implementation";
7070}
7171
7272test "strncmp" {
73 std.testing.expect(strncmp(c"a", c"b", 1) == -1);
74 std.testing.expect(strncmp(c"a", c"c", 1) == -2);
75 std.testing.expect(strncmp(c"b", c"a", 1) == 1);
76 std.testing.expect(strncmp(c"\xff", c"\x02", 1) == 253);
73 std.testing.expect(strncmp("a", "b", 1) == -1);
74 std.testing.expect(strncmp("a", "c", 1) == -2);
75 std.testing.expect(strncmp("b", "a", 1) == 1);
76 std.testing.expect(strncmp("\xff", "\x02", 1) == 253);
7777}
7878
7979// Avoid dragging in the runtime safety mechanisms into this .o file,
lib/std/thread.zig+1-1
......@@ -353,7 +353,7 @@ pub const Thread = struct {
353353 }
354354 var count: c_int = undefined;
355355 var count_len: usize = @sizeOf(c_int);
356 const name = if (comptime std.Target.current.isDarwin()) c"hw.logicalcpu" else c"hw.ncpu";
356 const name = if (comptime std.Target.current.isDarwin()) "hw.logicalcpu" else "hw.ncpu";
357357 os.sysctlbynameC(name, &count, &count_len, null, 0) catch |err| switch (err) {
358358 error.NameTooLong => unreachable,
359359 else => |e| return e,
lib/std/valgrind/memcheck.zig+1-1
......@@ -3,7 +3,7 @@ const testing = std.testing;
33const valgrind = std.valgrind;
44
55pub const MemCheckClientRequest = extern enum {
6 MakeMemNoAccess = valgrind.ToolBase("MC"),
6 MakeMemNoAccess = valgrind.ToolBase("MC".*),
77 MakeMemUndefined,
88 MakeMemDefined,
99 Discard,
src-self-hosted/codegen.zig+3-3
......@@ -52,7 +52,7 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code)
5252 u32(c.ZIG_VERSION_MINOR),
5353 u32(c.ZIG_VERSION_PATCH),
5454 );
55 const flags = c"";
55 const flags = "";
5656 const runtime_version = 0;
5757 const compile_unit_file = llvm.CreateFile(
5858 dibuilder,
......@@ -68,7 +68,7 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code)
6868 is_optimized,
6969 flags,
7070 runtime_version,
71 c"",
71 "",
7272 0,
7373 !comp.strip,
7474 ) orelse return error.OutOfMemory;
......@@ -402,7 +402,7 @@ pub fn getHandleValue(ofile: *ObjectFile, ptr: *llvm.Value, ptr_type: *Type.Poin
402402 if (child_type.handleIsPtr()) {
403403 return ptr;
404404 }
405 return try renderLoad(ofile, ptr, ptr_type, c"");
405 return try renderLoad(ofile, ptr, ptr_type, "");
406406}
407407
408408pub fn renderStoreUntyped(
src-self-hosted/compilation.zig+2-2
......@@ -511,8 +511,8 @@ pub const Compilation = struct {
511511 comp.target_machine = llvm.CreateTargetMachine(
512512 comp.llvm_target,
513513 comp.llvm_triple.ptr(),
514 target_specific_cpu_args orelse c"",
515 target_specific_cpu_features orelse c"",
514 target_specific_cpu_args orelse "",
515 target_specific_cpu_features orelse "",
516516 opt_level,
517517 reloc_mode,
518518 llvm.CodeModelDefault,
src-self-hosted/ir.zig+6-6
......@@ -331,7 +331,7 @@ pub const Inst = struct {
331331 @intCast(c_uint, args.len),
332332 llvm_cc,
333333 fn_inline,
334 c"",
334 "",
335335 ) orelse error.OutOfMemory;
336336 }
337337 };
......@@ -1410,7 +1410,7 @@ pub const Builder = struct {
14101410 if (block.label) |label| {
14111411 block_scope.incoming_values = std.ArrayList(*Inst).init(irb.arena());
14121412 block_scope.incoming_blocks = std.ArrayList(*BasicBlock).init(irb.arena());
1413 block_scope.end_block = try irb.createBasicBlock(parent_scope, c"BlockEnd");
1413 block_scope.end_block = try irb.createBasicBlock(parent_scope, "BlockEnd");
14141414 block_scope.is_comptime = try irb.buildConstBool(
14151415 parent_scope,
14161416 Span.token(block.lbrace),
......@@ -1542,8 +1542,8 @@ pub const Builder = struct {
15421542 const defer_counts = irb.countDefers(scope, outer_scope);
15431543 const have_err_defers = defer_counts.error_exit != 0;
15441544 if (have_err_defers or irb.comp.have_err_ret_tracing) {
1545 const err_block = try irb.createBasicBlock(scope, c"ErrRetErr");
1546 const ok_block = try irb.createBasicBlock(scope, c"ErrRetOk");
1545 const err_block = try irb.createBasicBlock(scope, "ErrRetErr");
1546 const ok_block = try irb.createBasicBlock(scope, "ErrRetOk");
15471547 if (!have_err_defers) {
15481548 _ = try await (async irb.genDefersForBlock(scope, outer_scope, Scope.Defer.Kind.ScopeExit) catch unreachable);
15491549 }
......@@ -1564,7 +1564,7 @@ pub const Builder = struct {
15641564 .is_comptime = err_is_comptime,
15651565 });
15661566
1567 const ret_stmt_block = try irb.createBasicBlock(scope, c"RetStmt");
1567 const ret_stmt_block = try irb.createBasicBlock(scope, "RetStmt");
15681568
15691569 try irb.setCursorAtEndAndAppendBlock(err_block);
15701570 if (have_err_defers) {
......@@ -2530,7 +2530,7 @@ pub async fn gen(
25302530 var irb = try Builder.init(comp, tree_scope, scope);
25312531 errdefer irb.abort();
25322532
2533 const entry_block = try irb.createBasicBlock(scope, c"Entry");
2533 const entry_block = try irb.createBasicBlock(scope, "Entry");
25342534 entry_block.ref(&irb); // Entry block gets a reference because we enter it to begin.
25352535 try irb.setCursorAtEndAndAppendBlock(entry_block);
25362536
src-self-hosted/link.zig+63-63
......@@ -55,7 +55,7 @@ pub async fn link(comp: *Compilation) !void {
5555
5656 // even though we're calling LLD as a library it thinks the first
5757 // argument is its own exe name
58 try ctx.args.append(c"lld");
58 try ctx.args.append("lld");
5959
6060 if (comp.haveLibC()) {
6161 ctx.libc = ctx.comp.override_libc orelse blk: {
......@@ -145,7 +145,7 @@ fn constructLinkerArgsElf(ctx: *Context) !void {
145145 // lj->args.append("-T");
146146 // lj->args.append(g->linker_script);
147147 //}
148 try ctx.args.append(c"--gc-sections");
148 try ctx.args.append("--gc-sections");
149149
150150 //lj->args.append("-m");
151151 //lj->args.append(getLDMOption(&g->zig_target));
......@@ -155,9 +155,9 @@ fn constructLinkerArgsElf(ctx: *Context) !void {
155155 //Buf *soname = nullptr;
156156 if (ctx.comp.is_static) {
157157 if (ctx.comp.target.isArmOrThumb()) {
158 try ctx.args.append(c"-Bstatic");
158 try ctx.args.append("-Bstatic");
159159 } else {
160 try ctx.args.append(c"-static");
160 try ctx.args.append("-static");
161161 }
162162 }
163163 //} else if (shared) {
......@@ -170,7 +170,7 @@ fn constructLinkerArgsElf(ctx: *Context) !void {
170170 // soname = buf_sprintf("lib%s.so.%" ZIG_PRI_usize "", buf_ptr(g->root_out_name), g->version_major);
171171 //}
172172
173 try ctx.args.append(c"-o");
173 try ctx.args.append("-o");
174174 try ctx.args.append(ctx.out_file_path.ptr());
175175
176176 if (ctx.link_in_crt) {
......@@ -213,10 +213,10 @@ fn constructLinkerArgsElf(ctx: *Context) !void {
213213 //}
214214
215215 if (ctx.comp.haveLibC()) {
216 try ctx.args.append(c"-L");
216 try ctx.args.append("-L");
217217 try ctx.args.append((try std.cstr.addNullByte(&ctx.arena.allocator, ctx.libc.lib_dir.?)).ptr);
218218
219 try ctx.args.append(c"-L");
219 try ctx.args.append("-L");
220220 try ctx.args.append((try std.cstr.addNullByte(&ctx.arena.allocator, ctx.libc.static_lib_dir.?)).ptr);
221221
222222 if (!ctx.comp.is_static) {
......@@ -225,7 +225,7 @@ fn constructLinkerArgsElf(ctx: *Context) !void {
225225 if (ctx.comp.target.getDynamicLinkerPath()) |dl| break :blk dl;
226226 return error.LibCMissingDynamicLinker;
227227 };
228 try ctx.args.append(c"-dynamic-linker");
228 try ctx.args.append("-dynamic-linker");
229229 try ctx.args.append((try std.cstr.addNullByte(&ctx.arena.allocator, dl)).ptr);
230230 }
231231 }
......@@ -272,23 +272,23 @@ fn constructLinkerArgsElf(ctx: *Context) !void {
272272 // libc dep
273273 if (ctx.comp.haveLibC()) {
274274 if (ctx.comp.is_static) {
275 try ctx.args.append(c"--start-group");
276 try ctx.args.append(c"-lgcc");
277 try ctx.args.append(c"-lgcc_eh");
278 try ctx.args.append(c"-lc");
279 try ctx.args.append(c"-lm");
280 try ctx.args.append(c"--end-group");
275 try ctx.args.append("--start-group");
276 try ctx.args.append("-lgcc");
277 try ctx.args.append("-lgcc_eh");
278 try ctx.args.append("-lc");
279 try ctx.args.append("-lm");
280 try ctx.args.append("--end-group");
281281 } else {
282 try ctx.args.append(c"-lgcc");
283 try ctx.args.append(c"--as-needed");
284 try ctx.args.append(c"-lgcc_s");
285 try ctx.args.append(c"--no-as-needed");
286 try ctx.args.append(c"-lc");
287 try ctx.args.append(c"-lm");
288 try ctx.args.append(c"-lgcc");
289 try ctx.args.append(c"--as-needed");
290 try ctx.args.append(c"-lgcc_s");
291 try ctx.args.append(c"--no-as-needed");
282 try ctx.args.append("-lgcc");
283 try ctx.args.append("--as-needed");
284 try ctx.args.append("-lgcc_s");
285 try ctx.args.append("--no-as-needed");
286 try ctx.args.append("-lc");
287 try ctx.args.append("-lm");
288 try ctx.args.append("-lgcc");
289 try ctx.args.append("--as-needed");
290 try ctx.args.append("-lgcc_s");
291 try ctx.args.append("--no-as-needed");
292292 }
293293 }
294294
......@@ -299,14 +299,14 @@ fn constructLinkerArgsElf(ctx: *Context) !void {
299299 }
300300
301301 if (ctx.comp.target != Target.Native) {
302 try ctx.args.append(c"--allow-shlib-undefined");
302 try ctx.args.append("--allow-shlib-undefined");
303303 }
304304
305305 if (ctx.comp.target.getOs() == .zen) {
306 try ctx.args.append(c"-e");
307 try ctx.args.append(c"_start");
306 try ctx.args.append("-e");
307 try ctx.args.append("_start");
308308
309 try ctx.args.append(c"--image-base=0x10000000");
309 try ctx.args.append("--image-base=0x10000000");
310310 }
311311}
312312
......@@ -317,23 +317,23 @@ fn addPathJoin(ctx: *Context, dirname: []const u8, basename: []const u8) !void {
317317}
318318
319319fn constructLinkerArgsCoff(ctx: *Context) !void {
320 try ctx.args.append(c"-NOLOGO");
320 try ctx.args.append("-NOLOGO");
321321
322322 if (!ctx.comp.strip) {
323 try ctx.args.append(c"-DEBUG");
323 try ctx.args.append("-DEBUG");
324324 }
325325
326326 switch (ctx.comp.target.getArch()) {
327 builtin.Arch.i386 => try ctx.args.append(c"-MACHINE:X86"),
328 builtin.Arch.x86_64 => try ctx.args.append(c"-MACHINE:X64"),
329 builtin.Arch.aarch64 => try ctx.args.append(c"-MACHINE:ARM"),
327 builtin.Arch.i386 => try ctx.args.append("-MACHINE:X86"),
328 builtin.Arch.x86_64 => try ctx.args.append("-MACHINE:X64"),
329 builtin.Arch.aarch64 => try ctx.args.append("-MACHINE:ARM"),
330330 else => return error.UnsupportedLinkArchitecture,
331331 }
332332
333333 if (ctx.comp.windows_subsystem_windows) {
334 try ctx.args.append(c"/SUBSYSTEM:windows");
334 try ctx.args.append("/SUBSYSTEM:windows");
335335 } else if (ctx.comp.windows_subsystem_console) {
336 try ctx.args.append(c"/SUBSYSTEM:console");
336 try ctx.args.append("/SUBSYSTEM:console");
337337 }
338338
339339 const is_library = ctx.comp.kind == Compilation.Kind.Lib;
......@@ -367,14 +367,14 @@ fn constructLinkerArgsCoff(ctx: *Context) !void {
367367
368368 // Visual C++ 2015 Conformance Changes
369369 // https://msdn.microsoft.com/en-us/library/bb531344.aspx
370 try ctx.args.append(c"legacy_stdio_definitions.lib");
370 try ctx.args.append("legacy_stdio_definitions.lib");
371371
372372 // msvcrt depends on kernel32
373 try ctx.args.append(c"kernel32.lib");
373 try ctx.args.append("kernel32.lib");
374374 } else {
375 try ctx.args.append(c"-NODEFAULTLIB");
375 try ctx.args.append("-NODEFAULTLIB");
376376 if (!is_library) {
377 try ctx.args.append(c"-ENTRY:WinMainCRTStartup");
377 try ctx.args.append("-ENTRY:WinMainCRTStartup");
378378 // TODO
379379 //if (g->have_winmain) {
380380 // lj->args.append("-ENTRY:WinMain");
......@@ -385,7 +385,7 @@ fn constructLinkerArgsCoff(ctx: *Context) !void {
385385 }
386386
387387 if (is_library and !ctx.comp.is_static) {
388 try ctx.args.append(c"-DLL");
388 try ctx.args.append("-DLL");
389389 }
390390
391391 //for (size_t i = 0; i < g->lib_dirs.length; i += 1) {
......@@ -463,18 +463,18 @@ fn constructLinkerArgsCoff(ctx: *Context) !void {
463463}
464464
465465fn constructLinkerArgsMachO(ctx: *Context) !void {
466 try ctx.args.append(c"-demangle");
466 try ctx.args.append("-demangle");
467467
468468 if (ctx.comp.linker_rdynamic) {
469 try ctx.args.append(c"-export_dynamic");
469 try ctx.args.append("-export_dynamic");
470470 }
471471
472472 const is_lib = ctx.comp.kind == Compilation.Kind.Lib;
473473 const shared = !ctx.comp.is_static and is_lib;
474474 if (ctx.comp.is_static) {
475 try ctx.args.append(c"-static");
475 try ctx.args.append("-static");
476476 } else {
477 try ctx.args.append(c"-dynamic");
477 try ctx.args.append("-dynamic");
478478 }
479479
480480 //if (is_lib) {
......@@ -503,7 +503,7 @@ fn constructLinkerArgsMachO(ctx: *Context) !void {
503503 // }
504504 //}
505505
506 try ctx.args.append(c"-arch");
506 try ctx.args.append("-arch");
507507 const darwin_arch_str = try std.cstr.addNullByte(
508508 &ctx.arena.allocator,
509509 ctx.comp.target.getDarwinArchString(),
......@@ -512,22 +512,22 @@ fn constructLinkerArgsMachO(ctx: *Context) !void {
512512
513513 const platform = try DarwinPlatform.get(ctx.comp);
514514 switch (platform.kind) {
515 DarwinPlatform.Kind.MacOS => try ctx.args.append(c"-macosx_version_min"),
516 DarwinPlatform.Kind.IPhoneOS => try ctx.args.append(c"-iphoneos_version_min"),
517 DarwinPlatform.Kind.IPhoneOSSimulator => try ctx.args.append(c"-ios_simulator_version_min"),
515 DarwinPlatform.Kind.MacOS => try ctx.args.append("-macosx_version_min"),
516 DarwinPlatform.Kind.IPhoneOS => try ctx.args.append("-iphoneos_version_min"),
517 DarwinPlatform.Kind.IPhoneOSSimulator => try ctx.args.append("-ios_simulator_version_min"),
518518 }
519519 const ver_str = try std.fmt.allocPrint(&ctx.arena.allocator, "{}.{}.{}\x00", platform.major, platform.minor, platform.micro);
520520 try ctx.args.append(ver_str.ptr);
521521
522522 if (ctx.comp.kind == Compilation.Kind.Exe) {
523523 if (ctx.comp.is_static) {
524 try ctx.args.append(c"-no_pie");
524 try ctx.args.append("-no_pie");
525525 } else {
526 try ctx.args.append(c"-pie");
526 try ctx.args.append("-pie");
527527 }
528528 }
529529
530 try ctx.args.append(c"-o");
530 try ctx.args.append("-o");
531531 try ctx.args.append(ctx.out_file_path.ptr());
532532
533533 //for (size_t i = 0; i < g->rpath_list.length; i += 1) {
......@@ -537,27 +537,27 @@ fn constructLinkerArgsMachO(ctx: *Context) !void {
537537 //add_rpath(lj, &lj->out_file);
538538
539539 if (shared) {
540 try ctx.args.append(c"-headerpad_max_install_names");
540 try ctx.args.append("-headerpad_max_install_names");
541541 } else if (ctx.comp.is_static) {
542 try ctx.args.append(c"-lcrt0.o");
542 try ctx.args.append("-lcrt0.o");
543543 } else {
544544 switch (platform.kind) {
545545 DarwinPlatform.Kind.MacOS => {
546546 if (platform.versionLessThan(10, 5)) {
547 try ctx.args.append(c"-lcrt1.o");
547 try ctx.args.append("-lcrt1.o");
548548 } else if (platform.versionLessThan(10, 6)) {
549 try ctx.args.append(c"-lcrt1.10.5.o");
549 try ctx.args.append("-lcrt1.10.5.o");
550550 } else if (platform.versionLessThan(10, 8)) {
551 try ctx.args.append(c"-lcrt1.10.6.o");
551 try ctx.args.append("-lcrt1.10.6.o");
552552 }
553553 },
554554 DarwinPlatform.Kind.IPhoneOS => {
555555 if (ctx.comp.target.getArch() == builtin.Arch.aarch64) {
556556 // iOS does not need any crt1 files for arm64
557557 } else if (platform.versionLessThan(3, 1)) {
558 try ctx.args.append(c"-lcrt1.o");
558 try ctx.args.append("-lcrt1.o");
559559 } else if (platform.versionLessThan(6, 0)) {
560 try ctx.args.append(c"-lcrt1.3.1.o");
560 try ctx.args.append("-lcrt1.3.1.o");
561561 }
562562 },
563563 DarwinPlatform.Kind.IPhoneOSSimulator => {}, // no crt1.o needed
......@@ -589,7 +589,7 @@ fn constructLinkerArgsMachO(ctx: *Context) !void {
589589 // to make syscalls because the syscall numbers are not documented
590590 // and change between versions.
591591 // so we always link against libSystem
592 try ctx.args.append(c"-lSystem");
592 try ctx.args.append("-lSystem");
593593 } else {
594594 if (mem.indexOfScalar(u8, lib.name, '/') == null) {
595595 const arg = try std.fmt.allocPrint(&ctx.arena.allocator, "-l{}\x00", lib.name);
......@@ -601,15 +601,15 @@ fn constructLinkerArgsMachO(ctx: *Context) !void {
601601 }
602602 }
603603 } else {
604 try ctx.args.append(c"-undefined");
605 try ctx.args.append(c"dynamic_lookup");
604 try ctx.args.append("-undefined");
605 try ctx.args.append("dynamic_lookup");
606606 }
607607
608608 if (platform.kind == DarwinPlatform.Kind.MacOS) {
609609 if (platform.versionLessThan(10, 5)) {
610 try ctx.args.append(c"-lgcc_s.10.4");
610 try ctx.args.append("-lgcc_s.10.4");
611611 } else if (platform.versionLessThan(10, 6)) {
612 try ctx.args.append(c"-lgcc_s.10.5");
612 try ctx.args.append("-lgcc_s.10.5");
613613 }
614614 } else {
615615 @panic("TODO");
src-self-hosted/stage1.zig+1-1
......@@ -28,7 +28,7 @@ comptime {
2828// ABI warning
2929export fn stage2_zen(ptr: *[*]const u8, len: *usize) void {
3030 const info_zen = @import("main.zig").info_zen;
31 ptr.* = &info_zen;
31 ptr.* = info_zen;
3232 len.* = info_zen.len;
3333}
3434
src-self-hosted/value.zig+1-1
......@@ -474,7 +474,7 @@ pub const Value = struct {
474474 dont_null_terminate,
475475 ) orelse return error.OutOfMemory;
476476 const str_init_type = llvm.TypeOf(llvm_str_init);
477 const global = llvm.AddGlobal(ofile.module, str_init_type, c"") orelse return error.OutOfMemory;
477 const global = llvm.AddGlobal(ofile.module, str_init_type, "") orelse return error.OutOfMemory;
478478 llvm.SetInitializer(global, llvm_str_init);
479479 llvm.SetLinkage(global, llvm.PrivateLinkage);
480480 llvm.SetGlobalConstant(global, 1);
src/all_types.hpp+5-4
......@@ -102,6 +102,10 @@ struct IrExecutable {
102102 bool is_inline;
103103 bool is_generic_instantiation;
104104 bool need_err_code_spill;
105
106 // This is a function for use in the debugger to print
107 // the source location.
108 void src();
105109};
106110
107111enum OutType {
......@@ -237,9 +241,6 @@ struct ConstPtrValue {
237241 struct {
238242 ConstExprValue *array_val;
239243 size_t elem_index;
240 // This helps us preserve the null byte when performing compile-time
241 // concatenation on C strings.
242 bool is_cstr;
243244 } base_array;
244245 struct {
245246 ConstExprValue *struct_val;
......@@ -1001,7 +1002,6 @@ struct AstNodeStructField {
10011002
10021003struct AstNodeStringLiteral {
10031004 Buf *buf;
1004 bool c;
10051005};
10061006
10071007struct AstNodeCharLiteral {
......@@ -1956,6 +1956,7 @@ struct CodeGen {
19561956 HashMap<Buf *, Tld *, buf_hash, buf_eql_buf> external_prototypes;
19571957 HashMap<Buf *, ConstExprValue *, buf_hash, buf_eql_buf> string_literals_table;
19581958 HashMap<const ZigType *, ConstExprValue *, type_ptr_hash, type_ptr_eql> type_info_cache;
1959 HashMap<const ZigType *, ConstExprValue *, type_ptr_hash, type_ptr_eql> one_possible_values;
19591960
19601961 ZigList<Tld *> resolve_queue;
19611962 size_t resolve_queue_index;
src/analyze.cpp+85-56
......@@ -767,10 +767,18 @@ ZigType *get_array_type(CodeGen *g, ZigType *child_type, uint64_t array_size, bo
767767
768768 ZigType *entry = new_type_table_entry(ZigTypeIdArray);
769769
770 const char *null_str = is_null_terminated ? "null " : "";
771
770772 buf_resize(&entry->name, 0);
771 buf_appendf(&entry->name, "[%" ZIG_PRI_u64 "]%s", array_size, buf_ptr(&child_type->name));
773 buf_appendf(&entry->name, "[%" ZIG_PRI_u64 "]%s%s", array_size, null_str, buf_ptr(&child_type->name));
774
775 size_t full_array_size;
776 if (array_size == 0) {
777 full_array_size = 0;
778 } else {
779 full_array_size = array_size + (is_null_terminated ? 1 : 0);
780 }
772781
773 size_t full_array_size = array_size + (is_null_terminated ? 1 : 0);
774782 entry->size_in_bits = child_type->size_in_bits * full_array_size;
775783 entry->abi_align = child_type->abi_align;
776784 entry->abi_size = child_type->abi_size * full_array_size;
......@@ -5046,7 +5054,6 @@ static uint32_t hash_const_val_ptr(ConstExprValue *const_val) {
50465054 hash_val += (uint32_t)1764906839;
50475055 hash_val += hash_ptr(const_val->data.x_ptr.data.base_array.array_val);
50485056 hash_val += hash_size(const_val->data.x_ptr.data.base_array.elem_index);
5049 hash_val += const_val->data.x_ptr.data.base_array.is_cstr ? 1297263887 : 200363492;
50505057 return hash_val;
50515058 case ConstPtrSpecialBaseStruct:
50525059 hash_val += (uint32_t)3518317043;
......@@ -5550,6 +5557,18 @@ OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry) {
55505557 zig_unreachable();
55515558}
55525559
5560ConstExprValue *get_the_one_possible_value(CodeGen *g, ZigType *type_entry) {
5561 auto entry = g->one_possible_values.maybe_get(type_entry);
5562 if (entry != nullptr) {
5563 return entry->value;
5564 }
5565 ConstExprValue *result = create_const_vals(1);
5566 result->type = type_entry;
5567 result->special = ConstValSpecialStatic;
5568 g->one_possible_values.put(type_entry, result);
5569 return result;
5570}
5571
55535572ReqCompTime type_requires_comptime(CodeGen *g, ZigType *ty) {
55545573 Error err;
55555574 switch (ty->id) {
......@@ -5617,52 +5636,26 @@ void init_const_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *str) {
56175636 return;
56185637 }
56195638
5620 const_val->special = ConstValSpecialStatic;
5621 const_val->type = get_array_type(g, g->builtin_types.entry_u8, buf_len(str), false);
5622 const_val->data.x_array.special = ConstArraySpecialBuf;
5623 const_val->data.x_array.data.s_buf = str;
5624
5625 g->string_literals_table.put(str, const_val);
5626}
5627
5628ConstExprValue *create_const_str_lit(CodeGen *g, Buf *str) {
5629 ConstExprValue *const_val = create_const_vals(1);
5630 init_const_str_lit(g, const_val, str);
5631 return const_val;
5632}
5633
5634void init_const_c_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *str) {
56355639 // first we build the underlying array
5636 size_t len_with_null = buf_len(str) + 1;
56375640 ConstExprValue *array_val = create_const_vals(1);
56385641 array_val->special = ConstValSpecialStatic;
5639 array_val->type = get_array_type(g, g->builtin_types.entry_u8, len_with_null, false);
5640 // TODO buf optimization
5641 array_val->data.x_array.data.s_none.elements = create_const_vals(len_with_null);
5642 for (size_t i = 0; i < buf_len(str); i += 1) {
5643 ConstExprValue *this_char = &array_val->data.x_array.data.s_none.elements[i];
5644 this_char->special = ConstValSpecialStatic;
5645 this_char->type = g->builtin_types.entry_u8;
5646 bigint_init_unsigned(&this_char->data.x_bigint, (uint8_t)buf_ptr(str)[i]);
5647 }
5648 ConstExprValue *null_char = &array_val->data.x_array.data.s_none.elements[len_with_null - 1];
5649 null_char->special = ConstValSpecialStatic;
5650 null_char->type = g->builtin_types.entry_u8;
5651 bigint_init_unsigned(&null_char->data.x_bigint, 0);
5642 array_val->type = get_array_type(g, g->builtin_types.entry_u8, buf_len(str), true);
5643 array_val->data.x_array.special = ConstArraySpecialBuf;
5644 array_val->data.x_array.data.s_buf = str;
56525645
56535646 // then make the pointer point to it
56545647 const_val->special = ConstValSpecialStatic;
5655 // TODO make this `[*]null u8` instead of `[*]u8`
5656 const_val->type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
5657 PtrLenUnknown, 0, 0, 0, false);
5658 const_val->data.x_ptr.special = ConstPtrSpecialBaseArray;
5659 const_val->data.x_ptr.data.base_array.array_val = array_val;
5660 const_val->data.x_ptr.data.base_array.elem_index = 0;
5661 const_val->data.x_ptr.data.base_array.is_cstr = true;
5648 const_val->type = get_pointer_to_type_extra2(g, array_val->type, true, false,
5649 PtrLenSingle, 0, 0, 0, false, VECTOR_INDEX_NONE, nullptr);
5650 const_val->data.x_ptr.special = ConstPtrSpecialRef;
5651 const_val->data.x_ptr.data.ref.pointee = array_val;
5652
5653 g->string_literals_table.put(str, const_val);
56625654}
5663ConstExprValue *create_const_c_str_lit(CodeGen *g, Buf *str) {
5655
5656ConstExprValue *create_const_str_lit(CodeGen *g, Buf *str) {
56645657 ConstExprValue *const_val = create_const_vals(1);
5665 init_const_c_str_lit(g, const_val, str);
5658 init_const_str_lit(g, const_val, str);
56665659 return const_val;
56675660}
56685661
......@@ -5712,6 +5705,18 @@ ConstExprValue *create_const_signed(ZigType *type, int64_t x) {
57125705 return const_val;
57135706}
57145707
5708void init_const_null(ConstExprValue *const_val, ZigType *type) {
5709 const_val->special = ConstValSpecialStatic;
5710 const_val->type = type;
5711 const_val->data.x_optional = nullptr;
5712}
5713
5714ConstExprValue *create_const_null(ZigType *type) {
5715 ConstExprValue *const_val = create_const_vals(1);
5716 init_const_null(const_val, type);
5717 return const_val;
5718}
5719
57155720void init_const_float(ConstExprValue *const_val, ZigType *type, double value) {
57165721 const_val->special = ConstValSpecialStatic;
57175722 const_val->type = type;
......@@ -6446,8 +6451,6 @@ bool ir_get_var_is_comptime(ZigVar *var) {
64466451bool const_values_equal_ptr(ConstExprValue *a, ConstExprValue *b) {
64476452 if (a->data.x_ptr.special != b->data.x_ptr.special)
64486453 return false;
6449 if (a->data.x_ptr.mut != b->data.x_ptr.mut)
6450 return false;
64516454 switch (a->data.x_ptr.special) {
64526455 case ConstPtrSpecialInvalid:
64536456 zig_unreachable();
......@@ -6464,8 +6467,6 @@ bool const_values_equal_ptr(ConstExprValue *a, ConstExprValue *b) {
64646467 }
64656468 if (a->data.x_ptr.data.base_array.elem_index != b->data.x_ptr.data.base_array.elem_index)
64666469 return false;
6467 if (a->data.x_ptr.data.base_array.is_cstr != b->data.x_ptr.data.base_array.is_cstr)
6468 return false;
64696470 return true;
64706471 case ConstPtrSpecialBaseStruct:
64716472 if (a->data.x_ptr.data.base_struct.struct_val != b->data.x_ptr.data.base_struct.struct_val &&
......@@ -6544,6 +6545,16 @@ bool const_values_equal(CodeGen *g, ConstExprValue *a, ConstExprValue *b) {
65446545 assert(a->type->id == b->type->id);
65456546 assert(a->special == ConstValSpecialStatic);
65466547 assert(b->special == ConstValSpecialStatic);
6548 if (a->type == b->type) {
6549 switch (type_has_one_possible_value(g, a->type)) {
6550 case OnePossibleValueInvalid:
6551 zig_unreachable();
6552 case OnePossibleValueNo:
6553 break;
6554 case OnePossibleValueYes:
6555 return true;
6556 }
6557 }
65476558 switch (a->type->id) {
65486559 case ZigTypeIdOpaque:
65496560 zig_unreachable();
......@@ -6709,15 +6720,10 @@ static void render_const_val_ptr(CodeGen *g, Buf *buf, ConstExprValue *const_val
67096720 render_const_value(g, buf, const_ptr_pointee(nullptr, g, const_val, nullptr));
67106721 return;
67116722 case ConstPtrSpecialBaseArray:
6712 if (const_val->data.x_ptr.data.base_array.is_cstr) {
6713 buf_appendf(buf, "*(c str lit)");
6714 return;
6715 } else {
6716 buf_appendf(buf, "*");
6717 // TODO we need a source node for const_ptr_pointee because it can generate compile errors
6718 render_const_value(g, buf, const_ptr_pointee(nullptr, g, const_val, nullptr));
6719 return;
6720 }
6723 buf_appendf(buf, "*");
6724 // TODO we need a source node for const_ptr_pointee because it can generate compile errors
6725 render_const_value(g, buf, const_ptr_pointee(nullptr, g, const_val, nullptr));
6726 return;
67216727 case ConstPtrSpecialHardCodedAddr:
67226728 buf_appendf(buf, "(%s)(%" ZIG_PRI_x64 ")", buf_ptr(&type_entry->name),
67236729 const_val->data.x_ptr.data.hard_coded_addr.addr);
......@@ -8653,14 +8659,16 @@ static void resolve_llvm_types_array(CodeGen *g, ZigType *type) {
86538659
86548660 ZigType *elem_type = type->data.array.child_type;
86558661
8662 uint64_t extra_len_from_null = type->data.array.is_null_terminated ? 1 : 0;
8663 uint64_t full_len = type->data.array.len + extra_len_from_null;
86568664 // TODO https://github.com/ziglang/zig/issues/1424
8657 type->llvm_type = LLVMArrayType(get_llvm_type(g, elem_type), (unsigned)type->data.array.len);
8665 type->llvm_type = LLVMArrayType(get_llvm_type(g, elem_type), (unsigned)full_len);
86588666
86598667 uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, type->llvm_type);
86608668 uint64_t debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, type->llvm_type);
86618669
86628670 type->llvm_di_type = ZigLLVMCreateDebugArrayType(g->dbuilder, debug_size_in_bits,
8663 debug_align_in_bits, get_llvm_di_type(g, elem_type), (int)type->data.array.len);
8671 debug_align_in_bits, get_llvm_di_type(g, elem_type), (int)full_len);
86648672}
86658673
86668674static void resolve_llvm_types_fn_type(CodeGen *g, ZigType *fn_type) {
......@@ -9150,3 +9158,24 @@ Error analyze_import(CodeGen *g, ZigType *source_import, Buf *import_target_str,
91509158 *out_import = add_source_file(g, target_package, resolved_path, import_code, source_kind);
91519159 return ErrorNone;
91529160}
9161
9162
9163void IrExecutable::src() {
9164 IrExecutable *it;
9165 for (it = this; it != nullptr && it->source_node != nullptr; it = it->parent_exec) {
9166 it->source_node->src();
9167 }
9168}
9169
9170ConstExprValue *get_null_value(ZigType *ty) {
9171 if (ty->id == ZigTypeIdInt || ty->id == ZigTypeIdComptimeInt) {
9172 return create_const_unsigned_negative(ty, 0, false);
9173 } else if (ty->id == ZigTypeIdFloat || ty->id == ZigTypeIdComptimeFloat) {
9174 return create_const_float(ty, NAN);
9175 } else if (ty->id == ZigTypeIdOptional) {
9176 return create_const_null(ty);
9177 } else {
9178 zig_unreachable();
9179 }
9180}
9181
src/analyze.hpp+5-4
......@@ -126,9 +126,6 @@ ScopeExpr *create_expr_scope(CodeGen *g, AstNode *node, Scope *parent);
126126void init_const_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *str);
127127ConstExprValue *create_const_str_lit(CodeGen *g, Buf *str);
128128
129void init_const_c_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *c_str);
130ConstExprValue *create_const_c_str_lit(CodeGen *g, Buf *c_str);
131
132129void init_const_bigint(ConstExprValue *const_val, ZigType *type, const BigInt *bigint);
133130ConstExprValue *create_const_bigint(ZigType *type, const BigInt *bigint);
134131
......@@ -176,6 +173,9 @@ ConstExprValue *create_const_slice(CodeGen *g, ConstExprValue *array_val, size_t
176173void init_const_arg_tuple(CodeGen *g, ConstExprValue *const_val, size_t arg_index_start, size_t arg_index_end);
177174ConstExprValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_t arg_index_end);
178175
176void init_const_null(ConstExprValue *const_val, ZigType *type);
177ConstExprValue *create_const_null(ZigType *type);
178
179179ConstExprValue *create_const_vals(size_t count);
180180ConstExprValue **alloc_const_vals_ptrs(size_t count);
181181ConstExprValue **realloc_const_vals_ptrs(ConstExprValue **ptr, size_t old_count, size_t new_count);
......@@ -275,5 +275,6 @@ IrInstruction *ir_create_alloca(CodeGen *g, Scope *scope, AstNode *source_node,
275275 ZigType *var_type, const char *name_hint);
276276Error analyze_import(CodeGen *codegen, ZigType *source_import, Buf *import_target_str,
277277 ZigType **out_import, Buf **out_import_target_path, Buf *out_full_path);
278
278ConstExprValue *get_the_one_possible_value(CodeGen *g, ZigType *type_entry);
279ConstExprValue *get_null_value(ZigType *ty);
279280#endif
src/ast_render.cpp-3
......@@ -619,9 +619,6 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {
619619 break;
620620 case NodeTypeStringLiteral:
621621 {
622 if (node->data.string_literal.c) {
623 fprintf(ar->f, "c");
624 }
625622 Buf tmp_buf = BUF_INIT;
626623 string_literal_escape(node->data.string_literal.buf, &tmp_buf);
627624 fprintf(ar->f, "\"%s\"", buf_ptr(&tmp_buf));
src/codegen.cpp+38-23
......@@ -949,7 +949,7 @@ static LLVMValueRef get_panic_msg_ptr_val(CodeGen *g, PanicMsgId msg_id) {
949949 if (!val->global_refs->llvm_global) {
950950
951951 Buf *buf_msg = panic_msg_buf(msg_id);
952 ConstExprValue *array_val = create_const_str_lit(g, buf_msg);
952 ConstExprValue *array_val = create_const_str_lit(g, buf_msg)->data.x_ptr.data.ref.pointee;
953953 init_const_slice(g, val, array_val, 0, buf_len(buf_msg), true);
954954
955955 render_const_val(g, val, "");
......@@ -2784,14 +2784,6 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
27842784 IrInstruction *op1 = bin_op_instruction->op1;
27852785 IrInstruction *op2 = bin_op_instruction->op2;
27862786
2787 assert(op1->value.type == op2->value.type || op_id == IrBinOpBitShiftLeftLossy ||
2788 op_id == IrBinOpBitShiftLeftExact || op_id == IrBinOpBitShiftRightLossy ||
2789 op_id == IrBinOpBitShiftRightExact ||
2790 (op1->value.type->id == ZigTypeIdErrorSet && op2->value.type->id == ZigTypeIdErrorSet) ||
2791 (op1->value.type->id == ZigTypeIdPointer &&
2792 (op_id == IrBinOpAdd || op_id == IrBinOpSub) &&
2793 op1->value.type->data.pointer.ptr_len != PtrLenSingle)
2794 );
27952787 ZigType *operand_type = op1->value.type;
27962788 ZigType *scalar_type = (operand_type->id == ZigTypeIdVector) ? operand_type->data.vector.elem_type : operand_type;
27972789
......@@ -2848,7 +2840,6 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
28482840 AddSubMulMul;
28492841
28502842 if (scalar_type->id == ZigTypeIdPointer) {
2851 assert(scalar_type->data.pointer.ptr_len != PtrLenSingle);
28522843 LLVMValueRef subscript_value;
28532844 if (operand_type->id == ZigTypeIdVector)
28542845 zig_panic("TODO: Implement vector operations on pointers.");
......@@ -3077,7 +3068,14 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
30773068 case CastOpNumLitToConcrete:
30783069 zig_unreachable();
30793070 case CastOpNoop:
3080 return expr_val;
3071 if (actual_type->id == ZigTypeIdPointer && wanted_type->id == ZigTypeIdPointer &&
3072 actual_type->data.pointer.child_type->id == ZigTypeIdArray &&
3073 wanted_type->data.pointer.child_type->id == ZigTypeIdArray)
3074 {
3075 return LLVMBuildBitCast(g->builder, expr_val, get_llvm_type(g, wanted_type), "");
3076 } else {
3077 return expr_val;
3078 }
30813079 case CastOpIntToFloat:
30823080 assert(actual_type->id == ZigTypeIdInt);
30833081 if (actual_type->data.integral.is_signed) {
......@@ -3709,8 +3707,9 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI
37093707 array_type = array_type->data.pointer.child_type;
37103708 }
37113709 if (safety_check_on) {
3712 LLVMValueRef end = LLVMConstInt(g->builtin_types.entry_usize->llvm_type,
3713 array_type->data.array.len, false);
3710 uint64_t extra_len_from_null = array_type->data.array.is_null_terminated ? 1 : 0;
3711 uint64_t full_len = array_type->data.array.len + extra_len_from_null;
3712 LLVMValueRef end = LLVMConstInt(g->builtin_types.entry_usize->llvm_type, full_len, false);
37143713 add_bounds_check(g, subscript_value, LLVMIntEQ, nullptr, LLVMIntULT, end);
37153714 }
37163715 if (array_ptr_type->data.pointer.host_int_bytes != 0) {
......@@ -6637,11 +6636,20 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con
66376636 ConstExprValue *array_const_val = const_val->data.x_ptr.data.base_array.array_val;
66386637 assert(array_const_val->type->id == ZigTypeIdArray);
66396638 if (!type_has_bits(array_const_val->type)) {
6640 // make this a null pointer
6641 ZigType *usize = g->builtin_types.entry_usize;
6642 const_val->global_refs->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->llvm_type),
6643 get_llvm_type(g, const_val->type));
6644 return const_val->global_refs->llvm_value;
6639 if (array_const_val->type->data.array.is_null_terminated) {
6640 ConstExprValue *pointee = get_null_value(array_const_val->type->data.array.child_type);
6641 render_const_val(g, pointee, "");
6642 render_const_val_global(g, pointee, "");
6643 const_val->global_refs->llvm_value = LLVMConstBitCast(pointee->global_refs->llvm_global,
6644 get_llvm_type(g, const_val->type));
6645 return const_val->global_refs->llvm_value;
6646 } else {
6647 // make this a null pointer
6648 ZigType *usize = g->builtin_types.entry_usize;
6649 const_val->global_refs->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->llvm_type),
6650 get_llvm_type(g, const_val->type));
6651 return const_val->global_refs->llvm_value;
6652 }
66456653 }
66466654 size_t elem_index = const_val->data.x_ptr.data.base_array.elem_index;
66476655 LLVMValueRef uncasted_ptr_val = gen_const_ptr_array_recursive(g, array_const_val, elem_index);
......@@ -6955,7 +6963,9 @@ check: switch (const_val->special) {
69556963 case ConstArraySpecialUndef:
69566964 return LLVMGetUndef(get_llvm_type(g, type_entry));
69576965 case ConstArraySpecialNone: {
6958 LLVMValueRef *values = allocate<LLVMValueRef>(len);
6966 uint64_t extra_len_from_null = type_entry->data.array.is_null_terminated ? 1 : 0;
6967 uint64_t full_len = len + extra_len_from_null;
6968 LLVMValueRef *values = allocate<LLVMValueRef>(full_len);
69596969 LLVMTypeRef element_type_ref = get_llvm_type(g, type_entry->data.array.child_type);
69606970 bool make_unnamed_struct = false;
69616971 for (uint64_t i = 0; i < len; i += 1) {
......@@ -6964,15 +6974,19 @@ check: switch (const_val->special) {
69646974 values[i] = val;
69656975 make_unnamed_struct = make_unnamed_struct || is_llvm_value_unnamed_type(g, elem_value->type, val);
69666976 }
6977 if (type_entry->data.array.is_null_terminated) {
6978 values[len] = LLVMConstNull(element_type_ref);
6979 }
69676980 if (make_unnamed_struct) {
6968 return LLVMConstStruct(values, len, true);
6981 return LLVMConstStruct(values, full_len, true);
69696982 } else {
6970 return LLVMConstArray(element_type_ref, values, (unsigned)len);
6983 return LLVMConstArray(element_type_ref, values, (unsigned)full_len);
69716984 }
69726985 }
69736986 case ConstArraySpecialBuf: {
69746987 Buf *buf = const_val->data.x_array.data.s_buf;
6975 return LLVMConstString(buf_ptr(buf), (unsigned)buf_len(buf), true);
6988 return LLVMConstString(buf_ptr(buf), (unsigned)buf_len(buf),
6989 !type_entry->data.array.is_null_terminated);
69766990 }
69776991 }
69786992 zig_unreachable();
......@@ -9092,7 +9106,7 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) {
90929106 this_val->data.x_struct.fields = alloc_const_vals_ptrs(2);
90939107
90949108 ConstExprValue *name_field = this_val->data.x_struct.fields[0];
9095 ConstExprValue *name_array_val = create_const_str_lit(g, &test_fn_entry->symbol_name);
9109 ConstExprValue *name_array_val = create_const_str_lit(g, &test_fn_entry->symbol_name)->data.x_ptr.data.ref.pointee;
90969110 init_const_slice(g, name_field, name_array_val, 0, buf_len(&test_fn_entry->symbol_name), true);
90979111
90989112 ConstExprValue *fn_field = this_val->data.x_struct.fields[1];
......@@ -10415,6 +10429,7 @@ CodeGen *codegen_create(Buf *main_pkg_path, Buf *root_src_path, const ZigTarget
1041510429 g->external_prototypes.init(8);
1041610430 g->string_literals_table.init(16);
1041710431 g->type_info_cache.init(32);
10432 g->one_possible_values.init(32);
1041810433 g->is_test_build = is_test_build;
1041910434 g->is_single_threaded = false;
1042010435 buf_resize(&g->global_asm, 0);
src/ir.cpp+321-127
......@@ -66,6 +66,8 @@ enum ConstCastResultId {
6666 ConstCastResultIdUnresolvedInferredErrSet,
6767 ConstCastResultIdAsyncAllocatorType,
6868 ConstCastResultIdBadAllowsZero,
69 ConstCastResultIdArrayChild,
70 ConstCastResultIdBadNullTermArrays,
6971};
7072
7173struct ConstCastOnly;
......@@ -87,7 +89,9 @@ struct ConstCastErrUnionErrSetMismatch;
8789struct ConstCastErrUnionPayloadMismatch;
8890struct ConstCastErrSetMismatch;
8991struct ConstCastTypeMismatch;
92struct ConstCastArrayMismatch;
9093struct ConstCastBadAllowsZero;
94struct ConstCastBadNullTermArrays;
9195
9296struct ConstCastOnly {
9397 ConstCastResultId id;
......@@ -99,11 +103,13 @@ struct ConstCastOnly {
99103 ConstCastErrUnionPayloadMismatch *error_union_payload;
100104 ConstCastErrUnionErrSetMismatch *error_union_error_set;
101105 ConstCastTypeMismatch *type_mismatch;
106 ConstCastArrayMismatch *array_mismatch;
102107 ConstCastOnly *return_type;
103108 ConstCastOnly *null_wrap_ptr_child;
104109 ConstCastArg fn_arg;
105110 ConstCastArgNoAlias arg_no_alias;
106111 ConstCastBadAllowsZero *bad_allows_zero;
112 ConstCastBadNullTermArrays *bad_null_term_arrays;
107113 } data;
108114};
109115
......@@ -130,6 +136,12 @@ struct ConstCastSliceMismatch {
130136 ZigType *actual_child;
131137};
132138
139struct ConstCastArrayMismatch {
140 ConstCastOnly child;
141 ZigType *wanted_child;
142 ZigType *actual_child;
143};
144
133145struct ConstCastErrUnionErrSetMismatch {
134146 ConstCastOnly child;
135147 ZigType *wanted_err_set;
......@@ -151,6 +163,12 @@ struct ConstCastBadAllowsZero {
151163 ZigType *actual_type;
152164};
153165
166struct ConstCastBadNullTermArrays {
167 ConstCastOnly child;
168 ZigType *wanted_type;
169 ZigType *actual_type;
170};
171
154172
155173static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope);
156174static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *scope, LVal lval,
......@@ -217,10 +235,7 @@ static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *c
217235 case OnePossibleValueInvalid:
218236 zig_unreachable();
219237 case OnePossibleValueYes:
220 result = create_const_vals(1);
221 result->type = const_val->type->data.pointer.child_type;
222 result->special = ConstValSpecialStatic;
223 return result;
238 return get_the_one_possible_value(g, const_val->type->data.pointer.child_type);
224239 case OnePossibleValueNo:
225240 break;
226241 }
......@@ -233,8 +248,13 @@ static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *c
233248 break;
234249 case ConstPtrSpecialBaseArray: {
235250 ConstExprValue *array_val = const_val->data.x_ptr.data.base_array.array_val;
236 expand_undef_array(g, array_val);
237 result = &array_val->data.x_array.data.s_none.elements[const_val->data.x_ptr.data.base_array.elem_index];
251 if (const_val->data.x_ptr.data.base_array.elem_index == array_val->type->data.array.len) {
252 assert(array_val->type->data.array.is_null_terminated);
253 result = get_null_value(array_val->type->data.array.child_type);
254 } else {
255 expand_undef_array(g, array_val);
256 result = &array_val->data.x_array.data.s_none.elements[const_val->data.x_ptr.data.base_array.elem_index];
257 }
238258 break;
239259 }
240260 case ConstPtrSpecialBaseStruct: {
......@@ -282,20 +302,20 @@ static bool slice_is_const(ZigType *type) {
282302
283303// This function returns true when you can change the type of a ConstExprValue and the
284304// value remains meaningful.
285static bool types_have_same_zig_comptime_repr(ZigType *a, ZigType *b) {
286 if (a == b)
305static bool types_have_same_zig_comptime_repr(ZigType *expected, ZigType *actual) {
306 if (expected == actual)
287307 return true;
288308
289 if (get_codegen_ptr_type(a) != nullptr && get_codegen_ptr_type(b) != nullptr)
309 if (get_codegen_ptr_type(expected) != nullptr && get_codegen_ptr_type(actual) != nullptr)
290310 return true;
291311
292 if (is_opt_err_set(a) && is_opt_err_set(b))
312 if (is_opt_err_set(expected) && is_opt_err_set(actual))
293313 return true;
294314
295 if (a->id != b->id)
315 if (expected->id != actual->id)
296316 return false;
297317
298 switch (a->id) {
318 switch (expected->id) {
299319 case ZigTypeIdInvalid:
300320 case ZigTypeIdUnreachable:
301321 zig_unreachable();
......@@ -314,12 +334,11 @@ static bool types_have_same_zig_comptime_repr(ZigType *a, ZigType *b) {
314334 case ZigTypeIdAnyFrame:
315335 return true;
316336 case ZigTypeIdFloat:
317 return a->data.floating.bit_count == b->data.floating.bit_count;
337 return expected->data.floating.bit_count == actual->data.floating.bit_count;
318338 case ZigTypeIdInt:
319 return a->data.integral.is_signed == b->data.integral.is_signed;
339 return expected->data.integral.is_signed == actual->data.integral.is_signed;
320340 case ZigTypeIdStruct:
321 return is_slice(a) && is_slice(b);
322 case ZigTypeIdArray:
341 return is_slice(expected) && is_slice(actual);
323342 case ZigTypeIdOptional:
324343 case ZigTypeIdErrorUnion:
325344 case ZigTypeIdEnum:
......@@ -329,6 +348,10 @@ static bool types_have_same_zig_comptime_repr(ZigType *a, ZigType *b) {
329348 case ZigTypeIdVector:
330349 case ZigTypeIdFnFrame:
331350 return false;
351 case ZigTypeIdArray:
352 return expected->data.array.len == actual->data.array.len &&
353 expected->data.array.child_type == actual->data.array.child_type &&
354 (!expected->data.array.is_null_terminated || actual->data.array.is_null_terminated);
332355 }
333356 zig_unreachable();
334357}
......@@ -1299,12 +1322,6 @@ static IrInstruction *ir_build_const_str_lit(IrBuilder *irb, Scope *scope, AstNo
12991322 return instruction;
13001323}
13011324
1302static IrInstruction *ir_build_const_c_str_lit(IrBuilder *irb, Scope *scope, AstNode *source_node, Buf *str) {
1303 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
1304 init_const_c_str_lit(irb->codegen, &const_instruction->base.value, str);
1305 return &const_instruction->base;
1306}
1307
13081325static IrInstruction *ir_build_bin_op(IrBuilder *irb, Scope *scope, AstNode *source_node, IrBinOp op_id,
13091326 IrInstruction *op1, IrInstruction *op2, bool safety_check_on)
13101327{
......@@ -6932,11 +6949,7 @@ static IrInstruction *ir_gen_enum_literal(IrBuilder *irb, Scope *scope, AstNode
69326949static IrInstruction *ir_gen_string_literal(IrBuilder *irb, Scope *scope, AstNode *node) {
69336950 assert(node->type == NodeTypeStringLiteral);
69346951
6935 if (node->data.string_literal.c) {
6936 return ir_build_const_c_str_lit(irb, scope, node, node->data.string_literal.buf);
6937 } else {
6938 return ir_build_const_str_lit(irb, scope, node, node->data.string_literal.buf);
6939 }
6952 return ir_build_const_str_lit(irb, scope, node, node->data.string_literal.buf);
69406953}
69416954
69426955static IrInstruction *ir_gen_array_type(IrBuilder *irb, Scope *scope, AstNode *node) {
......@@ -8662,7 +8675,15 @@ ConstExprValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ConstExprVal
86628675 assert(val != nullptr);
86638676 assert(const_val->type->id == ZigTypeIdPointer);
86648677 ZigType *expected_type = const_val->type->data.pointer.child_type;
8665 if (!types_have_same_zig_comptime_repr(val->type, expected_type)) {
8678 switch (type_has_one_possible_value(codegen, expected_type)) {
8679 case OnePossibleValueInvalid:
8680 return nullptr;
8681 case OnePossibleValueNo:
8682 break;
8683 case OnePossibleValueYes:
8684 return get_the_one_possible_value(codegen, expected_type);
8685 }
8686 if (!types_have_same_zig_comptime_repr(expected_type, val->type)) {
86668687 if ((err = eval_comptime_ptr_reinterpret(ira, codegen, source_node, const_val)))
86678688 return nullptr;
86688689 return const_ptr_pointee_unchecked(codegen, const_val);
......@@ -9876,6 +9897,35 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
98769897 }
98779898 }
98789899
9900 // arrays
9901 if (wanted_type->id == ZigTypeIdArray && actual_type->id == ZigTypeIdArray &&
9902 wanted_type->data.array.len == actual_type->data.array.len)
9903 {
9904 ConstCastOnly child = types_match_const_cast_only(ira, wanted_type->data.array.child_type,
9905 actual_type->data.array.child_type, source_node, wanted_is_mutable);
9906 if (child.id == ConstCastResultIdInvalid)
9907 return child;
9908 if (child.id != ConstCastResultIdOk) {
9909 result.id = ConstCastResultIdArrayChild;
9910 result.data.array_mismatch = allocate_nonzero<ConstCastArrayMismatch>(1);
9911 result.data.array_mismatch->child = child;
9912 result.data.array_mismatch->wanted_child = wanted_type->data.array.child_type;
9913 result.data.array_mismatch->actual_child = actual_type->data.array.child_type;
9914 return result;
9915 }
9916 bool ok_null_terminated = !wanted_type->data.array.is_null_terminated ||
9917 actual_type->data.array.is_null_terminated;
9918 if (!ok_null_terminated) {
9919 result.id = ConstCastResultIdBadNullTermArrays;
9920 result.data.bad_null_term_arrays = allocate_nonzero<ConstCastBadNullTermArrays>(1);
9921 result.data.bad_null_term_arrays->child = child;
9922 result.data.bad_null_term_arrays->wanted_type = wanted_type;
9923 result.data.bad_null_term_arrays->actual_type = actual_type;
9924 return result;
9925 }
9926 return result;
9927 }
9928
98799929 // slice const
98809930 if (is_slice(wanted_type) && is_slice(actual_type)) {
98819931 ZigType *actual_ptr_type = actual_type->data.structure.fields[slice_ptr_index]->type_entry;
......@@ -10692,6 +10742,42 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1069210742 continue;
1069310743 }
1069410744
10745
10746 // *[N]T and *[M]T
10747 if (cur_type->id == ZigTypeIdPointer && cur_type->data.pointer.ptr_len == PtrLenSingle &&
10748 cur_type->data.pointer.child_type->id == ZigTypeIdArray &&
10749 prev_type->id == ZigTypeIdPointer && prev_type->data.pointer.ptr_len == PtrLenSingle &&
10750 prev_type->data.pointer.child_type->id == ZigTypeIdArray &&
10751 (cur_type->data.pointer.is_const || !prev_type->data.pointer.is_const ||
10752 prev_type->data.pointer.child_type->data.array.len == 0) &&
10753 (cur_type->data.pointer.child_type->data.array.is_null_terminated ||
10754 !prev_type->data.pointer.child_type->data.array.is_null_terminated) &&
10755 types_match_const_cast_only(ira,
10756 cur_type->data.pointer.child_type->data.array.child_type,
10757 prev_type->data.pointer.child_type->data.array.child_type,
10758 source_node, !cur_type->data.pointer.is_const).id == ConstCastResultIdOk)
10759 {
10760 prev_inst = cur_inst;
10761 convert_to_const_slice = true;
10762 continue;
10763 }
10764 if (prev_type->id == ZigTypeIdPointer && prev_type->data.pointer.ptr_len == PtrLenSingle &&
10765 prev_type->data.pointer.child_type->id == ZigTypeIdArray &&
10766 cur_type->id == ZigTypeIdPointer && cur_type->data.pointer.ptr_len == PtrLenSingle &&
10767 cur_type->data.pointer.child_type->id == ZigTypeIdArray &&
10768 (prev_type->data.pointer.is_const || !cur_type->data.pointer.is_const ||
10769 cur_type->data.pointer.child_type->data.array.len == 0) &&
10770 (prev_type->data.pointer.child_type->data.array.is_null_terminated ||
10771 !cur_type->data.pointer.child_type->data.array.is_null_terminated) &&
10772 types_match_const_cast_only(ira,
10773 prev_type->data.pointer.child_type->data.array.child_type,
10774 cur_type->data.pointer.child_type->data.array.child_type,
10775 source_node, !prev_type->data.pointer.is_const).id == ConstCastResultIdOk)
10776 {
10777 convert_to_const_slice = true;
10778 continue;
10779 }
10780
1069510781 // [N]T to []T
1069610782 if (prev_type->id == ZigTypeIdArray && is_slice(cur_type) &&
1069710783 (cur_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const ||
......@@ -10740,16 +10826,33 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1074010826 free(errors);
1074110827
1074210828 if (convert_to_const_slice) {
10743 assert(prev_inst->value.type->id == ZigTypeIdArray);
10744 ZigType *ptr_type = get_pointer_to_type_extra(
10745 ira->codegen, prev_inst->value.type->data.array.child_type,
10746 true, false, PtrLenUnknown,
10747 0, 0, 0, false);
10748 ZigType *slice_type = get_slice_type(ira->codegen, ptr_type);
10749 if (err_set_type != nullptr) {
10750 return get_error_union_type(ira->codegen, err_set_type, slice_type);
10829 if (prev_inst->value.type->id == ZigTypeIdArray) {
10830 ZigType *ptr_type = get_pointer_to_type_extra(
10831 ira->codegen, prev_inst->value.type->data.array.child_type,
10832 true, false, PtrLenUnknown,
10833 0, 0, 0, false);
10834 ZigType *slice_type = get_slice_type(ira->codegen, ptr_type);
10835 if (err_set_type != nullptr) {
10836 return get_error_union_type(ira->codegen, err_set_type, slice_type);
10837 } else {
10838 return slice_type;
10839 }
10840 } else if (prev_inst->value.type->id == ZigTypeIdPointer) {
10841 ZigType *array_type = prev_inst->value.type->data.pointer.child_type;
10842 src_assert(array_type->id == ZigTypeIdArray, source_node);
10843 ZigType *ptr_type = get_pointer_to_type_extra(
10844 ira->codegen, array_type->data.array.child_type,
10845 prev_inst->value.type->data.pointer.is_const, false,
10846 array_type->data.array.is_null_terminated ? PtrLenNull : PtrLenUnknown,
10847 0, 0, 0, false);
10848 ZigType *slice_type = get_slice_type(ira->codegen, ptr_type);
10849 if (err_set_type != nullptr) {
10850 return get_error_union_type(ira->codegen, err_set_type, slice_type);
10851 } else {
10852 return slice_type;
10853 }
1075110854 } else {
10752 return slice_type;
10855 zig_unreachable();
1075310856 }
1075410857 } else if (err_set_type != nullptr) {
1075510858 if (prev_inst->value.type->id == ZigTypeIdErrorSet) {
......@@ -10970,7 +11073,6 @@ static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira,
1097011073 result->value.data.x_ptr.mut = value->value.data.x_ptr.mut;
1097111074 result->value.data.x_ptr.data.base_array.array_val = pointee;
1097211075 result->value.data.x_ptr.data.base_array.elem_index = 0;
10973 result->value.data.x_ptr.data.base_array.is_cstr = false;
1097411076 return result;
1097511077 }
1097611078 }
......@@ -10982,31 +11084,31 @@ static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira,
1098211084}
1098311085
1098411086static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruction *source_instr,
10985 IrInstruction *value, ZigType *wanted_type, ResultLoc *result_loc)
11087 IrInstruction *array_ptr, ZigType *wanted_type, ResultLoc *result_loc)
1098611088{
1098711089 Error err;
1098811090
10989 if ((err = type_resolve(ira->codegen, value->value.type->data.pointer.child_type,
11091 if ((err = type_resolve(ira->codegen, array_ptr->value.type->data.pointer.child_type,
1099011092 ResolveStatusAlignmentKnown)))
1099111093 {
1099211094 return ira->codegen->invalid_instruction;
1099311095 }
1099411096
10995 wanted_type = adjust_slice_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, value->value.type));
11097 wanted_type = adjust_slice_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, array_ptr->value.type));
1099611098
10997 if (instr_is_comptime(value)) {
10998 ConstExprValue *pointee = const_ptr_pointee(ira, ira->codegen, &value->value, source_instr->source_node);
11099 if (instr_is_comptime(array_ptr)) {
11100 ConstExprValue *pointee = const_ptr_pointee(ira, ira->codegen, &array_ptr->value, source_instr->source_node);
1099911101 if (pointee == nullptr)
1100011102 return ira->codegen->invalid_instruction;
1100111103 if (pointee->special != ConstValSpecialRuntime) {
11002 assert(value->value.type->id == ZigTypeIdPointer);
11003 ZigType *array_type = value->value.type->data.pointer.child_type;
11104 assert(array_ptr->value.type->id == ZigTypeIdPointer);
11105 ZigType *array_type = array_ptr->value.type->data.pointer.child_type;
1100411106 assert(is_slice(wanted_type));
1100511107 bool is_const = wanted_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const;
1100611108
1100711109 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
1100811110 init_const_slice(ira->codegen, &result->value, pointee, 0, array_type->data.array.len, is_const);
11009 result->value.data.x_struct.fields[slice_ptr_index]->data.x_ptr.mut = value->value.data.x_ptr.mut;
11111 result->value.data.x_struct.fields[slice_ptr_index]->data.x_ptr.mut = array_ptr->value.data.x_ptr.mut;
1101011112 result->value.type = wanted_type;
1101111113 return result;
1101211114 }
......@@ -11018,7 +11120,7 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc
1101811120 if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) {
1101911121 return result_loc_inst;
1102011122 }
11021 return ir_build_ptr_of_array_to_slice(ira, source_instr, wanted_type, value, result_loc_inst);
11123 return ir_build_ptr_of_array_to_slice(ira, source_instr, wanted_type, array_ptr, result_loc_inst);
1102211124}
1102311125
1102411126static IrBasicBlock *ir_get_new_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrInstruction *ref_old_instruction) {
......@@ -12483,6 +12585,8 @@ static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCa
1248312585 case ConstCastResultIdFnArgNoAlias: // TODO
1248412586 case ConstCastResultIdUnresolvedInferredErrSet: // TODO
1248512587 case ConstCastResultIdAsyncAllocatorType: // TODO
12588 case ConstCastResultIdArrayChild: // TODO
12589 case ConstCastResultIdBadNullTermArrays: // TODO
1248612590 break;
1248712591 }
1248812592}
......@@ -12795,7 +12899,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1279512899 return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type);
1279612900 }
1279712901
12798
1279912902 // cast from [N]T to []const T
1280012903 // TODO: once https://github.com/ziglang/zig/issues/265 lands, remove this
1280112904 if (is_slice(wanted_type) && actual_type->id == ZigTypeIdArray) {
......@@ -12834,23 +12937,46 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1283412937 }
1283512938 }
1283612939
12837 // *[N]T to [*]T and [*c]T
12838 if (wanted_type->id == ZigTypeIdPointer &&
12839 (wanted_type->data.pointer.ptr_len == PtrLenUnknown || wanted_type->data.pointer.ptr_len == PtrLenC) &&
12940 // *[N]T to ?[]const T
12941 if (wanted_type->id == ZigTypeIdOptional &&
12942 is_slice(wanted_type->data.maybe.child_type) &&
1284012943 actual_type->id == ZigTypeIdPointer &&
1284112944 actual_type->data.pointer.ptr_len == PtrLenSingle &&
1284212945 actual_type->data.pointer.child_type->id == ZigTypeIdArray)
1284312946 {
12844 if ((err = type_resolve(ira->codegen, actual_type->data.pointer.child_type, ResolveStatusAlignmentKnown)))
12947 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.maybe.child_type, value, nullptr);
12948 if (type_is_invalid(cast1->value.type))
1284512949 return ira->codegen->invalid_instruction;
12846 if ((err = type_resolve(ira->codegen, wanted_type->data.pointer.child_type, ResolveStatusAlignmentKnown)))
12950
12951 IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1, result_loc);
12952 if (type_is_invalid(cast2->value.type))
1284712953 return ira->codegen->invalid_instruction;
12848 if (get_ptr_align(ira->codegen, actual_type) >= get_ptr_align(ira->codegen, wanted_type) &&
12849 types_match_const_cast_only(ira, wanted_type->data.pointer.child_type,
12850 actual_type->data.pointer.child_type->data.array.child_type, source_node,
12851 !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk)
12954
12955 return cast2;
12956 }
12957
12958 // *[N]T to [*]T and [*c]T
12959 if (wanted_type->id == ZigTypeIdPointer &&
12960 (wanted_type->data.pointer.ptr_len == PtrLenUnknown || wanted_type->data.pointer.ptr_len == PtrLenC ||
12961 wanted_type->data.pointer.ptr_len == PtrLenNull) &&
12962 actual_type->id == ZigTypeIdPointer &&
12963 actual_type->data.pointer.ptr_len == PtrLenSingle &&
12964 actual_type->data.pointer.child_type->id == ZigTypeIdArray)
12965 {
12966 if (wanted_type->data.pointer.ptr_len != PtrLenNull ||
12967 actual_type->data.pointer.child_type->data.array.is_null_terminated)
1285212968 {
12853 return ir_resolve_ptr_of_array_to_unknown_len_ptr(ira, source_instr, value, wanted_type);
12969 if ((err = type_resolve(ira->codegen, actual_type->data.pointer.child_type, ResolveStatusAlignmentKnown)))
12970 return ira->codegen->invalid_instruction;
12971 if ((err = type_resolve(ira->codegen, wanted_type->data.pointer.child_type, ResolveStatusAlignmentKnown)))
12972 return ira->codegen->invalid_instruction;
12973 if (get_ptr_align(ira->codegen, actual_type) >= get_ptr_align(ira->codegen, wanted_type) &&
12974 types_match_const_cast_only(ira, wanted_type->data.pointer.child_type,
12975 actual_type->data.pointer.child_type->data.array.child_type, source_node,
12976 !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk)
12977 {
12978 return ir_resolve_ptr_of_array_to_unknown_len_ptr(ira, source_instr, value, wanted_type);
12979 }
1285412980 }
1285512981 }
1285612982
......@@ -14544,8 +14670,6 @@ static bool ok_float_op(IrBinOp op) {
1454414670}
1454514671
1454614672static bool is_pointer_arithmetic_allowed(ZigType *lhs_type, IrBinOp op) {
14547 if (lhs_type->id != ZigTypeIdPointer)
14548 return false;
1454914673 switch (op) {
1455014674 case IrBinOpAdd:
1455114675 case IrBinOpSub:
......@@ -14553,15 +14677,17 @@ static bool is_pointer_arithmetic_allowed(ZigType *lhs_type, IrBinOp op) {
1455314677 default:
1455414678 return false;
1455514679 }
14680 if (lhs_type->id != ZigTypeIdPointer)
14681 return false;
1455614682 switch (lhs_type->data.pointer.ptr_len) {
1455714683 case PtrLenSingle:
14558 return false;
14684 return lhs_type->data.pointer.child_type->id == ZigTypeIdArray;
1455914685 case PtrLenUnknown:
1456014686 case PtrLenNull:
1456114687 case PtrLenC:
14562 break;
14688 return true;
1456314689 }
14564 return true;
14690 zig_unreachable();
1456514691}
1456614692
1456714693static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp *instruction) {
......@@ -14823,6 +14949,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
1482314949 if (!op2_val)
1482414950 return ira->codegen->invalid_instruction;
1482514951
14952 bool is_null_terminated = false;
1482614953 ConstExprValue *op1_array_val;
1482714954 size_t op1_array_index;
1482814955 size_t op1_array_end;
......@@ -14834,13 +14961,14 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
1483414961 op1_array_end = op1_type->data.array.len;
1483514962 } else if (op1_type->id == ZigTypeIdPointer &&
1483614963 op1_type->data.pointer.child_type == ira->codegen->builtin_types.entry_u8 &&
14837 op1_val->data.x_ptr.special == ConstPtrSpecialBaseArray &&
14838 op1_val->data.x_ptr.data.base_array.is_cstr)
14964 op1_type->data.pointer.ptr_len == PtrLenNull &&
14965 op1_val->data.x_ptr.special == ConstPtrSpecialBaseArray)
1483914966 {
1484014967 child_type = op1_type->data.pointer.child_type;
1484114968 op1_array_val = op1_val->data.x_ptr.data.base_array.array_val;
1484214969 op1_array_index = op1_val->data.x_ptr.data.base_array.elem_index;
14843 op1_array_end = op1_array_val->type->data.array.len - 1;
14970 op1_array_end = op1_array_val->type->data.array.len;
14971 is_null_terminated = true;
1484414972 } else if (is_slice(op1_type)) {
1484514973 ZigType *ptr_type = op1_type->data.structure.fields[slice_ptr_index]->type_entry;
1484614974 child_type = ptr_type->data.pointer.child_type;
......@@ -14850,9 +14978,20 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
1485014978 op1_array_index = ptr_val->data.x_ptr.data.base_array.elem_index;
1485114979 ConstExprValue *len_val = op1_val->data.x_struct.fields[slice_len_index];
1485214980 op1_array_end = op1_array_index + bigint_as_usize(&len_val->data.x_bigint);
14981 } else if (op1_type->id == ZigTypeIdPointer && op1_type->data.pointer.ptr_len == PtrLenSingle &&
14982 op1_type->data.pointer.child_type->id == ZigTypeIdArray)
14983 {
14984 ZigType *array_type = op1_type->data.pointer.child_type;
14985 child_type = array_type->data.array.child_type;
14986 op1_array_val = const_ptr_pointee(ira, ira->codegen, op1_val, op1->source_node);
14987 if (op1_array_val == nullptr)
14988 return ira->codegen->invalid_instruction;
14989 op1_array_index = 0;
14990 op1_array_end = array_type->data.array.len;
14991 is_null_terminated = is_null_terminated || array_type->data.array.is_null_terminated;
1485314992 } else {
1485414993 ir_add_error(ira, op1,
14855 buf_sprintf("expected array or C string literal, found '%s'", buf_ptr(&op1->value.type->name)));
14994 buf_sprintf("expected array, found '%s'", buf_ptr(&op1->value.type->name)));
1485614995 return ira->codegen->invalid_instruction;
1485714996 }
1485814997
......@@ -14866,14 +15005,14 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
1486615005 op2_array_index = 0;
1486715006 op2_array_end = op2_array_val->type->data.array.len;
1486815007 } else if (op2_type->id == ZigTypeIdPointer &&
14869 op2_type->data.pointer.child_type == ira->codegen->builtin_types.entry_u8 &&
14870 op2_val->data.x_ptr.special == ConstPtrSpecialBaseArray &&
14871 op2_val->data.x_ptr.data.base_array.is_cstr)
15008 op2_type->data.pointer.ptr_len == PtrLenNull &&
15009 op2_val->data.x_ptr.special == ConstPtrSpecialBaseArray)
1487215010 {
14873 op2_type_valid = child_type == ira->codegen->builtin_types.entry_u8;
15011 op2_type_valid = op2_type->data.pointer.child_type == child_type;
1487415012 op2_array_val = op2_val->data.x_ptr.data.base_array.array_val;
1487515013 op2_array_index = op2_val->data.x_ptr.data.base_array.elem_index;
14876 op2_array_end = op2_array_val->type->data.array.len - 1;
15014 op2_array_end = op2_array_val->type->data.array.len;
15015 is_null_terminated = true;
1487715016 } else if (is_slice(op2_type)) {
1487815017 ZigType *ptr_type = op2_type->data.structure.fields[slice_ptr_index]->type_entry;
1487915018 op2_type_valid = ptr_type->data.pointer.child_type == child_type;
......@@ -14883,6 +15022,17 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
1488315022 op2_array_index = ptr_val->data.x_ptr.data.base_array.elem_index;
1488415023 ConstExprValue *len_val = op2_val->data.x_struct.fields[slice_len_index];
1488515024 op2_array_end = op2_array_index + bigint_as_usize(&len_val->data.x_bigint);
15025 } else if (op2_type->id == ZigTypeIdPointer && op2_type->data.pointer.ptr_len == PtrLenSingle &&
15026 op2_type->data.pointer.child_type->id == ZigTypeIdArray)
15027 {
15028 ZigType *array_type = op2_type->data.pointer.child_type;
15029 op2_type_valid = array_type->data.array.child_type == child_type;
15030 op2_array_val = const_ptr_pointee(ira, ira->codegen, op2_val, op2->source_node);
15031 if (op2_array_val == nullptr)
15032 return ira->codegen->invalid_instruction;
15033 op2_array_index = 0;
15034 op2_array_end = array_type->data.array.len;
15035 is_null_terminated = is_null_terminated || array_type->data.array.is_null_terminated;
1488615036 } else {
1488715037 ir_add_error(ira, op2,
1488815038 buf_sprintf("expected array or C string literal, found '%s'", buf_ptr(&op2->value.type->name)));
......@@ -14905,6 +15055,14 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
1490515055 result->value.type = get_array_type(ira->codegen, child_type, new_len, false);
1490615056
1490715057 out_array_val = out_val;
15058 } else if (op1_type->id == ZigTypeIdPointer || op2_type->id == ZigTypeIdPointer) {
15059 out_array_val = create_const_vals(1);
15060 out_array_val->special = ConstValSpecialStatic;
15061 out_array_val->type = get_array_type(ira->codegen, child_type, new_len, is_null_terminated);
15062
15063 out_val->data.x_ptr.special = ConstPtrSpecialRef;
15064 out_val->data.x_ptr.data.ref.pointee = out_array_val;
15065 out_val->type = get_pointer_to_type(ira->codegen, out_array_val->type, true);
1490815066 } else if (is_slice(op1_type) || is_slice(op2_type)) {
1490915067 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, child_type,
1491015068 true, false, PtrLenUnknown, 0, 0, 0, false);
......@@ -14925,22 +15083,20 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
1492515083 out_val->data.x_struct.fields[slice_len_index]->special = ConstValSpecialStatic;
1492615084 bigint_init_unsigned(&out_val->data.x_struct.fields[slice_len_index]->data.x_bigint, new_len);
1492715085 } else {
14928 new_len += 1; // null byte
14929
14930 // TODO make this `[*]null T` instead of `[*]T`
14931 result->value.type = get_pointer_to_type_extra(ira->codegen, child_type, true, false, PtrLenUnknown, 0, 0, 0, false);
15086 result->value.type = get_pointer_to_type_extra(ira->codegen, child_type, true, false, PtrLenNull,
15087 0, 0, 0, false);
1493215088
1493315089 out_array_val = create_const_vals(1);
1493415090 out_array_val->special = ConstValSpecialStatic;
1493515091 out_array_val->type = get_array_type(ira->codegen, child_type, new_len, false);
1493615092 out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;
14937 out_val->data.x_ptr.data.base_array.is_cstr = true;
1493815093 out_val->data.x_ptr.data.base_array.array_val = out_array_val;
1493915094 out_val->data.x_ptr.data.base_array.elem_index = 0;
1494015095 }
1494115096
1494215097 if (op1_array_val->data.x_array.special == ConstArraySpecialUndef &&
14943 op2_array_val->data.x_array.special == ConstArraySpecialUndef) {
15098 op2_array_val->data.x_array.special == ConstArraySpecialUndef)
15099 {
1494415100 out_array_val->data.x_array.special = ConstArraySpecialUndef;
1494515101 return result;
1494615102 }
......@@ -14978,20 +15134,34 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *
1497815134 if (type_is_invalid(op2->value.type))
1497915135 return ira->codegen->invalid_instruction;
1498015136
14981 ConstExprValue *array_val = ir_resolve_const(ira, op1, UndefBad);
14982 if (!array_val)
15137 bool want_ptr_to_array = false;
15138 ZigType *array_type;
15139 ConstExprValue *array_val;
15140 if (op1->value.type->id == ZigTypeIdArray) {
15141 array_type = op1->value.type;
15142 array_val = ir_resolve_const(ira, op1, UndefOk);
15143 if (array_val == nullptr)
15144 return ira->codegen->invalid_instruction;
15145 } else if (op1->value.type->id == ZigTypeIdPointer && op1->value.type->data.pointer.ptr_len == PtrLenSingle &&
15146 op1->value.type->data.pointer.child_type->id == ZigTypeIdArray)
15147 {
15148 array_type = op1->value.type->data.pointer.child_type;
15149 IrInstruction *array_inst = ir_get_deref(ira, op1, op1, nullptr);
15150 if (type_is_invalid(array_inst->value.type))
15151 return ira->codegen->invalid_instruction;
15152 array_val = ir_resolve_const(ira, array_inst, UndefOk);
15153 if (array_val == nullptr)
15154 return ira->codegen->invalid_instruction;
15155 want_ptr_to_array = true;
15156 } else {
15157 ir_add_error(ira, op1, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->value.type->name)));
1498315158 return ira->codegen->invalid_instruction;
15159 }
1498415160
1498515161 uint64_t mult_amt;
1498615162 if (!ir_resolve_usize(ira, op2, &mult_amt))
1498715163 return ira->codegen->invalid_instruction;
1498815164
14989 ZigType *array_type = op1->value.type;
14990 if (array_type->id != ZigTypeIdArray) {
14991 ir_add_error(ira, op1, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->value.type->name)));
14992 return ira->codegen->invalid_instruction;
14993 }
14994
1499515165 uint64_t old_array_len = array_type->data.array.len;
1499615166 uint64_t new_array_len;
1499715167
......@@ -15001,42 +15171,59 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *
1500115171 }
1500215172
1500315173 ZigType *child_type = array_type->data.array.child_type;
15174 ZigType *result_array_type = get_array_type(ira->codegen, child_type, new_array_len,
15175 array_type->data.array.is_null_terminated);
1500415176
15005 IrInstruction *result = ir_const(ira, &instruction->base,
15006 get_array_type(ira->codegen, child_type, new_array_len, false));
15007 ConstExprValue *out_val = &result->value;
15008 if (array_val->data.x_array.special == ConstArraySpecialUndef) {
15009 out_val->data.x_array.special = ConstArraySpecialUndef;
15010 return result;
15011 }
15177 IrInstruction *array_result;
15178 if (array_val->special == ConstValSpecialUndef || array_val->data.x_array.special == ConstArraySpecialUndef) {
15179 array_result = ir_const_undef(ira, &instruction->base, result_array_type);
15180 } else {
15181 array_result = ir_const(ira, &instruction->base, result_array_type);
15182 ConstExprValue *out_val = &array_result->value;
1501215183
15013 switch (type_has_one_possible_value(ira->codegen, result->value.type)) {
15014 case OnePossibleValueInvalid:
15015 return ira->codegen->invalid_instruction;
15016 case OnePossibleValueYes:
15017 return result;
15018 case OnePossibleValueNo:
15019 break;
15020 }
15184 switch (type_has_one_possible_value(ira->codegen, result_array_type)) {
15185 case OnePossibleValueInvalid:
15186 return ira->codegen->invalid_instruction;
15187 case OnePossibleValueYes:
15188 goto skip_computation;
15189 case OnePossibleValueNo:
15190 break;
15191 }
1502115192
15022 // TODO optimize the buf case
15023 expand_undef_array(ira->codegen, array_val);
15024 out_val->data.x_array.data.s_none.elements = create_const_vals(new_array_len);
15193 // TODO optimize the buf case
15194 expand_undef_array(ira->codegen, array_val);
15195 size_t extra_null_term = array_type->data.array.is_null_terminated ? 1 : 0;
15196 out_val->data.x_array.data.s_none.elements = create_const_vals(new_array_len + extra_null_term);
1502515197
15026 uint64_t i = 0;
15027 for (uint64_t x = 0; x < mult_amt; x += 1) {
15028 for (uint64_t y = 0; y < old_array_len; y += 1) {
15198 uint64_t i = 0;
15199 for (uint64_t x = 0; x < mult_amt; x += 1) {
15200 for (uint64_t y = 0; y < old_array_len; y += 1) {
15201 ConstExprValue *elem_dest_val = &out_val->data.x_array.data.s_none.elements[i];
15202 copy_const_val(elem_dest_val, &array_val->data.x_array.data.s_none.elements[y], false);
15203 elem_dest_val->parent.id = ConstParentIdArray;
15204 elem_dest_val->parent.data.p_array.array_val = out_val;
15205 elem_dest_val->parent.data.p_array.elem_index = i;
15206 i += 1;
15207 }
15208 }
15209 assert(i == new_array_len);
15210
15211 if (array_type->data.array.is_null_terminated) {
15212 ConstExprValue *null_value = get_null_value(array_type->data.array.child_type);
1502915213 ConstExprValue *elem_dest_val = &out_val->data.x_array.data.s_none.elements[i];
15030 copy_const_val(elem_dest_val, &array_val->data.x_array.data.s_none.elements[y], false);
15214 copy_const_val(elem_dest_val, null_value, false);
1503115215 elem_dest_val->parent.id = ConstParentIdArray;
1503215216 elem_dest_val->parent.data.p_array.array_val = out_val;
1503315217 elem_dest_val->parent.data.p_array.elem_index = i;
1503415218 i += 1;
1503515219 }
1503615220 }
15037 assert(i == new_array_len);
15038
15039 return result;
15221skip_computation:
15222 if (want_ptr_to_array) {
15223 return ir_get_ref(ira, &instruction->base, array_result, true, false);
15224 } else {
15225 return array_result;
15226 }
1504015227}
1504115228
1504215229static IrInstruction *ir_analyze_instruction_merge_err_sets(IrAnalyze *ira,
......@@ -17309,6 +17496,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source
1730917496 assert(out_val->type != nullptr);
1731017497
1731117498 ConstExprValue *pointee = const_ptr_pointee_unchecked(codegen, ptr_val);
17499 src_assert(pointee->type != nullptr, source_node);
1731217500
1731317501 if ((err = type_resolve(codegen, pointee->type, ResolveStatusSizeKnown)))
1731417502 return ErrorSemanticAnalyzeFail;
......@@ -17319,7 +17507,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source
1731917507 size_t dst_size = type_size(codegen, out_val->type);
1732017508
1732117509 if (dst_size <= src_size) {
17322 if (src_size == dst_size && types_have_same_zig_comptime_repr(pointee->type, out_val->type)) {
17510 if (src_size == dst_size && types_have_same_zig_comptime_repr(out_val->type, pointee->type)) {
1732317511 copy_const_val(out_val, pointee, ptr_val->data.x_ptr.mut != ConstPtrMutComptimeVar);
1732417512 return ErrorNone;
1732517513 }
......@@ -18070,6 +18258,12 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1807018258 uint64_t index = bigint_as_u64(&casted_elem_index->value.data.x_bigint);
1807118259 if (array_type->id == ZigTypeIdArray) {
1807218260 uint64_t array_len = array_type->data.array.len;
18261 if (index == array_len && array_type->data.array.is_null_terminated) {
18262 ZigType *elem_type = array_type->data.array.child_type;
18263 IrInstruction *null_element = ir_const(ira, &elem_ptr_instruction->base, elem_type);
18264 null_element->value = *get_null_value(elem_type);
18265 return ir_get_ref(ira, &elem_ptr_instruction->base, null_element, true, false);
18266 }
1807318267 if (index >= array_len) {
1807418268 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
1807518269 buf_sprintf("index %" ZIG_PRI_u64 " outside array of size %" ZIG_PRI_u64,
......@@ -18203,7 +18397,11 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1820318397 {
1820418398 size_t offset = array_ptr_val->data.x_ptr.data.base_array.elem_index;
1820518399 new_index = offset + index;
18206 mem_size = array_ptr_val->data.x_ptr.data.base_array.array_val->type->data.array.len;
18400 ZigType *array_type = array_ptr_val->data.x_ptr.data.base_array.array_val->type;
18401 mem_size = array_type->data.array.len;
18402 if (array_type->data.array.is_null_terminated) {
18403 mem_size += 1;
18404 }
1820718405 old_size = mem_size - offset;
1820818406
1820918407 assert(array_ptr_val->data.x_ptr.data.base_array.array_val);
......@@ -18212,8 +18410,6 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1821218410 out_val->data.x_ptr.data.base_array.array_val =
1821318411 array_ptr_val->data.x_ptr.data.base_array.array_val;
1821418412 out_val->data.x_ptr.data.base_array.elem_index = new_index;
18215 out_val->data.x_ptr.data.base_array.is_cstr =
18216 array_ptr_val->data.x_ptr.data.base_array.is_cstr;
1821718413
1821818414 break;
1821918415 }
......@@ -18277,8 +18473,6 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1827718473 out_val->data.x_ptr.data.base_array.array_val =
1827818474 ptr_field->data.x_ptr.data.base_array.array_val;
1827918475 out_val->data.x_ptr.data.base_array.elem_index = new_index;
18280 out_val->data.x_ptr.data.base_array.is_cstr =
18281 ptr_field->data.x_ptr.data.base_array.is_cstr;
1828218476 break;
1828318477 }
1828418478 case ConstPtrSpecialBaseStruct:
......@@ -19550,7 +19744,7 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr
1955019744 ZigType *result_type = get_pointer_to_type_extra(ira->codegen, child_type,
1955119745 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, PtrLenSingle, 0, 0, 0, false);
1955219746
19553 bool same_comptime_repr = types_have_same_zig_comptime_repr(type_entry, child_type);
19747 bool same_comptime_repr = types_have_same_zig_comptime_repr(child_type, type_entry);
1955419748
1955519749 if (instr_is_comptime(base_ptr)) {
1955619750 ConstExprValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad);
......@@ -20685,7 +20879,7 @@ static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruct
2068520879 return ira->codegen->invalid_instruction;
2068620880 ErrorTableEntry *err = casted_value->value.data.x_err_set;
2068720881 if (!err->cached_error_name_val) {
20688 ConstExprValue *array_val = create_const_str_lit(ira->codegen, &err->name);
20882 ConstExprValue *array_val = create_const_str_lit(ira->codegen, &err->name)->data.x_ptr.data.ref.pointee;
2068920883 err->cached_error_name_val = create_const_slice(ira->codegen, array_val, 0, buf_len(&err->name), true);
2069020884 }
2069120885 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
......@@ -20714,7 +20908,7 @@ static IrInstruction *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrIns
2071420908 if ((err = type_resolve(ira->codegen, target->value.type, ResolveStatusZeroBitsKnown)))
2071520909 return ira->codegen->invalid_instruction;
2071620910 TypeEnumField *field = find_enum_field_by_tag(target->value.type, &target->value.data.x_bigint);
20717 ConstExprValue *array_val = create_const_str_lit(ira->codegen, field->name);
20911 ConstExprValue *array_val = create_const_str_lit(ira->codegen, field->name)->data.x_ptr.data.ref.pointee;
2071820912 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
2071920913 init_const_slice(ira->codegen, &result->value, array_val, 0, buf_len(field->name), true);
2072020914 return result;
......@@ -21019,7 +21213,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
2101921213 declaration_val->type = type_info_declaration_type;
2102021214
2102121215 ConstExprValue **inner_fields = alloc_const_vals_ptrs(3);
21022 ConstExprValue *name = create_const_str_lit(ira->codegen, curr_entry->key);
21216 ConstExprValue *name = create_const_str_lit(ira->codegen, curr_entry->key)->data.x_ptr.data.ref.pointee;
2102321217 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(curr_entry->key), true);
2102421218 inner_fields[1]->special = ConstValSpecialStatic;
2102521219 inner_fields[1]->type = ira->codegen->builtin_types.entry_bool;
......@@ -21122,7 +21316,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
2112221316 fn_decl_fields[6]->type = get_optional_type(ira->codegen, get_slice_type(ira->codegen, u8_ptr));
2112321317 if (fn_node->is_extern && fn_node->lib_name != nullptr && buf_len(fn_node->lib_name) > 0) {
2112421318 fn_decl_fields[6]->data.x_optional = create_const_vals(1);
21125 ConstExprValue *lib_name = create_const_str_lit(ira->codegen, fn_node->lib_name);
21319 ConstExprValue *lib_name = create_const_str_lit(ira->codegen, fn_node->lib_name)->data.x_ptr.data.ref.pointee;
2112621320 init_const_slice(ira->codegen, fn_decl_fields[6]->data.x_optional, lib_name, 0,
2112721321 buf_len(fn_node->lib_name), true);
2112821322 } else {
......@@ -21149,7 +21343,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
2114921343 ZigVar *arg_var = fn_entry->variable_list.at(fn_arg_index);
2115021344 ConstExprValue *fn_arg_name_val = &fn_arg_name_array->data.x_array.data.s_none.elements[fn_arg_index];
2115121345 ConstExprValue *arg_name = create_const_str_lit(ira->codegen,
21152 buf_create_from_str(arg_var->name));
21346 buf_create_from_str(arg_var->name))->data.x_ptr.data.ref.pointee;
2115321347 init_const_slice(ira->codegen, fn_arg_name_val, arg_name, 0, strlen(arg_var->name), true);
2115421348 fn_arg_name_val->parent.id = ConstParentIdArray;
2115521349 fn_arg_name_val->parent.data.p_array.array_val = fn_arg_name_array;
......@@ -21294,7 +21488,7 @@ static void make_enum_field_val(IrAnalyze *ira, ConstExprValue *enum_field_val,
2129421488 inner_fields[1]->special = ConstValSpecialStatic;
2129521489 inner_fields[1]->type = ira->codegen->builtin_types.entry_num_lit_int;
2129621490
21297 ConstExprValue *name = create_const_str_lit(ira->codegen, enum_field->name);
21491 ConstExprValue *name = create_const_str_lit(ira->codegen, enum_field->name)->data.x_ptr.data.ref.pointee;
2129821492 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(enum_field->name), true);
2129921493
2130021494 bigint_init_bigint(&inner_fields[1]->data.x_bigint, &enum_field->value);
......@@ -21560,7 +21754,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2156021754 if (error->cached_error_name_val != nullptr)
2156121755 name = error->cached_error_name_val;
2156221756 if (name == nullptr)
21563 name = create_const_str_lit(ira->codegen, &error->name);
21757 name = create_const_str_lit(ira->codegen, &error->name)->data.x_ptr.data.ref.pointee;
2156421758 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(&error->name), true);
2156521759 bigint_init_unsigned(&inner_fields[1]->data.x_bigint, error->value);
2156621760
......@@ -21666,7 +21860,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2166621860 inner_fields[2]->type = ira->codegen->builtin_types.entry_type;
2166721861 inner_fields[2]->data.x_type = union_field->type_entry;
2166821862
21669 ConstExprValue *name = create_const_str_lit(ira->codegen, union_field->name);
21863 ConstExprValue *name = create_const_str_lit(ira->codegen, union_field->name)->data.x_ptr.data.ref.pointee;
2167021864 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(union_field->name), true);
2167121865
2167221866 union_field_val->data.x_struct.fields = inner_fields;
......@@ -21752,7 +21946,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2175221946 inner_fields[2]->type = ira->codegen->builtin_types.entry_type;
2175321947 inner_fields[2]->data.x_type = struct_field->type_entry;
2175421948
21755 ConstExprValue *name = create_const_str_lit(ira->codegen, struct_field->name);
21949 ConstExprValue *name = create_const_str_lit(ira->codegen, struct_field->name)->data.x_ptr.data.ref.pointee;
2175621950 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(struct_field->name), true);
2175721951
2175821952 struct_field_val->data.x_struct.fields = inner_fields;
src/parser.cpp-1
......@@ -1718,7 +1718,6 @@ static AstNode *ast_parse_primary_type_expr(ParseContext *pc) {
17181718 if (string_lit != nullptr) {
17191719 AstNode *res = ast_create_node(pc, NodeTypeStringLiteral, string_lit);
17201720 res->data.string_literal.buf = token_buf(string_lit);
1721 res->data.string_literal.c = string_lit->data.str_lit.is_c_str;
17221721 return res;
17231722 }
17241723
src/tokenizer.cpp+3-50
......@@ -33,10 +33,10 @@
3333 '0': \
3434 case DIGIT_NON_ZERO
3535
36#define ALPHA_EXCEPT_C \
36#define ALPHA \
3737 'a': \
3838 case 'b': \
39 /*case 'c':*/ \
39 case 'c': \
4040 case 'd': \
4141 case 'e': \
4242 case 'f': \
......@@ -87,10 +87,6 @@
8787 case 'Y': \
8888 case 'Z'
8989
90#define ALPHA \
91 ALPHA_EXCEPT_C: \
92 case 'c'
93
9490#define SYMBOL_CHAR \
9591 ALPHA: \
9692 case DIGIT: \
......@@ -180,7 +176,6 @@ static bool is_symbol_char(uint8_t c) {
180176enum TokenizeState {
181177 TokenizeStateStart,
182178 TokenizeStateSymbol,
183 TokenizeStateSymbolFirstC,
184179 TokenizeStateZero, // "0", which might lead to "0x"
185180 TokenizeStateNumber, // "123", "0x123"
186181 TokenizeStateNumberDot,
......@@ -279,7 +274,6 @@ static void set_token_id(Tokenize *t, Token *token, TokenId id) {
279274 } else if (id == TokenIdStringLiteral || id == TokenIdSymbol) {
280275 memset(&token->data.str_lit.str, 0, sizeof(Buf));
281276 buf_resize(&token->data.str_lit.str, 0);
282 token->data.str_lit.is_c_str = false;
283277 }
284278}
285279
......@@ -429,12 +423,7 @@ void tokenize(Buf *buf, Tokenization *out) {
429423 switch (c) {
430424 case WHITESPACE:
431425 break;
432 case 'c':
433 t.state = TokenizeStateSymbolFirstC;
434 begin_token(&t, TokenIdSymbol);
435 buf_append_char(&t.cur_tok->data.str_lit.str, c);
436 break;
437 case ALPHA_EXCEPT_C:
426 case ALPHA:
438427 case '_':
439428 t.state = TokenizeStateSymbol;
440429 begin_token(&t, TokenIdSymbol);
......@@ -1007,19 +996,7 @@ void tokenize(Buf *buf, Tokenization *out) {
1007996 switch (c) {
1008997 case WHITESPACE:
1009998 break;
1010 case 'c':
1011 if (!t.cur_tok->data.str_lit.is_c_str) {
1012 t.pos -= 1;
1013 end_token(&t);
1014 t.state = TokenizeStateStart;
1015 break;
1016 }
1017 t.state = TokenizeStateLineStringContinueC;
1018 break;
1019999 case '\\':
1020 if (t.cur_tok->data.str_lit.is_c_str) {
1021 invalid_char_error(&t, c);
1022 }
10231000 t.state = TokenizeStateLineStringContinue;
10241001 break;
10251002 default:
......@@ -1084,29 +1061,6 @@ void tokenize(Buf *buf, Tokenization *out) {
10841061 break;
10851062 }
10861063 break;
1087 case TokenizeStateSymbolFirstC:
1088 switch (c) {
1089 case '"':
1090 set_token_id(&t, t.cur_tok, TokenIdStringLiteral);
1091 t.cur_tok->data.str_lit.is_c_str = true;
1092 t.state = TokenizeStateString;
1093 break;
1094 case '\\':
1095 set_token_id(&t, t.cur_tok, TokenIdStringLiteral);
1096 t.cur_tok->data.str_lit.is_c_str = true;
1097 t.state = TokenizeStateSawBackslash;
1098 break;
1099 case SYMBOL_CHAR:
1100 t.state = TokenizeStateSymbol;
1101 buf_append_char(&t.cur_tok->data.str_lit.str, c);
1102 break;
1103 default:
1104 t.pos -= 1;
1105 end_token(&t);
1106 t.state = TokenizeStateStart;
1107 continue;
1108 }
1109 break;
11101064 case TokenizeStateSawAtSign:
11111065 switch (c) {
11121066 case '"':
......@@ -1544,7 +1498,6 @@ void tokenize(Buf *buf, Tokenization *out) {
15441498 tokenize_error(&t, "unterminated character literal");
15451499 break;
15461500 case TokenizeStateSymbol:
1547 case TokenizeStateSymbolFirstC:
15481501 case TokenizeStateZero:
15491502 case TokenizeStateNumber:
15501503 case TokenizeStateFloatFraction:
src/tokenizer.hpp-1
......@@ -149,7 +149,6 @@ struct TokenIntLit {
149149
150150struct TokenStrLit {
151151 Buf str;
152 bool is_c_str;
153152};
154153
155154struct TokenCharLit {
src/translate_c.cpp+5-13
......@@ -323,17 +323,9 @@ static AstNode *trans_create_node_bool(Context *c, bool value) {
323323 return bool_node;
324324}
325325
326static AstNode *trans_create_node_str_lit_c(Context *c, Buf *buf) {
326static AstNode *trans_create_node_str_lit(Context *c, Buf *buf) {
327327 AstNode *node = trans_create_node(c, NodeTypeStringLiteral);
328328 node->data.string_literal.buf = buf;
329 node->data.string_literal.c = true;
330 return node;
331}
332
333static AstNode *trans_create_node_str_lit_non_c(Context *c, Buf *buf) {
334 AstNode *node = trans_create_node(c, NodeTypeStringLiteral);
335 node->data.string_literal.buf = buf;
336 node->data.string_literal.c = false;
337329 return node;
338330}
339331
......@@ -632,7 +624,7 @@ static AstNode *qual_type_to_log2_int_ref(Context *c, const ZigClangQualType qt,
632624// zig_type_node
633625
634626 AstNode *import_fn_call = trans_create_node_builtin_fn_call_str(c, "import");
635 import_fn_call->data.fn_call_expr.params.append(trans_create_node_str_lit_non_c(c, buf_create_from_str("std")));
627 import_fn_call->data.fn_call_expr.params.append(trans_create_node_str_lit(c, buf_create_from_str("std")));
636628 AstNode *inner_field_access = trans_create_node_field_access_str(c, import_fn_call, "math");
637629 AstNode *outer_field_access = trans_create_node_field_access_str(c, inner_field_access, "Log2Int");
638630 AstNode *log2int_fn_call = trans_create_node_fn_call_1(c, outer_field_access, zig_type_node);
......@@ -3391,7 +3383,7 @@ static AstNode *trans_string_literal(Context *c, ResultUsed result_used, TransSc
33913383 case ZigClangStringLiteral_StringKind_UTF8: {
33923384 size_t str_len;
33933385 const char *str_ptr = ZigClangStringLiteral_getString_bytes_begin_size(stmt, &str_len);
3394 AstNode *node = trans_create_node_str_lit_c(c, buf_create_from_mem(str_ptr, str_len));
3386 AstNode *node = trans_create_node_str_lit(c, buf_create_from_mem(str_ptr, str_len));
33953387 return maybe_suppress_result(c, result_used, node);
33963388 }
33973389 case ZigClangStringLiteral_StringKind_UTF16:
......@@ -4890,7 +4882,7 @@ static AstNode *parse_ctok_primary_expr(Context *c, CTokenize *ctok, size_t *tok
48904882 return trans_create_node_unsigned(c, tok->data.char_lit);
48914883 case CTokIdStrLit:
48924884 *tok_i += 1;
4893 return trans_create_node_str_lit_c(c, buf_create_from_buf(&tok->data.str_lit));
4885 return trans_create_node_str_lit(c, buf_create_from_buf(&tok->data.str_lit));
48944886 case CTokIdMinus:
48954887 *tok_i += 1;
48964888 return parse_ctok_num_lit(c, ctok, tok_i, true);
......@@ -4937,7 +4929,7 @@ static AstNode *parse_ctok_primary_expr(Context *c, CTokenize *ctok, size_t *tok
49374929 // (dest)(x)
49384930
49394931 AstNode *import_builtin = trans_create_node_builtin_fn_call_str(c, "import");
4940 import_builtin->data.fn_call_expr.params.append(trans_create_node_str_lit_non_c(c, buf_create_from_str("builtin")));
4932 import_builtin->data.fn_call_expr.params.append(trans_create_node_str_lit(c, buf_create_from_str("builtin")));
49414933 AstNode *typeid_type = trans_create_node_field_access_str(c, import_builtin, "TypeId");
49424934 AstNode *typeid_pointer = trans_create_node_field_access_str(c, typeid_type, "Pointer");
49434935 AstNode *typeid_integer = trans_create_node_field_access_str(c, typeid_type, "Int");
test/compare_output.zig+36-36
......@@ -7,7 +7,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
77 cases.addC("hello world with libc",
88 \\const c = @cImport(@cInclude("stdio.h"));
99 \\export fn main(argc: c_int, argv: [*][*]u8) c_int {
10 \\ _ = c.puts(c"Hello, world!");
10 \\ _ = c.puts("Hello, world!");
1111 \\ return 0;
1212 \\}
1313 , "Hello, world!" ++ std.cstr.line_sep);
......@@ -144,75 +144,75 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
144144 \\ // we want actual \n, not \r\n
145145 \\ _ = c._setmode(1, c._O_BINARY);
146146 \\ }
147 \\ _ = c.printf(c"0: %llu\n",
147 \\ _ = c.printf("0: %llu\n",
148148 \\ @as(u64, 0));
149 \\ _ = c.printf(c"320402575052271: %llu\n",
149 \\ _ = c.printf("320402575052271: %llu\n",
150150 \\ @as(u64, 320402575052271));
151 \\ _ = c.printf(c"0x01236789abcdef: %llu\n",
151 \\ _ = c.printf("0x01236789abcdef: %llu\n",
152152 \\ @as(u64, 0x01236789abcdef));
153 \\ _ = c.printf(c"0xffffffffffffffff: %llu\n",
153 \\ _ = c.printf("0xffffffffffffffff: %llu\n",
154154 \\ @as(u64, 0xffffffffffffffff));
155 \\ _ = c.printf(c"0x000000ffffffffffffffff: %llu\n",
155 \\ _ = c.printf("0x000000ffffffffffffffff: %llu\n",
156156 \\ @as(u64, 0x000000ffffffffffffffff));
157 \\ _ = c.printf(c"0o1777777777777777777777: %llu\n",
157 \\ _ = c.printf("0o1777777777777777777777: %llu\n",
158158 \\ @as(u64, 0o1777777777777777777777));
159 \\ _ = c.printf(c"0o0000001777777777777777777777: %llu\n",
159 \\ _ = c.printf("0o0000001777777777777777777777: %llu\n",
160160 \\ @as(u64, 0o0000001777777777777777777777));
161 \\ _ = c.printf(c"0b1111111111111111111111111111111111111111111111111111111111111111: %llu\n",
161 \\ _ = c.printf("0b1111111111111111111111111111111111111111111111111111111111111111: %llu\n",
162162 \\ @as(u64, 0b1111111111111111111111111111111111111111111111111111111111111111));
163 \\ _ = c.printf(c"0b0000001111111111111111111111111111111111111111111111111111111111111111: %llu\n",
163 \\ _ = c.printf("0b0000001111111111111111111111111111111111111111111111111111111111111111: %llu\n",
164164 \\ @as(u64, 0b0000001111111111111111111111111111111111111111111111111111111111111111));
165165 \\
166 \\ _ = c.printf(c"\n");
166 \\ _ = c.printf("\n");
167167 \\
168 \\ _ = c.printf(c"0.0: %.013a\n",
168 \\ _ = c.printf("0.0: %.013a\n",
169169 \\ @as(f64, 0.0));
170 \\ _ = c.printf(c"0e0: %.013a\n",
170 \\ _ = c.printf("0e0: %.013a\n",
171171 \\ @as(f64, 0e0));
172 \\ _ = c.printf(c"0.0e0: %.013a\n",
172 \\ _ = c.printf("0.0e0: %.013a\n",
173173 \\ @as(f64, 0.0e0));
174 \\ _ = c.printf(c"000000000000000000000000000000000000000000000000000000000.0e0: %.013a\n",
174 \\ _ = c.printf("000000000000000000000000000000000000000000000000000000000.0e0: %.013a\n",
175175 \\ @as(f64, 000000000000000000000000000000000000000000000000000000000.0e0));
176 \\ _ = c.printf(c"0.000000000000000000000000000000000000000000000000000000000e0: %.013a\n",
176 \\ _ = c.printf("0.000000000000000000000000000000000000000000000000000000000e0: %.013a\n",
177177 \\ @as(f64, 0.000000000000000000000000000000000000000000000000000000000e0));
178 \\ _ = c.printf(c"0.0e000000000000000000000000000000000000000000000000000000000: %.013a\n",
178 \\ _ = c.printf("0.0e000000000000000000000000000000000000000000000000000000000: %.013a\n",
179179 \\ @as(f64, 0.0e000000000000000000000000000000000000000000000000000000000));
180 \\ _ = c.printf(c"1.0: %.013a\n",
180 \\ _ = c.printf("1.0: %.013a\n",
181181 \\ @as(f64, 1.0));
182 \\ _ = c.printf(c"10.0: %.013a\n",
182 \\ _ = c.printf("10.0: %.013a\n",
183183 \\ @as(f64, 10.0));
184 \\ _ = c.printf(c"10.5: %.013a\n",
184 \\ _ = c.printf("10.5: %.013a\n",
185185 \\ @as(f64, 10.5));
186 \\ _ = c.printf(c"10.5e5: %.013a\n",
186 \\ _ = c.printf("10.5e5: %.013a\n",
187187 \\ @as(f64, 10.5e5));
188 \\ _ = c.printf(c"10.5e+5: %.013a\n",
188 \\ _ = c.printf("10.5e+5: %.013a\n",
189189 \\ @as(f64, 10.5e+5));
190 \\ _ = c.printf(c"50.0e-2: %.013a\n",
190 \\ _ = c.printf("50.0e-2: %.013a\n",
191191 \\ @as(f64, 50.0e-2));
192 \\ _ = c.printf(c"50e-2: %.013a\n",
192 \\ _ = c.printf("50e-2: %.013a\n",
193193 \\ @as(f64, 50e-2));
194194 \\
195 \\ _ = c.printf(c"\n");
195 \\ _ = c.printf("\n");
196196 \\
197 \\ _ = c.printf(c"0x1.0: %.013a\n",
197 \\ _ = c.printf("0x1.0: %.013a\n",
198198 \\ @as(f64, 0x1.0));
199 \\ _ = c.printf(c"0x10.0: %.013a\n",
199 \\ _ = c.printf("0x10.0: %.013a\n",
200200 \\ @as(f64, 0x10.0));
201 \\ _ = c.printf(c"0x100.0: %.013a\n",
201 \\ _ = c.printf("0x100.0: %.013a\n",
202202 \\ @as(f64, 0x100.0));
203 \\ _ = c.printf(c"0x103.0: %.013a\n",
203 \\ _ = c.printf("0x103.0: %.013a\n",
204204 \\ @as(f64, 0x103.0));
205 \\ _ = c.printf(c"0x103.7: %.013a\n",
205 \\ _ = c.printf("0x103.7: %.013a\n",
206206 \\ @as(f64, 0x103.7));
207 \\ _ = c.printf(c"0x103.70: %.013a\n",
207 \\ _ = c.printf("0x103.70: %.013a\n",
208208 \\ @as(f64, 0x103.70));
209 \\ _ = c.printf(c"0x103.70p4: %.013a\n",
209 \\ _ = c.printf("0x103.70p4: %.013a\n",
210210 \\ @as(f64, 0x103.70p4));
211 \\ _ = c.printf(c"0x103.70p5: %.013a\n",
211 \\ _ = c.printf("0x103.70p5: %.013a\n",
212212 \\ @as(f64, 0x103.70p5));
213 \\ _ = c.printf(c"0x103.70p+5: %.013a\n",
213 \\ _ = c.printf("0x103.70p+5: %.013a\n",
214214 \\ @as(f64, 0x103.70p+5));
215 \\ _ = c.printf(c"0x103.70p-5: %.013a\n",
215 \\ _ = c.printf("0x103.70p-5: %.013a\n",
216216 \\ @as(f64, 0x103.70p-5));
217217 \\
218218 \\ return 0;
......@@ -323,7 +323,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
323323 \\ const x: f64 = small;
324324 \\ const y = @floatToInt(i32, x);
325325 \\ const z = @intToFloat(f64, y);
326 \\ _ = c.printf(c"%.2f\n%d\n%.2f\n%.2f\n", x, y, z, @as(f64, -0.4));
326 \\ _ = c.printf("%.2f\n%d\n%.2f\n%.2f\n", x, y, z, @as(f64, -0.4));
327327 \\ return 0;
328328 \\}
329329 , "3.25\n3\n3.00\n-0.40\n");
test/compile_errors.zig+5-5
......@@ -164,7 +164,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
164164 cases.add(
165165 "using an unknown len ptr type instead of array",
166166 \\const resolutions = [*][*]const u8{
167 \\ c"[320 240 ]",
167 \\ "[320 240 ]",
168168 \\ null,
169169 \\};
170170 \\comptime {
......@@ -781,7 +781,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
781781 "peer cast then implicit cast const pointer to mutable C pointer",
782782 \\export fn func() void {
783783 \\ var strValue: [*c]u8 = undefined;
784 \\ strValue = strValue orelse c"";
784 \\ strValue = strValue orelse "";
785785 \\}
786786 ,
787787 "tmp.zig:3:32: error: cast discards const qualifier",
......@@ -1115,7 +1115,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
11151115 "libc headers note",
11161116 \\const c = @cImport(@cInclude("stdio.h"));
11171117 \\export fn entry() void {
1118 \\ _ = c.printf(c"hello, world!\n");
1118 \\ _ = c.printf("hello, world!\n");
11191119 \\}
11201120 ,
11211121 "tmp.zig:1:11: error: C import failed",
......@@ -3352,7 +3352,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
33523352 cases.add(
33533353 "variable has wrong type",
33543354 \\export fn f() i32 {
3355 \\ const a = c"a";
3355 \\ const a = "a";
33563356 \\ return a;
33573357 \\}
33583358 ,
......@@ -4786,7 +4786,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
47864786 cases.add(
47874787 "assign through constant pointer",
47884788 \\export fn f() void {
4789 \\ var cstr = c"Hat";
4789 \\ var cstr = "Hat";
47904790 \\ cstr[0] = 'W';
47914791 \\}
47924792 ,
test/stage1/behavior/array.zig+33-6
......@@ -132,9 +132,16 @@ test "single-item pointer to array indexing and slicing" {
132132}
133133
134134fn testSingleItemPtrArrayIndexSlice() void {
135 var array = "aaaa";
136 doSomeMangling(&array);
137 expect(mem.eql(u8, "azya", array));
135 {
136 var array: [4]u8 = "aaaa".*;
137 doSomeMangling(&array);
138 expect(mem.eql(u8, "azya", &array));
139 }
140 {
141 var array = "aaaa".*;
142 doSomeMangling(&array);
143 expect(mem.eql(u8, "azya", &array));
144 }
138145}
139146
140147fn doSomeMangling(array: *[4]u8) void {
......@@ -294,9 +301,16 @@ test "read/write through global variable array of struct fields initialized via
294301}
295302
296303test "implicit cast zero sized array ptr to slice" {
297 var b = "";
298 const c: []const u8 = &b;
299 expect(c.len == 0);
304 {
305 var b = "".*;
306 const c: []const u8 = &b;
307 expect(c.len == 0);
308 }
309 {
310 var b: [0]u8 = "".*;
311 const c: []const u8 = &b;
312 expect(c.len == 0);
313 }
300314}
301315
302316test "anonymous list literal syntax" {
......@@ -333,3 +347,16 @@ test "anonymous literal in array" {
333347 S.doTheTest();
334348 comptime S.doTheTest();
335349}
350
351test "access the null element of a null terminated array" {
352 const S = struct {
353 fn doTheTest() void {
354 var array: [4]null u8 = .{'a', 'o', 'e', 'u'};
355 comptime expect(array[4] == 0);
356 var len: usize = 4;
357 expect(array[len] == 0);
358 }
359 };
360 S.doTheTest();
361 comptime S.doTheTest();
362}
test/stage1/behavior/bugs/1076.zig+12-4
......@@ -8,8 +8,16 @@ test "comptime code should not modify constant data" {
88}
99
1010fn testCastPtrOfArrayToSliceAndPtr() void {
11 var array = "aoeu";
12 const x: [*]u8 = &array;
13 x[0] += 1;
14 expect(mem.eql(u8, array[0..], "boeu"));
11 {
12 var array = "aoeu".*;
13 const x: [*]u8 = &array;
14 x[0] += 1;
15 expect(mem.eql(u8, array[0..], "boeu"));
16 }
17 {
18 var array: [4]u8 = "aoeu".*;
19 const x: [*]u8 = &array;
20 x[0] += 1;
21 expect(mem.eql(u8, array[0..], "boeu"));
22 }
1523}
test/stage1/behavior/cast.zig+83-27
......@@ -179,18 +179,24 @@ fn gimmeErrOrSlice() anyerror![]u8 {
179179}
180180
181181test "peer type resolution: [0]u8, []const u8, and anyerror![]u8" {
182 {
183 var data = "hi";
184 const slice = data[0..];
185 expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
186 expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
187 }
188 comptime {
189 var data = "hi";
190 const slice = data[0..];
191 expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
192 expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
193 }
182 const S = struct {
183 fn doTheTest() anyerror!void {
184 {
185 var data = "hi".*;
186 const slice = data[0..];
187 expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
188 expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
189 }
190 {
191 var data: [2]u8 = "hi".*;
192 const slice = data[0..];
193 expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
194 expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
195 }
196 }
197 };
198 try S.doTheTest();
199 try comptime S.doTheTest();
194200}
195201fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {
196202 if (a) {
......@@ -217,11 +223,20 @@ test "implicit cast from &const [N]T to []const T" {
217223}
218224
219225fn testCastConstArrayRefToConstSlice() void {
220 const blah = "aoeu";
221 const const_array_ref = &blah;
222 expect(@typeOf(const_array_ref) == *const [4]u8);
223 const slice: []const u8 = const_array_ref;
224 expect(mem.eql(u8, slice, "aoeu"));
226 {
227 const blah = "aoeu".*;
228 const const_array_ref = &blah;
229 expect(@typeOf(const_array_ref) == *const [4]null u8);
230 const slice: []const u8 = const_array_ref;
231 expect(mem.eql(u8, slice, "aoeu"));
232 }
233 {
234 const blah: [4]u8 = "aoeu".*;
235 const const_array_ref = &blah;
236 expect(@typeOf(const_array_ref) == *const [4]u8);
237 const slice: []const u8 = const_array_ref;
238 expect(mem.eql(u8, slice, "aoeu"));
239 }
225240}
226241
227242test "peer type resolution: error and [N]T" {
......@@ -310,17 +325,28 @@ test "single-item pointer of array to slice and to unknown length pointer" {
310325}
311326
312327fn testCastPtrOfArrayToSliceAndPtr() void {
313 var array = "aoeu";
314 const x: [*]u8 = &array;
315 x[0] += 1;
316 expect(mem.eql(u8, array[0..], "boeu"));
317 const y: []u8 = &array;
318 y[0] += 1;
319 expect(mem.eql(u8, array[0..], "coeu"));
328 {
329 var array = "aoeu".*;
330 const x: [*]u8 = &array;
331 x[0] += 1;
332 expect(mem.eql(u8, array[0..], "boeu"));
333 const y: []u8 = &array;
334 y[0] += 1;
335 expect(mem.eql(u8, array[0..], "coeu"));
336 }
337 {
338 var array: [4]u8 = "aoeu".*;
339 const x: [*]u8 = &array;
340 x[0] += 1;
341 expect(mem.eql(u8, array[0..], "boeu"));
342 const y: []u8 = &array;
343 y[0] += 1;
344 expect(mem.eql(u8, array[0..], "coeu"));
345 }
320346}
321347
322348test "cast *[1][*]const u8 to [*]const ?[*]const u8" {
323 const window_name = [1][*]const u8{c"window name"};
349 const window_name = [1][*]const u8{"window name"};
324350 const x: [*]const ?[*]const u8 = &window_name;
325351 expect(mem.eql(u8, std.mem.toSliceConst(u8, x[0].?), "window name"));
326352}
......@@ -545,7 +571,7 @@ test "implicit cast *[0]T to E![]const u8" {
545571}
546572
547573test "peer cast *[0]T to E![]const T" {
548 var buffer: [5]u8 = "abcde";
574 var buffer: [5]u8 = "abcde".*;
549575 var buf: anyerror![]const u8 = buffer[0..];
550576 var b = false;
551577 var y = if (b) &[0]u8{} else buf;
......@@ -553,7 +579,7 @@ test "peer cast *[0]T to E![]const T" {
553579}
554580
555581test "peer cast *[0]T to []const T" {
556 var buffer: [5]u8 = "abcde";
582 var buffer: [5]u8 = "abcde".*;
557583 var buf: []const u8 = buffer[0..];
558584 var b = false;
559585 var y = if (b) &[0]u8{} else buf;
......@@ -565,3 +591,33 @@ test "cast from array reference to fn" {
565591 const f = @ptrCast(extern fn () void, &global_array);
566592 expect(@ptrToInt(f) == @ptrToInt(&global_array));
567593}
594
595test "*const [N]null u8 to ?[]const u8" {
596 const S = struct {
597 fn doTheTest() void {
598 var a = "Hello";
599 var b: ?[]const u8 = a;
600 expect(mem.eql(u8, b.?, "Hello"));
601 }
602 };
603 S.doTheTest();
604 comptime S.doTheTest();
605}
606
607test "peer resolution of string literals" {
608 const S = struct {
609 const E = extern enum { a, b, c, d};
610
611 fn doTheTest(e: E) void {
612 const cmd = switch (e) {
613 .a => "one",
614 .b => "two",
615 .c => "three",
616 .d => "four",
617 };
618 expect(mem.eql(u8, cmd, "two"));
619 }
620 };
621 S.doTheTest(.b);
622 comptime S.doTheTest(.b);
623}
test/stage1/behavior/const_slice_child.zig+4-5
......@@ -6,12 +6,11 @@ var argv: [*]const [*]const u8 = undefined;
66
77test "const slice child" {
88 const strs = [_][*]const u8{
9 c"one",
10 c"two",
11 c"three",
9 "one",
10 "two",
11 "three",
1212 };
13 // TODO this should implicitly cast
14 argv = @ptrCast([*]const [*]const u8, &strs);
13 argv = &strs;
1514 bar(strs.len);
1615}
1716
test/stage1/behavior/eval.zig+1-1
......@@ -736,7 +736,7 @@ test "comptime pointer cast array and then slice" {
736736
737737test "slice bounds in comptime concatenation" {
738738 const bs = comptime blk: {
739 const b = c"........1........";
739 const b = "........1........";
740740 break :blk b[8..9];
741741 };
742742 const str = "" ++ bs;
test/stage1/behavior/misc.zig+10-7
......@@ -204,11 +204,11 @@ test "multiline string" {
204204
205205test "multiline C string" {
206206 const s1 =
207 c\\one
208 c\\two)
209 c\\three
207 \\one
208 \\two)
209 \\three
210210 ;
211 const s2 = c"one\ntwo)\nthree";
211 const s2 = "one\ntwo)\nthree";
212212 expect(std.cstr.cmp(s1, s2) == 0);
213213}
214214
......@@ -358,9 +358,12 @@ fn ptrEql(a: *const []const u8, b: *const []const u8) bool {
358358 return a == b;
359359}
360360
361test "C string concatenation" {
362 const a = c"OK" ++ c" IT " ++ c"WORKED";
363 const b = c"OK IT WORKED";
361test "string concatenation" {
362 const a = "OK" ++ " IT " ++ "WORKED";
363 const b = "OK IT WORKED";
364
365 comptime expect(@typeOf(a) == *const [12]null u8);
366 comptime expect(@typeOf(b) == *const [12]null u8);
364367
365368 const len = mem.len(u8, b);
366369 const len_with_null = len + 1;
test/stage1/behavior/pointers.zig+1-1
......@@ -15,7 +15,7 @@ fn testDerefPtr() void {
1515}
1616
1717test "pointer arithmetic" {
18 var ptr = c"abcd";
18 var ptr: [*]const u8 = "abcd";
1919
2020 expect(ptr[0] == 'a');
2121 ptr += 1;
test/stage1/behavior/ptrcast.zig+1-1
......@@ -60,7 +60,7 @@ test "comptime ptrcast keeps larger alignment" {
6060}
6161
6262test "implicit optional pointer to optional c_void pointer" {
63 var buf: [4]u8 = "aoeu";
63 var buf: [4]u8 = "aoeu".*;
6464 var x: ?[*]u8 = &buf;
6565 var y: ?*c_void = x;
6666 var z = @ptrCast(*[4]u8, y);
test/stage1/behavior/slice.zig+1-1
......@@ -36,7 +36,7 @@ fn assertLenIsZero(msg: []const u8) void {
3636}
3737
3838test "C pointer" {
39 var buf: [*c]const u8 = c"kjdhfkjdhfdkjhfkfjhdfkjdhfkdjhfdkjhf";
39 var buf: [*c]const u8 = "kjdhfkjdhfdkjhfkfjhdfkjdhfkdjhfdkjhf";
4040 var len: u32 = 10;
4141 var slice = buf[0..len];
4242 expectEqualSlices(u8, "kjdhfkjdhf", slice);
test/stage1/behavior/struct.zig+1-1
......@@ -493,7 +493,7 @@ test "non-byte-aligned array inside packed struct" {
493493 fn doTheTest() void {
494494 var foo = Foo{
495495 .a = true,
496 .b = "abcdefghijklmnopqurstu",
496 .b = "abcdefghijklmnopqurstu".*,
497497 };
498498 bar(foo.b);
499499 }
test/stage2/compare_output.zig+2-2
......@@ -6,7 +6,7 @@ pub fn addCases(ctx: *TestContext) !void {
66 try ctx.testCompareOutputLibC(
77 \\extern fn puts([*]const u8) void;
88 \\export fn main() c_int {
9 \\ puts(c"Hello, world!");
9 \\ puts("Hello, world!");
1010 \\ return 0;
1111 \\}
1212 , "Hello, world!" ++ std.cstr.line_sep);
......@@ -15,7 +15,7 @@ pub fn addCases(ctx: *TestContext) !void {
1515 try ctx.testCompareOutputLibC(
1616 \\extern fn puts(s: [*]const u8) void;
1717 \\export fn main() c_int {
18 \\ return foo(c"OK");
18 \\ return foo("OK");
1919 \\}
2020 \\fn foo(s: [*]const u8) c_int {
2121 \\ puts(s);
test/standalone/hello_world/hello_libc.zig+1-1
......@@ -5,7 +5,7 @@ const c = @cImport({
55 @cInclude("string.h");
66});
77
8const msg = c"Hello, world!\n";
8const msg = "Hello, world!\n";
99
1010export fn main(argc: c_int, argv: **u8) c_int {
1111 if (c.printf(msg) != @intCast(c_int, c.strlen(msg))) return -1;
test/translate_c.zig+14-14
......@@ -47,7 +47,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
4747 \\pub fn foo() void {
4848 \\ var a: c_int = undefined;
4949 \\ _ = 1;
50 \\ _ = c"hey";
50 \\ _ = "hey";
5151 \\ _ = (1 + 1);
5252 \\ _ = (1 - 1);
5353 \\ a = 1;
......@@ -213,9 +213,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
213213 \\}
214214 ,
215215 \\pub fn foo() void {
216 \\ _ = c"foo";
217 \\ _ = c"foo";
218 \\ _ = c"void foo(void)";
216 \\ _ = "foo";
217 \\ _ = "foo";
218 \\ _ = "void foo(void)";
219219 \\}
220220 );
221221
......@@ -232,7 +232,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
232232 \\pub fn foo() void {
233233 \\ var a: c_int = undefined;
234234 \\ _ = 1;
235 \\ _ = c"hey";
235 \\ _ = "hey";
236236 \\ _ = (1 + 1);
237237 \\ _ = (1 - 1);
238238 \\ a = 1;
......@@ -543,7 +543,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
543543 cases.add("#define string",
544544 \\#define foo "a string"
545545 ,
546 \\pub const foo = c"a string";
546 \\pub const foo = "a string";
547547 );
548548
549549 cases.add("__cdecl doesn't mess up function pointers",
......@@ -617,9 +617,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
617617 \\#define FOO2 "aoeu\x0007a derp"
618618 \\#define FOO_CHAR '\xfF'
619619 ,
620 \\pub const FOO = c"aoeu\xab derp";
620 \\pub const FOO = "aoeu\xab derp";
621621 ,
622 \\pub const FOO2 = c"aoeuz derp";
622 \\pub const FOO2 = "aoeuz derp";
623623 ,
624624 \\pub const FOO_CHAR = 255;
625625 );
......@@ -629,9 +629,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
629629 \\#define FOO2 "aoeu\0234 derp"
630630 \\#define FOO_CHAR '\077'
631631 ,
632 \\pub const FOO = c"aoeu\x13 derp";
632 \\pub const FOO = "aoeu\x13 derp";
633633 ,
634 \\pub const FOO2 = c"aoeu\x134 derp";
634 \\pub const FOO2 = "aoeu\x134 derp";
635635 ,
636636 \\pub const FOO_CHAR = 63;
637637 );
......@@ -1351,7 +1351,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
13511351 \\}
13521352 ,
13531353 \\pub fn foo() [*c]const u8 {
1354 \\ return c"bar";
1354 \\ return "bar";
13551355 \\}
13561356 );
13571357
......@@ -1523,7 +1523,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
15231523 cases.add("const ptr initializer",
15241524 \\static const char *v0 = "0.0.0";
15251525 ,
1526 \\pub var v0: [*c]const u8 = c"0.0.0";
1526 \\pub var v0: [*c]const u8 = "0.0.0";
15271527 );
15281528
15291529 cases.add("static incomplete array inside function",
......@@ -1532,7 +1532,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
15321532 \\}
15331533 ,
15341534 \\pub fn foo() void {
1535 \\ const v2: [*c]const u8 = c"2.2.2";
1535 \\ const v2: [*c]const u8 = "2.2.2";
15361536 \\}
15371537 );
15381538
......@@ -1809,7 +1809,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
18091809 \\ var i: u8 = @as(u8, '\x0b');
18101810 \\ var j: u8 = @as(u8, '\x00');
18111811 \\ var k: u8 = @as(u8, '\"');
1812 \\ return c"\'\\\x07\x08\x0c\n\r\t\x0b\x00\"";
1812 \\ return "\'\\\x07\x08\x0c\n\r\t\x0b\x00\"";
18131813 \\}
18141814 \\
18151815 );