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 {...@@ -328,7 +328,7 @@ pub const ChildProcess = struct {
328328
329 const any_ignore = (self.stdin_behavior == StdIo.Ignore or self.stdout_behavior == StdIo.Ignore or self.stderr_behavior == StdIo.Ignore);329 const any_ignore = (self.stdin_behavior == StdIo.Ignore or self.stdout_behavior == StdIo.Ignore or self.stderr_behavior == StdIo.Ignore);
330 const dev_null_fd = if (any_ignore)330 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) {
332 error.PathAlreadyExists => unreachable,332 error.PathAlreadyExists => unreachable,
333 error.NoSpaceLeft => unreachable,333 error.NoSpaceLeft => unreachable,
334 error.FileTooBig => unreachable,334 error.FileTooBig => unreachable,
lib/std/crypto/x25519.zig+6-6
...@@ -610,8 +610,8 @@ test "x25519 rfc7748 vector2" {...@@ -610,8 +610,8 @@ test "x25519 rfc7748 vector2" {
610}610}
611611
612test "x25519 rfc7748 one iteration" {612test "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";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";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
616 var k: [32]u8 = initial_value;616 var k: [32]u8 = initial_value;
617 var u: [32]u8 = initial_value;617 var u: [32]u8 = initial_value;
...@@ -634,8 +634,8 @@ test "x25519 rfc7748 1,000 iterations" {...@@ -634,8 +634,8 @@ test "x25519 rfc7748 1,000 iterations" {
634 return error.SkipZigTest;634 return error.SkipZigTest;
635 }635 }
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";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";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
640 var k: [32]u8 = initial_value;640 var k: [32]u8 = initial_value;
641 var u: [32]u8 = initial_value;641 var u: [32]u8 = initial_value;
...@@ -657,8 +657,8 @@ test "x25519 rfc7748 1,000,000 iterations" {...@@ -657,8 +657,8 @@ test "x25519 rfc7748 1,000,000 iterations" {
657 return error.SkipZigTest;657 return error.SkipZigTest;
658 }658 }
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";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";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
663 var k: [32]u8 = initial_value;663 var k: [32]u8 = initial_value;
664 var u: [32]u8 = initial_value;664 var u: [32]u8 = initial_value;
lib/std/cstr.zig+2-2
...@@ -27,8 +27,8 @@ test "cstr fns" {...@@ -27,8 +27,8 @@ test "cstr fns" {
27}27}
2828
29fn testCStrFnsImpl() void {29fn testCStrFnsImpl() void {
30 testing.expect(cmp(c"aoeu", c"aoez") == -1);30 testing.expect(cmp("aoeu", "aoez") == -1);
31 testing.expect(mem.len(u8, c"123456789") == 9);31 testing.expect(mem.len(u8, "123456789") == 9);
32}32}
3333
34/// Returns a mutable slice with 1 more byte of length which is a null byte.34/// 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 @@...@@ -1,8 +1,6 @@
1const std = @import("std.zig");1const std = @import("std.zig");
2const math = std.math;2const math = std.math;
3const debug = std.debug;3const assert = std.debug.assert;
4const assert = debug.assert;
5const testing = std.testing;
6const mem = std.mem;4const mem = std.mem;
7const builtin = @import("builtin");5const builtin = @import("builtin");
8const errol = @import("fmt/errol.zig");6const errol = @import("fmt/errol.zig");
...@@ -36,7 +34,7 @@ fn nextArg(comptime used_pos_args: *u32, comptime maybe_pos_arg: ?comptime_int,...@@ -36,7 +34,7 @@ fn nextArg(comptime used_pos_args: *u32, comptime maybe_pos_arg: ?comptime_int,
3634
37fn peekIsAlign(comptime fmt: []const u8) bool {35fn peekIsAlign(comptime fmt: []const u8) bool {
38 // Should only be called during a state transition to the format segment.36 // Should only be called during a state transition to the format segment.
39 std.debug.assert(fmt[0] == ':');37 comptime assert(fmt[0] == ':');
4038
41 inline for (([_]u8{ 1, 2 })[0..]) |i| {39 inline for (([_]u8{ 1, 2 })[0..]) |i| {
42 if (fmt.len > i and (fmt[i] == '<' or fmt[i] == '^' or fmt[i] == '>')) {40 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 {...@@ -1009,13 +1007,13 @@ pub fn parseInt(comptime T: type, buf: []const u8, radix: u8) !T {
1009}1007}
10101008
1011test "parseInt" {1009test "parseInt" {
1012 testing.expect((parseInt(i32, "-10", 10) catch unreachable) == -10);1010 std.testing.expect((parseInt(i32, "-10", 10) catch unreachable) == -10);
1013 testing.expect((parseInt(i32, "+10", 10) catch unreachable) == 10);1011 std.testing.expect((parseInt(i32, "+10", 10) catch unreachable) == 10);
1014 testing.expect(if (parseInt(i32, " 10", 10)) |_| false else |err| err == error.InvalidCharacter);1012 std.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);1013 std.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);1014 std.testing.expect(if (parseInt(u32, "-10", 10)) |_| false else |err| err == error.InvalidCharacter);
1017 testing.expect((parseInt(u8, "255", 10) catch unreachable) == 255);1015 std.testing.expect((parseInt(u8, "255", 10) catch unreachable) == 255);
1018 testing.expect(if (parseInt(u8, "256", 10)) |_| false else |err| err == error.Overflow);1016 std.testing.expect(if (parseInt(u8, "256", 10)) |_| false else |err| err == error.Overflow);
1019}1017}
10201018
1021const ParseUnsignedError = error{1019const ParseUnsignedError = error{
...@@ -1040,30 +1038,30 @@ pub fn parseUnsigned(comptime T: type, buf: []const u8, radix: u8) ParseUnsigned...@@ -1040,30 +1038,30 @@ pub fn parseUnsigned(comptime T: type, buf: []const u8, radix: u8) ParseUnsigned
1040}1038}
10411039
1042test "parseUnsigned" {1040test "parseUnsigned" {
1043 testing.expect((try parseUnsigned(u16, "050124", 10)) == 50124);1041 std.testing.expect((try parseUnsigned(u16, "050124", 10)) == 50124);
1044 testing.expect((try parseUnsigned(u16, "65535", 10)) == 65535);1042 std.testing.expect((try parseUnsigned(u16, "65535", 10)) == 65535);
1045 testing.expectError(error.Overflow, parseUnsigned(u16, "65536", 10));1043 std.testing.expectError(error.Overflow, parseUnsigned(u16, "65536", 10));
10461044
1047 testing.expect((try parseUnsigned(u64, "0ffffffffffffffff", 16)) == 0xffffffffffffffff);1045 std.testing.expect((try parseUnsigned(u64, "0ffffffffffffffff", 16)) == 0xffffffffffffffff);
1048 testing.expectError(error.Overflow, parseUnsigned(u64, "10000000000000000", 16));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);1050 std.testing.expect((try parseUnsigned(u7, "1", 10)) == 1);
1053 testing.expect((try parseUnsigned(u7, "1000", 2)) == 8);1051 std.testing.expect((try parseUnsigned(u7, "1000", 2)) == 8);
10541052
1055 testing.expectError(error.InvalidCharacter, parseUnsigned(u32, "f", 10));1053 std.testing.expectError(error.InvalidCharacter, parseUnsigned(u32, "f", 10));
1056 testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "109", 8));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
1060 // these numbers should fit even though the radix itself doesn't fit in the destination type1058 // 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);1059 std.testing.expect((try parseUnsigned(u1, "0", 10)) == 0);
1062 testing.expect((try parseUnsigned(u1, "1", 10)) == 1);1060 std.testing.expect((try parseUnsigned(u1, "1", 10)) == 1);
1063 testing.expectError(error.Overflow, parseUnsigned(u1, "2", 10));1061 std.testing.expectError(error.Overflow, parseUnsigned(u1, "2", 10));
1064 testing.expect((try parseUnsigned(u1, "001", 16)) == 1);1062 std.testing.expect((try parseUnsigned(u1, "001", 16)) == 1);
1065 testing.expect((try parseUnsigned(u2, "3", 16)) == 3);1063 std.testing.expect((try parseUnsigned(u2, "3", 16)) == 3);
1066 testing.expectError(error.Overflow, parseUnsigned(u2, "4", 16));1064 std.testing.expectError(error.Overflow, parseUnsigned(u2, "4", 16));
1067}1065}
10681066
1069pub const parseFloat = @import("fmt/parse_float.zig").parseFloat;1067pub const parseFloat = @import("fmt/parse_float.zig").parseFloat;
...@@ -1134,19 +1132,19 @@ fn countSize(size: *usize, bytes: []const u8) (error{}!void) {...@@ -1134,19 +1132,19 @@ fn countSize(size: *usize, bytes: []const u8) (error{}!void) {
1134test "bufPrintInt" {1132test "bufPrintInt" {
1135 var buffer: [100]u8 = undefined;1133 var buffer: [100]u8 = undefined;
1136 const buf = buffer[0..];1134 const buf = buffer[0..];
1137 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, -12345678), 2, false, FormatOptions{}), "-101111000110000101001110"));1135 std.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"));1136 std.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"));1137 std.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"));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"));1142 std.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"));1143 std.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"));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"));1146 std.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"));1147 std.testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, @as(i32, -42), 10, false, FormatOptions{ .width = 3 }), "-42"));
1150}1148}
11511149
1152fn bufPrintIntToSlice(buf: []u8, value: var, base: u8, uppercase: bool, options: FormatOptions) []u8 {1150fn bufPrintIntToSlice(buf: []u8, value: var, base: u8, uppercase: bool, options: FormatOptions) []u8 {
...@@ -1163,7 +1161,7 @@ test "parse u64 digit too big" {...@@ -1163,7 +1161,7 @@ test "parse u64 digit too big" {
11631161
1164test "parse unsigned comptime" {1162test "parse unsigned comptime" {
1165 comptime {1163 comptime {
1166 testing.expect((try parseUnsigned(usize, "2", 10)) == 2);1164 std.testing.expect((try parseUnsigned(usize, "2", 10)) == 2);
1167 }1165 }
1168}1166}
11691167
...@@ -1218,23 +1216,23 @@ test "buffer" {...@@ -1218,23 +1216,23 @@ test "buffer" {
1218 var context = BufPrintContext{ .remaining = buf1[0..] };1216 var context = BufPrintContext{ .remaining = buf1[0..] };
1219 try formatType(1234, "", FormatOptions{}, &context, error{BufferTooSmall}, bufPrintWrite, default_max_depth);1217 try formatType(1234, "", FormatOptions{}, &context, error{BufferTooSmall}, bufPrintWrite, default_max_depth);
1220 var res = buf1[0 .. buf1.len - context.remaining.len];1218 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
1223 context = BufPrintContext{ .remaining = buf1[0..] };1221 context = BufPrintContext{ .remaining = buf1[0..] };
1224 try formatType('a', "c", FormatOptions{}, &context, error{BufferTooSmall}, bufPrintWrite, default_max_depth);1222 try formatType('a', "c", FormatOptions{}, &context, error{BufferTooSmall}, bufPrintWrite, default_max_depth);
1225 res = buf1[0 .. buf1.len - context.remaining.len];1223 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
1228 context = BufPrintContext{ .remaining = buf1[0..] };1226 context = BufPrintContext{ .remaining = buf1[0..] };
1229 try formatType(0b1100, "b", FormatOptions{}, &context, error{BufferTooSmall}, bufPrintWrite, default_max_depth);1227 try formatType(0b1100, "b", FormatOptions{}, &context, error{BufferTooSmall}, bufPrintWrite, default_max_depth);
1230 res = buf1[0 .. buf1.len - context.remaining.len];1228 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"));
1232 }1230 }
1233}1231}
12341232
1235test "array" {1233test "array" {
1236 {1234 {
1237 const value: [3]u8 = "abc";1235 const value: [3]u8 = "abc".*;
1238 try testFmt("array: abc\n", "array: {}\n", value);1236 try testFmt("array: abc\n", "array: {}\n", value);
1239 try testFmt("array: abc\n", "array: {}\n", &value);1237 try testFmt("array: abc\n", "array: {}\n", &value);
12401238
...@@ -1278,8 +1276,8 @@ test "pointer" {...@@ -1278,8 +1276,8 @@ test "pointer" {
1278}1276}
12791277
1280test "cstr" {1278test "cstr" {
1281 try testFmt("cstr: Test C\n", "cstr: {s}\n", c"Test C");1279 try testFmt("cstr: Test C\n", "cstr: {s}\n", "Test C");
1282 try testFmt("cstr: Test C \n", "cstr: {s:10}\n", c"Test C");1280 try testFmt("cstr: Test C \n", "cstr: {s:10}\n", "Test C");
1283}1281}
12841282
1285test "filesize" {1283test "filesize" {
...@@ -1479,10 +1477,10 @@ test "union" {...@@ -1479,10 +1477,10 @@ test "union" {
14791477
1480 var buf: [100]u8 = undefined;1478 var buf: [100]u8 = undefined;
1481 const uu_result = try bufPrint(buf[0..], "{}", uu_inst);1479 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
1484 const eu_result = try bufPrint(buf[0..], "{}", eu_inst);1482 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@"));
1486}1484}
14871485
1488test "enum" {1486test "enum" {
...@@ -1569,11 +1567,11 @@ pub fn trim(buf: []const u8) []const u8 {...@@ -1569,11 +1567,11 @@ pub fn trim(buf: []const u8) []const u8 {
1569}1567}
15701568
1571test "trim" {1569test "trim" {
1572 testing.expect(mem.eql(u8, "abc", trim("\n abc \t")));1570 std.testing.expect(mem.eql(u8, "abc", trim("\n abc \t")));
1573 testing.expect(mem.eql(u8, "", trim(" ")));1571 std.testing.expect(mem.eql(u8, "", trim(" ")));
1574 testing.expect(mem.eql(u8, "", trim("")));1572 std.testing.expect(mem.eql(u8, "", trim("")));
1575 testing.expect(mem.eql(u8, "abc", trim(" abc")));1573 std.testing.expect(mem.eql(u8, "abc", trim(" abc")));
1576 testing.expect(mem.eql(u8, "abc", trim("abc ")));1574 std.testing.expect(mem.eql(u8, "abc", trim("abc ")));
1577}1575}
15781576
1579pub fn isWhiteSpace(byte: u8) bool {1577pub fn isWhiteSpace(byte: u8) bool {
...@@ -1607,7 +1605,7 @@ test "formatIntValue with comptime_int" {...@@ -1607,7 +1605,7 @@ test "formatIntValue with comptime_int" {
16071605
1608 var buf = try std.Buffer.init(std.debug.global_allocator, "");1606 var buf = try std.Buffer.init(std.debug.global_allocator, "");
1609 try formatIntValue(value, "", FormatOptions{}, &buf, @typeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append);1607 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"));
1611}1609}
16121610
1613test "formatType max_depth" {1611test "formatType max_depth" {
...@@ -1661,19 +1659,19 @@ test "formatType max_depth" {...@@ -1661,19 +1659,19 @@ test "formatType max_depth" {
16611659
1662 var buf0 = try std.Buffer.init(std.debug.global_allocator, "");1660 var buf0 = try std.Buffer.init(std.debug.global_allocator, "");
1663 try formatType(inst, "", FormatOptions{}, &buf0, @typeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append, 0);1661 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
1666 var buf1 = try std.Buffer.init(std.debug.global_allocator, "");1664 var buf1 = try std.Buffer.init(std.debug.global_allocator, "");
1667 try formatType(inst, "", FormatOptions{}, &buf1, @typeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append, 1);1665 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
1670 var buf2 = try std.Buffer.init(std.debug.global_allocator, "");1668 var buf2 = try std.Buffer.init(std.debug.global_allocator, "");
1671 try formatType(inst, "", FormatOptions{}, &buf2, @typeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append, 2);1669 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
1674 var buf3 = try std.Buffer.init(std.debug.global_allocator, "");1672 var buf3 = try std.Buffer.init(std.debug.global_allocator, "");
1675 try formatType(inst, "", FormatOptions{}, &buf3, @typeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append, 3);1673 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) }"));
1677}1675}
16781676
1679test "positional" {1677test "positional" {
lib/std/fs.zig+3-3
...@@ -1240,7 +1240,7 @@ pub const OpenSelfExeError = os.OpenError || os.windows.CreateFileError || SelfE...@@ -1240,7 +1240,7 @@ pub const OpenSelfExeError = os.OpenError || os.windows.CreateFileError || SelfE
12401240
1241pub fn openSelfExe() OpenSelfExeError!File {1241pub fn openSelfExe() OpenSelfExeError!File {
1242 if (builtin.os == .linux) {1242 if (builtin.os == .linux) {
1243 return File.openReadC(c"/proc/self/exe");1243 return File.openReadC("/proc/self/exe");
1244 }1244 }
1245 if (builtin.os == .windows) {1245 if (builtin.os == .windows) {
1246 const wide_slice = selfExePathW();1246 const wide_slice = selfExePathW();
...@@ -1280,7 +1280,7 @@ pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) SelfExePathError![]u8 {...@@ -1280,7 +1280,7 @@ pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) SelfExePathError![]u8 {
1280 return mem.toSlice(u8, out_buffer);1280 return mem.toSlice(u8, out_buffer);
1281 }1281 }
1282 switch (builtin.os) {1282 switch (builtin.os) {
1283 .linux => return os.readlinkC(c"/proc/self/exe", out_buffer),1283 .linux => return os.readlinkC("/proc/self/exe", out_buffer),
1284 .freebsd, .dragonfly => {1284 .freebsd, .dragonfly => {
1285 var mib = [4]c_int{ os.CTL_KERN, os.KERN_PROC, os.KERN_PROC_PATHNAME, -1 };1285 var mib = [4]c_int{ os.CTL_KERN, os.KERN_PROC, os.KERN_PROC_PATHNAME, -1 };
1286 var out_len: usize = out_buffer.len;1286 var out_len: usize = out_buffer.len;
...@@ -1326,7 +1326,7 @@ pub fn selfExeDirPath(out_buffer: *[MAX_PATH_BYTES]u8) SelfExePathError![]const...@@ -1326,7 +1326,7 @@ pub fn selfExeDirPath(out_buffer: *[MAX_PATH_BYTES]u8) SelfExePathError![]const
1326 // the file path looks something like `/a/b/c/exe (deleted)`1326 // the file path looks something like `/a/b/c/exe (deleted)`
1327 // This path cannot be opened, but it's valid for determining the directory1327 // This path cannot be opened, but it's valid for determining the directory
1328 // the executable was in when it was run.1328 // 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);
1330 // Assume that /proc/self/exe has an absolute path, and therefore dirname1330 // Assume that /proc/self/exe has an absolute path, and therefore dirname
1331 // will not return null.1331 // will not return null.
1332 return path.dirname(full_exe_path).?;1332 return path.dirname(full_exe_path).?;
lib/std/fs/file.zig+1-1
...@@ -172,7 +172,7 @@ pub const File = struct {...@@ -172,7 +172,7 @@ pub const File = struct {
172 if (self.isTty()) {172 if (self.isTty()) {
173 if (self.handle == os.STDOUT_FILENO or self.handle == os.STDERR_FILENO) {173 if (self.handle == os.STDOUT_FILENO or self.handle == os.STDERR_FILENO) {
174 // Use getenvC to workaround https://github.com/ziglang/zig/issues/3511174 // Use getenvC to workaround https://github.com/ziglang/zig/issues/3511
175 if (os.getenvC(c"TERM")) |term| {175 if (os.getenvC("TERM")) |term| {
176 if (std.mem.eql(u8, term, "dumb"))176 if (std.mem.eql(u8, term, "dumb"))
177 return false;177 return false;
178 }178 }
lib/std/fs/path.zig+1-1
...@@ -394,7 +394,7 @@ pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {...@@ -394,7 +394,7 @@ pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {
394 }394 }
395395
396 // determine which disk designator we will result with, if any396 // determine which disk designator we will result with, if any
397 var result_drive_buf = "_:";397 var result_drive_buf = "_:".*;
398 var result_disk_designator: []const u8 = "";398 var result_disk_designator: []const u8 = "";
399 var have_drive_kind = WindowsPath.Kind.None;399 var have_drive_kind = WindowsPath.Kind.None;
400 var have_abs_path = false;400 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...@@ -202,70 +202,70 @@ const test_key = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x
202202
203test "siphash64-2-4 sanity" {203test "siphash64-2-4 sanity" {
204 const vectors = [_][8]u8{204 const vectors = [_][8]u8{
205 "\x31\x0e\x0e\xdd\x47\xdb\x6f\x72", // ""205 "\x31\x0e\x0e\xdd\x47\xdb\x6f\x72".*, // ""
206 "\xfd\x67\xdc\x93\xc5\x39\xf8\x74", // "\x00"206 "\xfd\x67\xdc\x93\xc5\x39\xf8\x74".*, // "\x00"
207 "\x5a\x4f\xa9\xd9\x09\x80\x6c\x0d", // "\x00\x01" ... etc207 "\x5a\x4f\xa9\xd9\x09\x80\x6c\x0d".*, // "\x00\x01" ... etc
208 "\x2d\x7e\xfb\xd7\x96\x66\x67\x85",208 "\x2d\x7e\xfb\xd7\x96\x66\x67\x85".*,
209 "\xb7\x87\x71\x27\xe0\x94\x27\xcf",209 "\xb7\x87\x71\x27\xe0\x94\x27\xcf".*,
210 "\x8d\xa6\x99\xcd\x64\x55\x76\x18",210 "\x8d\xa6\x99\xcd\x64\x55\x76\x18".*,
211 "\xce\xe3\xfe\x58\x6e\x46\xc9\xcb",211 "\xce\xe3\xfe\x58\x6e\x46\xc9\xcb".*,
212 "\x37\xd1\x01\x8b\xf5\x00\x02\xab",212 "\x37\xd1\x01\x8b\xf5\x00\x02\xab".*,
213 "\x62\x24\x93\x9a\x79\xf5\xf5\x93",213 "\x62\x24\x93\x9a\x79\xf5\xf5\x93".*,
214 "\xb0\xe4\xa9\x0b\xdf\x82\x00\x9e",214 "\xb0\xe4\xa9\x0b\xdf\x82\x00\x9e".*,
215 "\xf3\xb9\xdd\x94\xc5\xbb\x5d\x7a",215 "\xf3\xb9\xdd\x94\xc5\xbb\x5d\x7a".*,
216 "\xa7\xad\x6b\x22\x46\x2f\xb3\xf4",216 "\xa7\xad\x6b\x22\x46\x2f\xb3\xf4".*,
217 "\xfb\xe5\x0e\x86\xbc\x8f\x1e\x75",217 "\xfb\xe5\x0e\x86\xbc\x8f\x1e\x75".*,
218 "\x90\x3d\x84\xc0\x27\x56\xea\x14",218 "\x90\x3d\x84\xc0\x27\x56\xea\x14".*,
219 "\xee\xf2\x7a\x8e\x90\xca\x23\xf7",219 "\xee\xf2\x7a\x8e\x90\xca\x23\xf7".*,
220 "\xe5\x45\xbe\x49\x61\xca\x29\xa1",220 "\xe5\x45\xbe\x49\x61\xca\x29\xa1".*,
221 "\xdb\x9b\xc2\x57\x7f\xcc\x2a\x3f",221 "\xdb\x9b\xc2\x57\x7f\xcc\x2a\x3f".*,
222 "\x94\x47\xbe\x2c\xf5\xe9\x9a\x69",222 "\x94\x47\xbe\x2c\xf5\xe9\x9a\x69".*,
223 "\x9c\xd3\x8d\x96\xf0\xb3\xc1\x4b",223 "\x9c\xd3\x8d\x96\xf0\xb3\xc1\x4b".*,
224 "\xbd\x61\x79\xa7\x1d\xc9\x6d\xbb",224 "\xbd\x61\x79\xa7\x1d\xc9\x6d\xbb".*,
225 "\x98\xee\xa2\x1a\xf2\x5c\xd6\xbe",225 "\x98\xee\xa2\x1a\xf2\x5c\xd6\xbe".*,
226 "\xc7\x67\x3b\x2e\xb0\xcb\xf2\xd0",226 "\xc7\x67\x3b\x2e\xb0\xcb\xf2\xd0".*,
227 "\x88\x3e\xa3\xe3\x95\x67\x53\x93",227 "\x88\x3e\xa3\xe3\x95\x67\x53\x93".*,
228 "\xc8\xce\x5c\xcd\x8c\x03\x0c\xa8",228 "\xc8\xce\x5c\xcd\x8c\x03\x0c\xa8".*,
229 "\x94\xaf\x49\xf6\xc6\x50\xad\xb8",229 "\x94\xaf\x49\xf6\xc6\x50\xad\xb8".*,
230 "\xea\xb8\x85\x8a\xde\x92\xe1\xbc",230 "\xea\xb8\x85\x8a\xde\x92\xe1\xbc".*,
231 "\xf3\x15\xbb\x5b\xb8\x35\xd8\x17",231 "\xf3\x15\xbb\x5b\xb8\x35\xd8\x17".*,
232 "\xad\xcf\x6b\x07\x63\x61\x2e\x2f",232 "\xad\xcf\x6b\x07\x63\x61\x2e\x2f".*,
233 "\xa5\xc9\x1d\xa7\xac\xaa\x4d\xde",233 "\xa5\xc9\x1d\xa7\xac\xaa\x4d\xde".*,
234 "\x71\x65\x95\x87\x66\x50\xa2\xa6",234 "\x71\x65\x95\x87\x66\x50\xa2\xa6".*,
235 "\x28\xef\x49\x5c\x53\xa3\x87\xad",235 "\x28\xef\x49\x5c\x53\xa3\x87\xad".*,
236 "\x42\xc3\x41\xd8\xfa\x92\xd8\x32",236 "\x42\xc3\x41\xd8\xfa\x92\xd8\x32".*,
237 "\xce\x7c\xf2\x72\x2f\x51\x27\x71",237 "\xce\x7c\xf2\x72\x2f\x51\x27\x71".*,
238 "\xe3\x78\x59\xf9\x46\x23\xf3\xa7",238 "\xe3\x78\x59\xf9\x46\x23\xf3\xa7".*,
239 "\x38\x12\x05\xbb\x1a\xb0\xe0\x12",239 "\x38\x12\x05\xbb\x1a\xb0\xe0\x12".*,
240 "\xae\x97\xa1\x0f\xd4\x34\xe0\x15",240 "\xae\x97\xa1\x0f\xd4\x34\xe0\x15".*,
241 "\xb4\xa3\x15\x08\xbe\xff\x4d\x31",241 "\xb4\xa3\x15\x08\xbe\xff\x4d\x31".*,
242 "\x81\x39\x62\x29\xf0\x90\x79\x02",242 "\x81\x39\x62\x29\xf0\x90\x79\x02".*,
243 "\x4d\x0c\xf4\x9e\xe5\xd4\xdc\xca",243 "\x4d\x0c\xf4\x9e\xe5\xd4\xdc\xca".*,
244 "\x5c\x73\x33\x6a\x76\xd8\xbf\x9a",244 "\x5c\x73\x33\x6a\x76\xd8\xbf\x9a".*,
245 "\xd0\xa7\x04\x53\x6b\xa9\x3e\x0e",245 "\xd0\xa7\x04\x53\x6b\xa9\x3e\x0e".*,
246 "\x92\x59\x58\xfc\xd6\x42\x0c\xad",246 "\x92\x59\x58\xfc\xd6\x42\x0c\xad".*,
247 "\xa9\x15\xc2\x9b\xc8\x06\x73\x18",247 "\xa9\x15\xc2\x9b\xc8\x06\x73\x18".*,
248 "\x95\x2b\x79\xf3\xbc\x0a\xa6\xd4",248 "\x95\x2b\x79\xf3\xbc\x0a\xa6\xd4".*,
249 "\xf2\x1d\xf2\xe4\x1d\x45\x35\xf9",249 "\xf2\x1d\xf2\xe4\x1d\x45\x35\xf9".*,
250 "\x87\x57\x75\x19\x04\x8f\x53\xa9",250 "\x87\x57\x75\x19\x04\x8f\x53\xa9".*,
251 "\x10\xa5\x6c\xf5\xdf\xcd\x9a\xdb",251 "\x10\xa5\x6c\xf5\xdf\xcd\x9a\xdb".*,
252 "\xeb\x75\x09\x5c\xcd\x98\x6c\xd0",252 "\xeb\x75\x09\x5c\xcd\x98\x6c\xd0".*,
253 "\x51\xa9\xcb\x9e\xcb\xa3\x12\xe6",253 "\x51\xa9\xcb\x9e\xcb\xa3\x12\xe6".*,
254 "\x96\xaf\xad\xfc\x2c\xe6\x66\xc7",254 "\x96\xaf\xad\xfc\x2c\xe6\x66\xc7".*,
255 "\x72\xfe\x52\x97\x5a\x43\x64\xee",255 "\x72\xfe\x52\x97\x5a\x43\x64\xee".*,
256 "\x5a\x16\x45\xb2\x76\xd5\x92\xa1",256 "\x5a\x16\x45\xb2\x76\xd5\x92\xa1".*,
257 "\xb2\x74\xcb\x8e\xbf\x87\x87\x0a",257 "\xb2\x74\xcb\x8e\xbf\x87\x87\x0a".*,
258 "\x6f\x9b\xb4\x20\x3d\xe7\xb3\x81",258 "\x6f\x9b\xb4\x20\x3d\xe7\xb3\x81".*,
259 "\xea\xec\xb2\xa3\x0b\x22\xa8\x7f",259 "\xea\xec\xb2\xa3\x0b\x22\xa8\x7f".*,
260 "\x99\x24\xa4\x3c\xc1\x31\x57\x24",260 "\x99\x24\xa4\x3c\xc1\x31\x57\x24".*,
261 "\xbd\x83\x8d\x3a\xaf\xbf\x8d\xb7",261 "\xbd\x83\x8d\x3a\xaf\xbf\x8d\xb7".*,
262 "\x0b\x1a\x2a\x32\x65\xd5\x1a\xea",262 "\x0b\x1a\x2a\x32\x65\xd5\x1a\xea".*,
263 "\x13\x50\x79\xa3\x23\x1c\xe6\x60",263 "\x13\x50\x79\xa3\x23\x1c\xe6\x60".*,
264 "\x93\x2b\x28\x46\xe4\xd7\x06\x66",264 "\x93\x2b\x28\x46\xe4\xd7\x06\x66".*,
265 "\xe1\x91\x5f\x5c\xb1\xec\xa4\x6c",265 "\xe1\x91\x5f\x5c\xb1\xec\xa4\x6c".*,
266 "\xf3\x25\x96\x5c\xa1\x6d\x62\x9f",266 "\xf3\x25\x96\x5c\xa1\x6d\x62\x9f".*,
267 "\x57\x5f\xf2\x8e\x60\x38\x1b\xe5",267 "\x57\x5f\xf2\x8e\x60\x38\x1b\xe5".*,
268 "\x72\x45\x06\xeb\x4c\x32\x8a\x95",268 "\x72\x45\x06\xeb\x4c\x32\x8a\x95".*,
269 };269 };
270270
271 const siphash = SipHash64(2, 4);271 const siphash = SipHash64(2, 4);
...@@ -281,70 +281,70 @@ test "siphash64-2-4 sanity" {...@@ -281,70 +281,70 @@ test "siphash64-2-4 sanity" {
281281
282test "siphash128-2-4 sanity" {282test "siphash128-2-4 sanity" {
283 const vectors = [_][16]u8{283 const vectors = [_][16]u8{
284 "\xa3\x81\x7f\x04\xba\x25\xa8\xe6\x6d\xf6\x72\x14\xc7\x55\x02\x93",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",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",347 "\x51\x50\xd1\x77\x2f\x50\x83\x4a\x50\x3e\x06\x9a\x97\x3f\xbd\x7c".*,
348 };348 };
349349
350 const siphash = SipHash128(2, 4);350 const siphash = SipHash128(2, 4);
lib/std/io/test.zig+2-2
...@@ -595,8 +595,8 @@ test "Deserializer bad data" {...@@ -595,8 +595,8 @@ test "Deserializer bad data" {
595test "c out stream" {595test "c out stream" {
596 if (!builtin.link_libc) return error.SkipZigTest;596 if (!builtin.link_libc) return error.SkipZigTest;
597597
598 const filename = c"tmp_io_test_file.txt";598 const filename = "tmp_io_test_file.txt";
599 const out_file = std.c.fopen(filename, c"w") orelse return error.UnableToOpenTestFile;599 const out_file = std.c.fopen(filename, "w") orelse return error.UnableToOpenTestFile;
600 defer {600 defer {
601 _ = std.c.fclose(out_file);601 _ = std.c.fclose(out_file);
602 fs.deleteFileC(filename) catch {};602 fs.deleteFileC(filename) catch {};
lib/std/mem.zig+10-8
...@@ -1408,7 +1408,9 @@ test "toBytes" {...@@ -1408,7 +1408,9 @@ test "toBytes" {
1408fn BytesAsValueReturnType(comptime T: type, comptime B: type) type {1408fn BytesAsValueReturnType(comptime T: type, comptime B: type) type {
1409 const size = @as(usize, @sizeOf(T));1409 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 {
1412 @compileError("expected *[N]u8 " ++ ", passed " ++ @typeName(B));1414 @compileError("expected *[N]u8 " ++ ", passed " ++ @typeName(B));
1413 }1415 }
14141416
...@@ -1430,12 +1432,12 @@ test "bytesAsValue" {...@@ -1430,12 +1432,12 @@ test "bytesAsValue" {
1430 builtin.Endian.Little => "\xEF\xBE\xAD\xDE",1432 builtin.Endian.Little => "\xEF\xBE\xAD\xDE",
1431 };1433 };
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) {
1436 builtin.Endian.Big => "\xC0\xDE\xFA\xCE",1438 builtin.Endian.Big => "\xC0\xDE\xFA\xCE",
1437 builtin.Endian.Little => "\xCE\xFA\xDE\xC0",1439 builtin.Endian.Little => "\xCE\xFA\xDE\xC0",
1438 };1440 }.*;
1439 var codeface = bytesAsValue(u32, &codeface_bytes);1441 var codeface = bytesAsValue(u32, &codeface_bytes);
1440 testing.expect(codeface.* == 0xC0DEFACE);1442 testing.expect(codeface.* == 0xC0DEFACE);
1441 codeface.* = 0;1443 codeface.* = 0;
...@@ -1456,14 +1458,14 @@ test "bytesAsValue" {...@@ -1456,14 +1458,14 @@ test "bytesAsValue" {
1456 .d = 0xA1,1458 .d = 0xA1,
1457 };1459 };
1458 const inst_bytes = "\xBE\xEF\xDE\xA1";1460 const inst_bytes = "\xBE\xEF\xDE\xA1";
1459 const inst2 = bytesAsValue(S, &inst_bytes);1461 const inst2 = bytesAsValue(S, inst_bytes);
1460 testing.expect(meta.eql(inst, inst2.*));1462 testing.expect(meta.eql(inst, inst2.*));
1461}1463}
14621464
1463///Given a pointer to an array of bytes, returns a value of the specified type backed by a1465///Given a pointer to an array of bytes, returns a value of the specified type backed by a
1464/// copy of those bytes.1466/// copy of those bytes.
1465pub fn bytesToValue(comptime T: type, bytes: var) T {1467pub fn bytesToValue(comptime T: type, bytes: var) T {
1466 return bytesAsValue(T, &bytes).*;1468 return bytesAsValue(T, bytes).*;
1467}1469}
1468test "bytesToValue" {1470test "bytesToValue" {
1469 const deadbeef_bytes = switch (builtin.endian) {1471 const deadbeef_bytes = switch (builtin.endian) {
...@@ -1491,11 +1493,11 @@ pub fn subArrayPtr(ptr: var, comptime start: usize, comptime length: usize) SubA...@@ -1491,11 +1493,11 @@ pub fn subArrayPtr(ptr: var, comptime start: usize, comptime length: usize) SubA
1491}1493}
14921494
1493test "subArrayPtr" {1495test "subArrayPtr" {
1494 const a1 = "abcdef";1496 const a1: [6]u8 = "abcdef".*;
1495 const sub1 = subArrayPtr(&a1, 2, 3);1497 const sub1 = subArrayPtr(&a1, 2, 3);
1496 testing.expect(eql(u8, sub1.*, "cde"));1498 testing.expect(eql(u8, sub1.*, "cde"));
14971499
1498 var a2 = "abcdef";1500 var a2: [6]u8 = "abcdef".*;
1499 var sub2 = subArrayPtr(&a2, 2, 3);1501 var sub2 = subArrayPtr(&a2, 2, 3);
15001502
1501 testing.expect(eql(u8, sub2, "cde"));1503 testing.expect(eql(u8, sub2, "cde"));
lib/std/meta.zig+6-7
...@@ -469,19 +469,19 @@ test "std.meta.eql" {...@@ -469,19 +469,19 @@ test "std.meta.eql" {
469 const s_1 = S{469 const s_1 = S{
470 .a = 134,470 .a = 134,
471 .b = 123.3,471 .b = 123.3,
472 .c = "12345",472 .c = "12345".*,
473 };473 };
474474
475 const s_2 = S{475 const s_2 = S{
476 .a = 1,476 .a = 1,
477 .b = 123.3,477 .b = 123.3,
478 .c = "54321",478 .c = "54321".*,
479 };479 };
480480
481 const s_3 = S{481 const s_3 = S{
482 .a = 134,482 .a = 134,
483 .b = 123.3,483 .b = 123.3,
484 .c = "12345",484 .c = "12345".*,
485 };485 };
486486
487 const u_1 = U{ .f = 24 };487 const u_1 = U{ .f = 24 };
...@@ -494,9 +494,9 @@ test "std.meta.eql" {...@@ -494,9 +494,9 @@ test "std.meta.eql" {
494 testing.expect(eql(u_1, u_3));494 testing.expect(eql(u_1, u_3));
495 testing.expect(!eql(u_1, u_2));495 testing.expect(!eql(u_1, u_2));
496496
497 var a1 = "abcdef";497 var a1 = "abcdef".*;
498 var a2 = "abcdef";498 var a2 = "abcdef".*;
499 var a3 = "ghijkl";499 var a3 = "ghijkl".*;
500500
501 testing.expect(eql(a1, a2));501 testing.expect(eql(a1, a2));
502 testing.expect(!eql(a1, a3));502 testing.expect(!eql(a1, a3));
...@@ -558,4 +558,3 @@ pub fn refAllDecls(comptime T: type) void {...@@ -558,4 +558,3 @@ pub fn refAllDecls(comptime T: type) void {
558 if (!builtin.is_test) return;558 if (!builtin.is_test) return;
559 _ = declarations(T);559 _ = declarations(T);
560}560}
561
lib/std/meta/trait.zig-2
...@@ -319,7 +319,6 @@ test "std.meta.trait.isNumber" {...@@ -319,7 +319,6 @@ test "std.meta.trait.isNumber" {
319 testing.expect(!isNumber(NotANumber));319 testing.expect(!isNumber(NotANumber));
320}320}
321321
322///
323pub fn isConstPtr(comptime T: type) bool {322pub fn isConstPtr(comptime T: type) bool {
324 if (!comptime is(builtin.TypeId.Pointer)(T)) return false;323 if (!comptime is(builtin.TypeId.Pointer)(T)) return false;
325 const info = @typeInfo(T);324 const info = @typeInfo(T);
...@@ -335,7 +334,6 @@ test "std.meta.trait.isConstPtr" {...@@ -335,7 +334,6 @@ test "std.meta.trait.isConstPtr" {
335 testing.expect(!isConstPtr(@typeOf(6)));334 testing.expect(!isConstPtr(@typeOf(6)));
336}335}
337336
338///
339pub fn isContainer(comptime T: type) bool {337pub fn isContainer(comptime T: type) bool {
340 const info = @typeInfo(T);338 const info = @typeInfo(T);
341 return switch (info) {339 return switch (info) {
lib/std/net.zig+8-8
...@@ -666,35 +666,35 @@ const Policy = struct {...@@ -666,35 +666,35 @@ const Policy = struct {
666666
667const defined_policies = [_]Policy{667const defined_policies = [_]Policy{
668 Policy{668 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".*,
670 .len = 15,670 .len = 15,
671 .mask = 0xff,671 .mask = 0xff,
672 .prec = 50,672 .prec = 50,
673 .label = 0,673 .label = 0,
674 },674 },
675 Policy{675 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".*,
677 .len = 11,677 .len = 11,
678 .mask = 0xff,678 .mask = 0xff,
679 .prec = 35,679 .prec = 35,
680 .label = 4,680 .label = 4,
681 },681 },
682 Policy{682 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".*,
684 .len = 1,684 .len = 1,
685 .mask = 0xff,685 .mask = 0xff,
686 .prec = 30,686 .prec = 30,
687 .label = 2,687 .label = 2,
688 },688 },
689 Policy{689 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".*,
691 .len = 3,691 .len = 3,
692 .mask = 0xff,692 .mask = 0xff,
693 .prec = 5,693 .prec = 5,
694 .label = 5,694 .label = 5,
695 },695 },
696 Policy{696 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".*,
698 .len = 0,698 .len = 0,
699 .mask = 0xfe,699 .mask = 0xfe,
700 .prec = 3,700 .prec = 3,
...@@ -708,7 +708,7 @@ const defined_policies = [_]Policy{...@@ -708,7 +708,7 @@ const defined_policies = [_]Policy{
708 // { "\x3f\xfe", 1, 0xff, 1, 12 },708 // { "\x3f\xfe", 1, 0xff, 1, 12 },
709 // Last rule must match all addresses to stop loop.709 // Last rule must match all addresses to stop loop.
710 Policy{710 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".*,
712 .len = 0,712 .len = 0,
713 .mask = 0,713 .mask = 0,
714 .prec = 40,714 .prec = 40,
...@@ -812,7 +812,7 @@ fn linuxLookupNameFromHosts(...@@ -812,7 +812,7 @@ fn linuxLookupNameFromHosts(
812 family: os.sa_family_t,812 family: os.sa_family_t,
813 port: u16,813 port: u16,
814) !void {814) !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) {
816 error.FileNotFound,816 error.FileNotFound,
817 error.NotDir,817 error.NotDir,
818 error.AccessDenied,818 error.AccessDenied,
...@@ -1006,7 +1006,7 @@ fn getResolvConf(allocator: *mem.Allocator, rc: *ResolvConf) !void {...@@ -1006,7 +1006,7 @@ fn getResolvConf(allocator: *mem.Allocator, rc: *ResolvConf) !void {
1006 };1006 };
1007 errdefer rc.deinit();1007 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) {
1010 error.FileNotFound,1010 error.FileNotFound,
1011 error.NotDir,1011 error.NotDir,
1012 error.AccessDenied,1012 error.AccessDenied,
lib/std/os.zig+2-2
...@@ -157,7 +157,7 @@ pub fn getrandom(buffer: []u8) GetRandomError!void {...@@ -157,7 +157,7 @@ pub fn getrandom(buffer: []u8) GetRandomError!void {
157}157}
158158
159fn getRandomBytesDevURandom(buf: []u8) !void {159fn 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);
161 defer close(fd);161 defer close(fd);
162162
163 const st = try fstat(fd);163 const st = try fstat(fd);
...@@ -2674,7 +2674,7 @@ pub fn dl_iterate_phdr(...@@ -2674,7 +2674,7 @@ pub fn dl_iterate_phdr(
2674 if (it.end()) {2674 if (it.end()) {
2675 var info = dl_phdr_info{2675 var info = dl_phdr_info{
2676 .dlpi_addr = elf_base,2676 .dlpi_addr = elf_base,
2677 .dlpi_name = c"/proc/self/exe",2677 .dlpi_name = "/proc/self/exe",
2678 .dlpi_phdr = phdrs.ptr,2678 .dlpi_phdr = phdrs.ptr,
2679 .dlpi_phnum = ehdr.e_phnum,2679 .dlpi_phnum = ehdr.e_phnum,
2680 };2680 };
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...@@ -1053,7 +1053,7 @@ pub fn dl_iterate_phdr(comptime T: type, callback: extern fn (info: *dl_phdr_inf
1053 if (it.end()) {1053 if (it.end()) {
1054 var info = dl_phdr_info{1054 var info = dl_phdr_info{
1055 .dlpi_addr = elf_base,1055 .dlpi_addr = elf_base,
1056 .dlpi_name = c"/proc/self/exe",1056 .dlpi_name = "/proc/self/exe",
1057 .dlpi_phdr = @intToPtr([*]elf.Phdr, elf_base + __ehdr_start.e_phoff),1057 .dlpi_phdr = @intToPtr([*]elf.Phdr, elf_base + __ehdr_start.e_phoff),
1058 .dlpi_phnum = __ehdr_start.e_phnum,1058 .dlpi_phnum = __ehdr_start.e_phnum,
1059 };1059 };
lib/std/os/linux/test.zig+2-2
...@@ -56,7 +56,7 @@ test "statx" {...@@ -56,7 +56,7 @@ test "statx" {
56 }56 }
5757
58 var statx_buf: linux.Statx = undefined;58 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))) {
60 0 => {},60 0 => {},
61 // The statx syscall was only introduced in linux 4.1161 // The statx syscall was only introduced in linux 4.11
62 linux.ENOSYS => return error.SkipZigTest,62 linux.ENOSYS => return error.SkipZigTest,
...@@ -64,7 +64,7 @@ test "statx" {...@@ -64,7 +64,7 @@ test "statx" {
64 }64 }
6565
66 var stat_buf: linux.Stat = undefined;66 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))) {
68 0 => {},68 0 => {},
69 else => unreachable,69 else => unreachable,
70 }70 }
lib/std/process.zig+8-8
...@@ -473,14 +473,14 @@ pub fn argsFree(allocator: *mem.Allocator, args_alloc: []const []u8) void {...@@ -473,14 +473,14 @@ pub fn argsFree(allocator: *mem.Allocator, args_alloc: []const []u8) void {
473}473}
474474
475test "windows arg parsing" {475test "windows arg parsing" {
476 testWindowsCmdLine(c"a b\tc d", [_][]const u8{ "a", "b", "c", "d" });476 testWindowsCmdLine("a b\tc d", [_][]const u8{ "a", "b", "c", "d" });
477 testWindowsCmdLine(c"\"abc\" d e", [_][]const u8{ "abc", "d", "e" });477 testWindowsCmdLine("\"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" });478 testWindowsCmdLine("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" });479 testWindowsCmdLine("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" });480 testWindowsCmdLine("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" });481 testWindowsCmdLine("a b\tc \"d f", [_][]const u8{ "a", "b", "c", "\"d", "f" });
482482
483 testWindowsCmdLine(c"\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\"", [_][]const u8{483 testWindowsCmdLine("\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\"", [_][]const u8{
484 ".\\..\\zig-cache\\build",484 ".\\..\\zig-cache\\build",
485 "bin\\zig.exe",485 "bin\\zig.exe",
486 ".\\..",486 ".\\..",
lib/std/special/c.zig+5-5
...@@ -66,14 +66,14 @@ extern fn strncmp(_l: [*]const u8, _r: [*]const u8, _n: usize) c_int {...@@ -66,14 +66,14 @@ extern fn strncmp(_l: [*]const u8, _r: [*]const u8, _n: usize) c_int {
66}66}
6767
68extern fn strerror(errnum: c_int) [*]const u8 {68extern fn strerror(errnum: c_int) [*]const u8 {
69 return c"TODO strerror implementation";69 return "TODO strerror implementation";
70}70}
7171
72test "strncmp" {72test "strncmp" {
73 std.testing.expect(strncmp(c"a", c"b", 1) == -1);73 std.testing.expect(strncmp("a", "b", 1) == -1);
74 std.testing.expect(strncmp(c"a", c"c", 1) == -2);74 std.testing.expect(strncmp("a", "c", 1) == -2);
75 std.testing.expect(strncmp(c"b", c"a", 1) == 1);75 std.testing.expect(strncmp("b", "a", 1) == 1);
76 std.testing.expect(strncmp(c"\xff", c"\x02", 1) == 253);76 std.testing.expect(strncmp("\xff", "\x02", 1) == 253);
77}77}
7878
79// Avoid dragging in the runtime safety mechanisms into this .o file,79// 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 {...@@ -353,7 +353,7 @@ pub const Thread = struct {
353 }353 }
354 var count: c_int = undefined;354 var count: c_int = undefined;
355 var count_len: usize = @sizeOf(c_int);355 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";
357 os.sysctlbynameC(name, &count, &count_len, null, 0) catch |err| switch (err) {357 os.sysctlbynameC(name, &count, &count_len, null, 0) catch |err| switch (err) {
358 error.NameTooLong => unreachable,358 error.NameTooLong => unreachable,
359 else => |e| return e,359 else => |e| return e,
lib/std/valgrind/memcheck.zig+1-1
...@@ -3,7 +3,7 @@ const testing = std.testing;...@@ -3,7 +3,7 @@ const testing = std.testing;
3const valgrind = std.valgrind;3const valgrind = std.valgrind;
44
5pub const MemCheckClientRequest = extern enum {5pub const MemCheckClientRequest = extern enum {
6 MakeMemNoAccess = valgrind.ToolBase("MC"),6 MakeMemNoAccess = valgrind.ToolBase("MC".*),
7 MakeMemUndefined,7 MakeMemUndefined,
8 MakeMemDefined,8 MakeMemDefined,
9 Discard,9 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)...@@ -52,7 +52,7 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code)
52 u32(c.ZIG_VERSION_MINOR),52 u32(c.ZIG_VERSION_MINOR),
53 u32(c.ZIG_VERSION_PATCH),53 u32(c.ZIG_VERSION_PATCH),
54 );54 );
55 const flags = c"";55 const flags = "";
56 const runtime_version = 0;56 const runtime_version = 0;
57 const compile_unit_file = llvm.CreateFile(57 const compile_unit_file = llvm.CreateFile(
58 dibuilder,58 dibuilder,
...@@ -68,7 +68,7 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code)...@@ -68,7 +68,7 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code)
68 is_optimized,68 is_optimized,
69 flags,69 flags,
70 runtime_version,70 runtime_version,
71 c"",71 "",
72 0,72 0,
73 !comp.strip,73 !comp.strip,
74 ) orelse return error.OutOfMemory;74 ) orelse return error.OutOfMemory;
...@@ -402,7 +402,7 @@ pub fn getHandleValue(ofile: *ObjectFile, ptr: *llvm.Value, ptr_type: *Type.Poin...@@ -402,7 +402,7 @@ pub fn getHandleValue(ofile: *ObjectFile, ptr: *llvm.Value, ptr_type: *Type.Poin
402 if (child_type.handleIsPtr()) {402 if (child_type.handleIsPtr()) {
403 return ptr;403 return ptr;
404 }404 }
405 return try renderLoad(ofile, ptr, ptr_type, c"");405 return try renderLoad(ofile, ptr, ptr_type, "");
406}406}
407407
408pub fn renderStoreUntyped(408pub fn renderStoreUntyped(
src-self-hosted/compilation.zig+2-2
...@@ -511,8 +511,8 @@ pub const Compilation = struct {...@@ -511,8 +511,8 @@ pub const Compilation = struct {
511 comp.target_machine = llvm.CreateTargetMachine(511 comp.target_machine = llvm.CreateTargetMachine(
512 comp.llvm_target,512 comp.llvm_target,
513 comp.llvm_triple.ptr(),513 comp.llvm_triple.ptr(),
514 target_specific_cpu_args orelse c"",514 target_specific_cpu_args orelse "",
515 target_specific_cpu_features orelse c"",515 target_specific_cpu_features orelse "",
516 opt_level,516 opt_level,
517 reloc_mode,517 reloc_mode,
518 llvm.CodeModelDefault,518 llvm.CodeModelDefault,
src-self-hosted/ir.zig+6-6
...@@ -331,7 +331,7 @@ pub const Inst = struct {...@@ -331,7 +331,7 @@ pub const Inst = struct {
331 @intCast(c_uint, args.len),331 @intCast(c_uint, args.len),
332 llvm_cc,332 llvm_cc,
333 fn_inline,333 fn_inline,
334 c"",334 "",
335 ) orelse error.OutOfMemory;335 ) orelse error.OutOfMemory;
336 }336 }
337 };337 };
...@@ -1410,7 +1410,7 @@ pub const Builder = struct {...@@ -1410,7 +1410,7 @@ pub const Builder = struct {
1410 if (block.label) |label| {1410 if (block.label) |label| {
1411 block_scope.incoming_values = std.ArrayList(*Inst).init(irb.arena());1411 block_scope.incoming_values = std.ArrayList(*Inst).init(irb.arena());
1412 block_scope.incoming_blocks = std.ArrayList(*BasicBlock).init(irb.arena());1412 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");
1414 block_scope.is_comptime = try irb.buildConstBool(1414 block_scope.is_comptime = try irb.buildConstBool(
1415 parent_scope,1415 parent_scope,
1416 Span.token(block.lbrace),1416 Span.token(block.lbrace),
...@@ -1542,8 +1542,8 @@ pub const Builder = struct {...@@ -1542,8 +1542,8 @@ pub const Builder = struct {
1542 const defer_counts = irb.countDefers(scope, outer_scope);1542 const defer_counts = irb.countDefers(scope, outer_scope);
1543 const have_err_defers = defer_counts.error_exit != 0;1543 const have_err_defers = defer_counts.error_exit != 0;
1544 if (have_err_defers or irb.comp.have_err_ret_tracing) {1544 if (have_err_defers or irb.comp.have_err_ret_tracing) {
1545 const err_block = try irb.createBasicBlock(scope, c"ErrRetErr");1545 const err_block = try irb.createBasicBlock(scope, "ErrRetErr");
1546 const ok_block = try irb.createBasicBlock(scope, c"ErrRetOk");1546 const ok_block = try irb.createBasicBlock(scope, "ErrRetOk");
1547 if (!have_err_defers) {1547 if (!have_err_defers) {
1548 _ = try await (async irb.genDefersForBlock(scope, outer_scope, Scope.Defer.Kind.ScopeExit) catch unreachable);1548 _ = try await (async irb.genDefersForBlock(scope, outer_scope, Scope.Defer.Kind.ScopeExit) catch unreachable);
1549 }1549 }
...@@ -1564,7 +1564,7 @@ pub const Builder = struct {...@@ -1564,7 +1564,7 @@ pub const Builder = struct {
1564 .is_comptime = err_is_comptime,1564 .is_comptime = err_is_comptime,
1565 });1565 });
15661566
1567 const ret_stmt_block = try irb.createBasicBlock(scope, c"RetStmt");1567 const ret_stmt_block = try irb.createBasicBlock(scope, "RetStmt");
15681568
1569 try irb.setCursorAtEndAndAppendBlock(err_block);1569 try irb.setCursorAtEndAndAppendBlock(err_block);
1570 if (have_err_defers) {1570 if (have_err_defers) {
...@@ -2530,7 +2530,7 @@ pub async fn gen(...@@ -2530,7 +2530,7 @@ pub async fn gen(
2530 var irb = try Builder.init(comp, tree_scope, scope);2530 var irb = try Builder.init(comp, tree_scope, scope);
2531 errdefer irb.abort();2531 errdefer irb.abort();
25322532
2533 const entry_block = try irb.createBasicBlock(scope, c"Entry");2533 const entry_block = try irb.createBasicBlock(scope, "Entry");
2534 entry_block.ref(&irb); // Entry block gets a reference because we enter it to begin.2534 entry_block.ref(&irb); // Entry block gets a reference because we enter it to begin.
2535 try irb.setCursorAtEndAndAppendBlock(entry_block);2535 try irb.setCursorAtEndAndAppendBlock(entry_block);
25362536
src-self-hosted/link.zig+63-63
...@@ -55,7 +55,7 @@ pub async fn link(comp: *Compilation) !void {...@@ -55,7 +55,7 @@ pub async fn link(comp: *Compilation) !void {
5555
56 // even though we're calling LLD as a library it thinks the first56 // even though we're calling LLD as a library it thinks the first
57 // argument is its own exe name57 // argument is its own exe name
58 try ctx.args.append(c"lld");58 try ctx.args.append("lld");
5959
60 if (comp.haveLibC()) {60 if (comp.haveLibC()) {
61 ctx.libc = ctx.comp.override_libc orelse blk: {61 ctx.libc = ctx.comp.override_libc orelse blk: {
...@@ -145,7 +145,7 @@ fn constructLinkerArgsElf(ctx: *Context) !void {...@@ -145,7 +145,7 @@ fn constructLinkerArgsElf(ctx: *Context) !void {
145 // lj->args.append("-T");145 // lj->args.append("-T");
146 // lj->args.append(g->linker_script);146 // lj->args.append(g->linker_script);
147 //}147 //}
148 try ctx.args.append(c"--gc-sections");148 try ctx.args.append("--gc-sections");
149149
150 //lj->args.append("-m");150 //lj->args.append("-m");
151 //lj->args.append(getLDMOption(&g->zig_target));151 //lj->args.append(getLDMOption(&g->zig_target));
...@@ -155,9 +155,9 @@ fn constructLinkerArgsElf(ctx: *Context) !void {...@@ -155,9 +155,9 @@ fn constructLinkerArgsElf(ctx: *Context) !void {
155 //Buf *soname = nullptr;155 //Buf *soname = nullptr;
156 if (ctx.comp.is_static) {156 if (ctx.comp.is_static) {
157 if (ctx.comp.target.isArmOrThumb()) {157 if (ctx.comp.target.isArmOrThumb()) {
158 try ctx.args.append(c"-Bstatic");158 try ctx.args.append("-Bstatic");
159 } else {159 } else {
160 try ctx.args.append(c"-static");160 try ctx.args.append("-static");
161 }161 }
162 }162 }
163 //} else if (shared) {163 //} else if (shared) {
...@@ -170,7 +170,7 @@ fn constructLinkerArgsElf(ctx: *Context) !void {...@@ -170,7 +170,7 @@ fn constructLinkerArgsElf(ctx: *Context) !void {
170 // soname = buf_sprintf("lib%s.so.%" ZIG_PRI_usize "", buf_ptr(g->root_out_name), g->version_major);170 // soname = buf_sprintf("lib%s.so.%" ZIG_PRI_usize "", buf_ptr(g->root_out_name), g->version_major);
171 //}171 //}
172172
173 try ctx.args.append(c"-o");173 try ctx.args.append("-o");
174 try ctx.args.append(ctx.out_file_path.ptr());174 try ctx.args.append(ctx.out_file_path.ptr());
175175
176 if (ctx.link_in_crt) {176 if (ctx.link_in_crt) {
...@@ -213,10 +213,10 @@ fn constructLinkerArgsElf(ctx: *Context) !void {...@@ -213,10 +213,10 @@ fn constructLinkerArgsElf(ctx: *Context) !void {
213 //}213 //}
214214
215 if (ctx.comp.haveLibC()) {215 if (ctx.comp.haveLibC()) {
216 try ctx.args.append(c"-L");216 try ctx.args.append("-L");
217 try ctx.args.append((try std.cstr.addNullByte(&ctx.arena.allocator, ctx.libc.lib_dir.?)).ptr);217 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");
220 try ctx.args.append((try std.cstr.addNullByte(&ctx.arena.allocator, ctx.libc.static_lib_dir.?)).ptr);220 try ctx.args.append((try std.cstr.addNullByte(&ctx.arena.allocator, ctx.libc.static_lib_dir.?)).ptr);
221221
222 if (!ctx.comp.is_static) {222 if (!ctx.comp.is_static) {
...@@ -225,7 +225,7 @@ fn constructLinkerArgsElf(ctx: *Context) !void {...@@ -225,7 +225,7 @@ fn constructLinkerArgsElf(ctx: *Context) !void {
225 if (ctx.comp.target.getDynamicLinkerPath()) |dl| break :blk dl;225 if (ctx.comp.target.getDynamicLinkerPath()) |dl| break :blk dl;
226 return error.LibCMissingDynamicLinker;226 return error.LibCMissingDynamicLinker;
227 };227 };
228 try ctx.args.append(c"-dynamic-linker");228 try ctx.args.append("-dynamic-linker");
229 try ctx.args.append((try std.cstr.addNullByte(&ctx.arena.allocator, dl)).ptr);229 try ctx.args.append((try std.cstr.addNullByte(&ctx.arena.allocator, dl)).ptr);
230 }230 }
231 }231 }
...@@ -272,23 +272,23 @@ fn constructLinkerArgsElf(ctx: *Context) !void {...@@ -272,23 +272,23 @@ fn constructLinkerArgsElf(ctx: *Context) !void {
272 // libc dep272 // libc dep
273 if (ctx.comp.haveLibC()) {273 if (ctx.comp.haveLibC()) {
274 if (ctx.comp.is_static) {274 if (ctx.comp.is_static) {
275 try ctx.args.append(c"--start-group");275 try ctx.args.append("--start-group");
276 try ctx.args.append(c"-lgcc");276 try ctx.args.append("-lgcc");
277 try ctx.args.append(c"-lgcc_eh");277 try ctx.args.append("-lgcc_eh");
278 try ctx.args.append(c"-lc");278 try ctx.args.append("-lc");
279 try ctx.args.append(c"-lm");279 try ctx.args.append("-lm");
280 try ctx.args.append(c"--end-group");280 try ctx.args.append("--end-group");
281 } else {281 } else {
282 try ctx.args.append(c"-lgcc");282 try ctx.args.append("-lgcc");
283 try ctx.args.append(c"--as-needed");283 try ctx.args.append("--as-needed");
284 try ctx.args.append(c"-lgcc_s");284 try ctx.args.append("-lgcc_s");
285 try ctx.args.append(c"--no-as-needed");285 try ctx.args.append("--no-as-needed");
286 try ctx.args.append(c"-lc");286 try ctx.args.append("-lc");
287 try ctx.args.append(c"-lm");287 try ctx.args.append("-lm");
288 try ctx.args.append(c"-lgcc");288 try ctx.args.append("-lgcc");
289 try ctx.args.append(c"--as-needed");289 try ctx.args.append("--as-needed");
290 try ctx.args.append(c"-lgcc_s");290 try ctx.args.append("-lgcc_s");
291 try ctx.args.append(c"--no-as-needed");291 try ctx.args.append("--no-as-needed");
292 }292 }
293 }293 }
294294
...@@ -299,14 +299,14 @@ fn constructLinkerArgsElf(ctx: *Context) !void {...@@ -299,14 +299,14 @@ fn constructLinkerArgsElf(ctx: *Context) !void {
299 }299 }
300300
301 if (ctx.comp.target != Target.Native) {301 if (ctx.comp.target != Target.Native) {
302 try ctx.args.append(c"--allow-shlib-undefined");302 try ctx.args.append("--allow-shlib-undefined");
303 }303 }
304304
305 if (ctx.comp.target.getOs() == .zen) {305 if (ctx.comp.target.getOs() == .zen) {
306 try ctx.args.append(c"-e");306 try ctx.args.append("-e");
307 try ctx.args.append(c"_start");307 try ctx.args.append("_start");
308308
309 try ctx.args.append(c"--image-base=0x10000000");309 try ctx.args.append("--image-base=0x10000000");
310 }310 }
311}311}
312312
...@@ -317,23 +317,23 @@ fn addPathJoin(ctx: *Context, dirname: []const u8, basename: []const u8) !void {...@@ -317,23 +317,23 @@ fn addPathJoin(ctx: *Context, dirname: []const u8, basename: []const u8) !void {
317}317}
318318
319fn constructLinkerArgsCoff(ctx: *Context) !void {319fn constructLinkerArgsCoff(ctx: *Context) !void {
320 try ctx.args.append(c"-NOLOGO");320 try ctx.args.append("-NOLOGO");
321321
322 if (!ctx.comp.strip) {322 if (!ctx.comp.strip) {
323 try ctx.args.append(c"-DEBUG");323 try ctx.args.append("-DEBUG");
324 }324 }
325325
326 switch (ctx.comp.target.getArch()) {326 switch (ctx.comp.target.getArch()) {
327 builtin.Arch.i386 => try ctx.args.append(c"-MACHINE:X86"),327 builtin.Arch.i386 => try ctx.args.append("-MACHINE:X86"),
328 builtin.Arch.x86_64 => try ctx.args.append(c"-MACHINE:X64"),328 builtin.Arch.x86_64 => try ctx.args.append("-MACHINE:X64"),
329 builtin.Arch.aarch64 => try ctx.args.append(c"-MACHINE:ARM"),329 builtin.Arch.aarch64 => try ctx.args.append("-MACHINE:ARM"),
330 else => return error.UnsupportedLinkArchitecture,330 else => return error.UnsupportedLinkArchitecture,
331 }331 }
332332
333 if (ctx.comp.windows_subsystem_windows) {333 if (ctx.comp.windows_subsystem_windows) {
334 try ctx.args.append(c"/SUBSYSTEM:windows");334 try ctx.args.append("/SUBSYSTEM:windows");
335 } else if (ctx.comp.windows_subsystem_console) {335 } else if (ctx.comp.windows_subsystem_console) {
336 try ctx.args.append(c"/SUBSYSTEM:console");336 try ctx.args.append("/SUBSYSTEM:console");
337 }337 }
338338
339 const is_library = ctx.comp.kind == Compilation.Kind.Lib;339 const is_library = ctx.comp.kind == Compilation.Kind.Lib;
...@@ -367,14 +367,14 @@ fn constructLinkerArgsCoff(ctx: *Context) !void {...@@ -367,14 +367,14 @@ fn constructLinkerArgsCoff(ctx: *Context) !void {
367367
368 // Visual C++ 2015 Conformance Changes368 // Visual C++ 2015 Conformance Changes
369 // https://msdn.microsoft.com/en-us/library/bb531344.aspx369 // 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
372 // msvcrt depends on kernel32372 // msvcrt depends on kernel32
373 try ctx.args.append(c"kernel32.lib");373 try ctx.args.append("kernel32.lib");
374 } else {374 } else {
375 try ctx.args.append(c"-NODEFAULTLIB");375 try ctx.args.append("-NODEFAULTLIB");
376 if (!is_library) {376 if (!is_library) {
377 try ctx.args.append(c"-ENTRY:WinMainCRTStartup");377 try ctx.args.append("-ENTRY:WinMainCRTStartup");
378 // TODO378 // TODO
379 //if (g->have_winmain) {379 //if (g->have_winmain) {
380 // lj->args.append("-ENTRY:WinMain");380 // lj->args.append("-ENTRY:WinMain");
...@@ -385,7 +385,7 @@ fn constructLinkerArgsCoff(ctx: *Context) !void {...@@ -385,7 +385,7 @@ fn constructLinkerArgsCoff(ctx: *Context) !void {
385 }385 }
386386
387 if (is_library and !ctx.comp.is_static) {387 if (is_library and !ctx.comp.is_static) {
388 try ctx.args.append(c"-DLL");388 try ctx.args.append("-DLL");
389 }389 }
390390
391 //for (size_t i = 0; i < g->lib_dirs.length; i += 1) {391 //for (size_t i = 0; i < g->lib_dirs.length; i += 1) {
...@@ -463,18 +463,18 @@ fn constructLinkerArgsCoff(ctx: *Context) !void {...@@ -463,18 +463,18 @@ fn constructLinkerArgsCoff(ctx: *Context) !void {
463}463}
464464
465fn constructLinkerArgsMachO(ctx: *Context) !void {465fn constructLinkerArgsMachO(ctx: *Context) !void {
466 try ctx.args.append(c"-demangle");466 try ctx.args.append("-demangle");
467467
468 if (ctx.comp.linker_rdynamic) {468 if (ctx.comp.linker_rdynamic) {
469 try ctx.args.append(c"-export_dynamic");469 try ctx.args.append("-export_dynamic");
470 }470 }
471471
472 const is_lib = ctx.comp.kind == Compilation.Kind.Lib;472 const is_lib = ctx.comp.kind == Compilation.Kind.Lib;
473 const shared = !ctx.comp.is_static and is_lib;473 const shared = !ctx.comp.is_static and is_lib;
474 if (ctx.comp.is_static) {474 if (ctx.comp.is_static) {
475 try ctx.args.append(c"-static");475 try ctx.args.append("-static");
476 } else {476 } else {
477 try ctx.args.append(c"-dynamic");477 try ctx.args.append("-dynamic");
478 }478 }
479479
480 //if (is_lib) {480 //if (is_lib) {
...@@ -503,7 +503,7 @@ fn constructLinkerArgsMachO(ctx: *Context) !void {...@@ -503,7 +503,7 @@ fn constructLinkerArgsMachO(ctx: *Context) !void {
503 // }503 // }
504 //}504 //}
505505
506 try ctx.args.append(c"-arch");506 try ctx.args.append("-arch");
507 const darwin_arch_str = try std.cstr.addNullByte(507 const darwin_arch_str = try std.cstr.addNullByte(
508 &ctx.arena.allocator,508 &ctx.arena.allocator,
509 ctx.comp.target.getDarwinArchString(),509 ctx.comp.target.getDarwinArchString(),
...@@ -512,22 +512,22 @@ fn constructLinkerArgsMachO(ctx: *Context) !void {...@@ -512,22 +512,22 @@ fn constructLinkerArgsMachO(ctx: *Context) !void {
512512
513 const platform = try DarwinPlatform.get(ctx.comp);513 const platform = try DarwinPlatform.get(ctx.comp);
514 switch (platform.kind) {514 switch (platform.kind) {
515 DarwinPlatform.Kind.MacOS => try ctx.args.append(c"-macosx_version_min"),515 DarwinPlatform.Kind.MacOS => try ctx.args.append("-macosx_version_min"),
516 DarwinPlatform.Kind.IPhoneOS => try ctx.args.append(c"-iphoneos_version_min"),516 DarwinPlatform.Kind.IPhoneOS => try ctx.args.append("-iphoneos_version_min"),
517 DarwinPlatform.Kind.IPhoneOSSimulator => try ctx.args.append(c"-ios_simulator_version_min"),517 DarwinPlatform.Kind.IPhoneOSSimulator => try ctx.args.append("-ios_simulator_version_min"),
518 }518 }
519 const ver_str = try std.fmt.allocPrint(&ctx.arena.allocator, "{}.{}.{}\x00", platform.major, platform.minor, platform.micro);519 const ver_str = try std.fmt.allocPrint(&ctx.arena.allocator, "{}.{}.{}\x00", platform.major, platform.minor, platform.micro);
520 try ctx.args.append(ver_str.ptr);520 try ctx.args.append(ver_str.ptr);
521521
522 if (ctx.comp.kind == Compilation.Kind.Exe) {522 if (ctx.comp.kind == Compilation.Kind.Exe) {
523 if (ctx.comp.is_static) {523 if (ctx.comp.is_static) {
524 try ctx.args.append(c"-no_pie");524 try ctx.args.append("-no_pie");
525 } else {525 } else {
526 try ctx.args.append(c"-pie");526 try ctx.args.append("-pie");
527 }527 }
528 }528 }
529529
530 try ctx.args.append(c"-o");530 try ctx.args.append("-o");
531 try ctx.args.append(ctx.out_file_path.ptr());531 try ctx.args.append(ctx.out_file_path.ptr());
532532
533 //for (size_t i = 0; i < g->rpath_list.length; i += 1) {533 //for (size_t i = 0; i < g->rpath_list.length; i += 1) {
...@@ -537,27 +537,27 @@ fn constructLinkerArgsMachO(ctx: *Context) !void {...@@ -537,27 +537,27 @@ fn constructLinkerArgsMachO(ctx: *Context) !void {
537 //add_rpath(lj, &lj->out_file);537 //add_rpath(lj, &lj->out_file);
538538
539 if (shared) {539 if (shared) {
540 try ctx.args.append(c"-headerpad_max_install_names");540 try ctx.args.append("-headerpad_max_install_names");
541 } else if (ctx.comp.is_static) {541 } else if (ctx.comp.is_static) {
542 try ctx.args.append(c"-lcrt0.o");542 try ctx.args.append("-lcrt0.o");
543 } else {543 } else {
544 switch (platform.kind) {544 switch (platform.kind) {
545 DarwinPlatform.Kind.MacOS => {545 DarwinPlatform.Kind.MacOS => {
546 if (platform.versionLessThan(10, 5)) {546 if (platform.versionLessThan(10, 5)) {
547 try ctx.args.append(c"-lcrt1.o");547 try ctx.args.append("-lcrt1.o");
548 } else if (platform.versionLessThan(10, 6)) {548 } 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");
550 } else if (platform.versionLessThan(10, 8)) {550 } 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");
552 }552 }
553 },553 },
554 DarwinPlatform.Kind.IPhoneOS => {554 DarwinPlatform.Kind.IPhoneOS => {
555 if (ctx.comp.target.getArch() == builtin.Arch.aarch64) {555 if (ctx.comp.target.getArch() == builtin.Arch.aarch64) {
556 // iOS does not need any crt1 files for arm64556 // iOS does not need any crt1 files for arm64
557 } else if (platform.versionLessThan(3, 1)) {557 } else if (platform.versionLessThan(3, 1)) {
558 try ctx.args.append(c"-lcrt1.o");558 try ctx.args.append("-lcrt1.o");
559 } else if (platform.versionLessThan(6, 0)) {559 } 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");
561 }561 }
562 },562 },
563 DarwinPlatform.Kind.IPhoneOSSimulator => {}, // no crt1.o needed563 DarwinPlatform.Kind.IPhoneOSSimulator => {}, // no crt1.o needed
...@@ -589,7 +589,7 @@ fn constructLinkerArgsMachO(ctx: *Context) !void {...@@ -589,7 +589,7 @@ fn constructLinkerArgsMachO(ctx: *Context) !void {
589 // to make syscalls because the syscall numbers are not documented589 // to make syscalls because the syscall numbers are not documented
590 // and change between versions.590 // and change between versions.
591 // so we always link against libSystem591 // so we always link against libSystem
592 try ctx.args.append(c"-lSystem");592 try ctx.args.append("-lSystem");
593 } else {593 } else {
594 if (mem.indexOfScalar(u8, lib.name, '/') == null) {594 if (mem.indexOfScalar(u8, lib.name, '/') == null) {
595 const arg = try std.fmt.allocPrint(&ctx.arena.allocator, "-l{}\x00", lib.name);595 const arg = try std.fmt.allocPrint(&ctx.arena.allocator, "-l{}\x00", lib.name);
...@@ -601,15 +601,15 @@ fn constructLinkerArgsMachO(ctx: *Context) !void {...@@ -601,15 +601,15 @@ fn constructLinkerArgsMachO(ctx: *Context) !void {
601 }601 }
602 }602 }
603 } else {603 } else {
604 try ctx.args.append(c"-undefined");604 try ctx.args.append("-undefined");
605 try ctx.args.append(c"dynamic_lookup");605 try ctx.args.append("dynamic_lookup");
606 }606 }
607607
608 if (platform.kind == DarwinPlatform.Kind.MacOS) {608 if (platform.kind == DarwinPlatform.Kind.MacOS) {
609 if (platform.versionLessThan(10, 5)) {609 if (platform.versionLessThan(10, 5)) {
610 try ctx.args.append(c"-lgcc_s.10.4");610 try ctx.args.append("-lgcc_s.10.4");
611 } else if (platform.versionLessThan(10, 6)) {611 } 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");
613 }613 }
614 } else {614 } else {
615 @panic("TODO");615 @panic("TODO");
src-self-hosted/stage1.zig+1-1
...@@ -28,7 +28,7 @@ comptime {...@@ -28,7 +28,7 @@ comptime {
28// ABI warning28// ABI warning
29export fn stage2_zen(ptr: *[*]const u8, len: *usize) void {29export fn stage2_zen(ptr: *[*]const u8, len: *usize) void {
30 const info_zen = @import("main.zig").info_zen;30 const info_zen = @import("main.zig").info_zen;
31 ptr.* = &info_zen;31 ptr.* = info_zen;
32 len.* = info_zen.len;32 len.* = info_zen.len;
33}33}
3434
src-self-hosted/value.zig+1-1
...@@ -474,7 +474,7 @@ pub const Value = struct {...@@ -474,7 +474,7 @@ pub const Value = struct {
474 dont_null_terminate,474 dont_null_terminate,
475 ) orelse return error.OutOfMemory;475 ) orelse return error.OutOfMemory;
476 const str_init_type = llvm.TypeOf(llvm_str_init);476 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;
478 llvm.SetInitializer(global, llvm_str_init);478 llvm.SetInitializer(global, llvm_str_init);
479 llvm.SetLinkage(global, llvm.PrivateLinkage);479 llvm.SetLinkage(global, llvm.PrivateLinkage);
480 llvm.SetGlobalConstant(global, 1);480 llvm.SetGlobalConstant(global, 1);
src/all_types.hpp+5-4
...@@ -102,6 +102,10 @@ struct IrExecutable {...@@ -102,6 +102,10 @@ struct IrExecutable {
102 bool is_inline;102 bool is_inline;
103 bool is_generic_instantiation;103 bool is_generic_instantiation;
104 bool need_err_code_spill;104 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();
105};109};
106110
107enum OutType {111enum OutType {
...@@ -237,9 +241,6 @@ struct ConstPtrValue {...@@ -237,9 +241,6 @@ struct ConstPtrValue {
237 struct {241 struct {
238 ConstExprValue *array_val;242 ConstExprValue *array_val;
239 size_t elem_index;243 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;
243 } base_array;244 } base_array;
244 struct {245 struct {
245 ConstExprValue *struct_val;246 ConstExprValue *struct_val;
...@@ -1001,7 +1002,6 @@ struct AstNodeStructField {...@@ -1001,7 +1002,6 @@ struct AstNodeStructField {
10011002
1002struct AstNodeStringLiteral {1003struct AstNodeStringLiteral {
1003 Buf *buf;1004 Buf *buf;
1004 bool c;
1005};1005};
10061006
1007struct AstNodeCharLiteral {1007struct AstNodeCharLiteral {
...@@ -1956,6 +1956,7 @@ struct CodeGen {...@@ -1956,6 +1956,7 @@ struct CodeGen {
1956 HashMap<Buf *, Tld *, buf_hash, buf_eql_buf> external_prototypes;1956 HashMap<Buf *, Tld *, buf_hash, buf_eql_buf> external_prototypes;
1957 HashMap<Buf *, ConstExprValue *, buf_hash, buf_eql_buf> string_literals_table;1957 HashMap<Buf *, ConstExprValue *, buf_hash, buf_eql_buf> string_literals_table;
1958 HashMap<const ZigType *, ConstExprValue *, type_ptr_hash, type_ptr_eql> type_info_cache;1958 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
1960 ZigList<Tld *> resolve_queue;1961 ZigList<Tld *> resolve_queue;
1961 size_t resolve_queue_index;1962 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...@@ -767,10 +767,18 @@ ZigType *get_array_type(CodeGen *g, ZigType *child_type, uint64_t array_size, bo
767767
768 ZigType *entry = new_type_table_entry(ZigTypeIdArray);768 ZigType *entry = new_type_table_entry(ZigTypeIdArray);
769769
770 const char *null_str = is_null_terminated ? "null " : "";
771
770 buf_resize(&entry->name, 0);772 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);
774 entry->size_in_bits = child_type->size_in_bits * full_array_size;782 entry->size_in_bits = child_type->size_in_bits * full_array_size;
775 entry->abi_align = child_type->abi_align;783 entry->abi_align = child_type->abi_align;
776 entry->abi_size = child_type->abi_size * full_array_size;784 entry->abi_size = child_type->abi_size * full_array_size;
...@@ -5046,7 +5054,6 @@ static uint32_t hash_const_val_ptr(ConstExprValue *const_val) {...@@ -5046,7 +5054,6 @@ static uint32_t hash_const_val_ptr(ConstExprValue *const_val) {
5046 hash_val += (uint32_t)1764906839;5054 hash_val += (uint32_t)1764906839;
5047 hash_val += hash_ptr(const_val->data.x_ptr.data.base_array.array_val);5055 hash_val += hash_ptr(const_val->data.x_ptr.data.base_array.array_val);
5048 hash_val += hash_size(const_val->data.x_ptr.data.base_array.elem_index);5056 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;
5050 return hash_val;5057 return hash_val;
5051 case ConstPtrSpecialBaseStruct:5058 case ConstPtrSpecialBaseStruct:
5052 hash_val += (uint32_t)3518317043;5059 hash_val += (uint32_t)3518317043;
...@@ -5550,6 +5557,18 @@ OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry) {...@@ -5550,6 +5557,18 @@ OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry) {
5550 zig_unreachable();5557 zig_unreachable();
5551}5558}
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
5553ReqCompTime type_requires_comptime(CodeGen *g, ZigType *ty) {5572ReqCompTime type_requires_comptime(CodeGen *g, ZigType *ty) {
5554 Error err;5573 Error err;
5555 switch (ty->id) {5574 switch (ty->id) {
...@@ -5617,52 +5636,26 @@ void init_const_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *str) {...@@ -5617,52 +5636,26 @@ void init_const_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *str) {
5617 return;5636 return;
5618 }5637 }
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) {
5635 // first we build the underlying array5639 // first we build the underlying array
5636 size_t len_with_null = buf_len(str) + 1;
5637 ConstExprValue *array_val = create_const_vals(1);5640 ConstExprValue *array_val = create_const_vals(1);
5638 array_val->special = ConstValSpecialStatic;5641 array_val->special = ConstValSpecialStatic;
5639 array_val->type = get_array_type(g, g->builtin_types.entry_u8, len_with_null, false);5642 array_val->type = get_array_type(g, g->builtin_types.entry_u8, buf_len(str), true);
5640 // TODO buf optimization5643 array_val->data.x_array.special = ConstArraySpecialBuf;
5641 array_val->data.x_array.data.s_none.elements = create_const_vals(len_with_null);5644 array_val->data.x_array.data.s_buf = str;
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);
56525645
5653 // then make the pointer point to it5646 // then make the pointer point to it
5654 const_val->special = ConstValSpecialStatic;5647 const_val->special = ConstValSpecialStatic;
5655 // TODO make this `[*]null u8` instead of `[*]u8`5648 const_val->type = get_pointer_to_type_extra2(g, array_val->type, true, false,
5656 const_val->type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,5649 PtrLenSingle, 0, 0, 0, false, VECTOR_INDEX_NONE, nullptr);
5657 PtrLenUnknown, 0, 0, 0, false);5650 const_val->data.x_ptr.special = ConstPtrSpecialRef;
5658 const_val->data.x_ptr.special = ConstPtrSpecialBaseArray;5651 const_val->data.x_ptr.data.ref.pointee = array_val;
5659 const_val->data.x_ptr.data.base_array.array_val = array_val;5652
5660 const_val->data.x_ptr.data.base_array.elem_index = 0;5653 g->string_literals_table.put(str, const_val);
5661 const_val->data.x_ptr.data.base_array.is_cstr = true;
5662}5654}
5663ConstExprValue *create_const_c_str_lit(CodeGen *g, Buf *str) {5655
5656ConstExprValue *create_const_str_lit(CodeGen *g, Buf *str) {
5664 ConstExprValue *const_val = create_const_vals(1);5657 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);
5666 return const_val;5659 return const_val;
5667}5660}
56685661
...@@ -5712,6 +5705,18 @@ ConstExprValue *create_const_signed(ZigType *type, int64_t x) {...@@ -5712,6 +5705,18 @@ ConstExprValue *create_const_signed(ZigType *type, int64_t x) {
5712 return const_val;5705 return const_val;
5713}5706}
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
5715void init_const_float(ConstExprValue *const_val, ZigType *type, double value) {5720void init_const_float(ConstExprValue *const_val, ZigType *type, double value) {
5716 const_val->special = ConstValSpecialStatic;5721 const_val->special = ConstValSpecialStatic;
5717 const_val->type = type;5722 const_val->type = type;
...@@ -6446,8 +6451,6 @@ bool ir_get_var_is_comptime(ZigVar *var) {...@@ -6446,8 +6451,6 @@ bool ir_get_var_is_comptime(ZigVar *var) {
6446bool const_values_equal_ptr(ConstExprValue *a, ConstExprValue *b) {6451bool const_values_equal_ptr(ConstExprValue *a, ConstExprValue *b) {
6447 if (a->data.x_ptr.special != b->data.x_ptr.special)6452 if (a->data.x_ptr.special != b->data.x_ptr.special)
6448 return false;6453 return false;
6449 if (a->data.x_ptr.mut != b->data.x_ptr.mut)
6450 return false;
6451 switch (a->data.x_ptr.special) {6454 switch (a->data.x_ptr.special) {
6452 case ConstPtrSpecialInvalid:6455 case ConstPtrSpecialInvalid:
6453 zig_unreachable();6456 zig_unreachable();
...@@ -6464,8 +6467,6 @@ bool const_values_equal_ptr(ConstExprValue *a, ConstExprValue *b) {...@@ -6464,8 +6467,6 @@ bool const_values_equal_ptr(ConstExprValue *a, ConstExprValue *b) {
6464 }6467 }
6465 if (a->data.x_ptr.data.base_array.elem_index != b->data.x_ptr.data.base_array.elem_index)6468 if (a->data.x_ptr.data.base_array.elem_index != b->data.x_ptr.data.base_array.elem_index)
6466 return false;6469 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;
6469 return true;6470 return true;
6470 case ConstPtrSpecialBaseStruct:6471 case ConstPtrSpecialBaseStruct:
6471 if (a->data.x_ptr.data.base_struct.struct_val != b->data.x_ptr.data.base_struct.struct_val &&6472 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) {...@@ -6544,6 +6545,16 @@ bool const_values_equal(CodeGen *g, ConstExprValue *a, ConstExprValue *b) {
6544 assert(a->type->id == b->type->id);6545 assert(a->type->id == b->type->id);
6545 assert(a->special == ConstValSpecialStatic);6546 assert(a->special == ConstValSpecialStatic);
6546 assert(b->special == ConstValSpecialStatic);6547 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 }
6547 switch (a->type->id) {6558 switch (a->type->id) {
6548 case ZigTypeIdOpaque:6559 case ZigTypeIdOpaque:
6549 zig_unreachable();6560 zig_unreachable();
...@@ -6709,15 +6720,10 @@ static void render_const_val_ptr(CodeGen *g, Buf *buf, ConstExprValue *const_val...@@ -6709,15 +6720,10 @@ static void render_const_val_ptr(CodeGen *g, Buf *buf, ConstExprValue *const_val
6709 render_const_value(g, buf, const_ptr_pointee(nullptr, g, const_val, nullptr));6720 render_const_value(g, buf, const_ptr_pointee(nullptr, g, const_val, nullptr));
6710 return;6721 return;
6711 case ConstPtrSpecialBaseArray:6722 case ConstPtrSpecialBaseArray:
6712 if (const_val->data.x_ptr.data.base_array.is_cstr) {6723 buf_appendf(buf, "*");
6713 buf_appendf(buf, "*(c str lit)");6724 // TODO we need a source node for const_ptr_pointee because it can generate compile errors
6714 return;6725 render_const_value(g, buf, const_ptr_pointee(nullptr, g, const_val, nullptr));
6715 } else {6726 return;
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 }
6721 case ConstPtrSpecialHardCodedAddr:6727 case ConstPtrSpecialHardCodedAddr:
6722 buf_appendf(buf, "(%s)(%" ZIG_PRI_x64 ")", buf_ptr(&type_entry->name),6728 buf_appendf(buf, "(%s)(%" ZIG_PRI_x64 ")", buf_ptr(&type_entry->name),
6723 const_val->data.x_ptr.data.hard_coded_addr.addr);6729 const_val->data.x_ptr.data.hard_coded_addr.addr);
...@@ -8653,14 +8659,16 @@ static void resolve_llvm_types_array(CodeGen *g, ZigType *type) {...@@ -8653,14 +8659,16 @@ static void resolve_llvm_types_array(CodeGen *g, ZigType *type) {
86538659
8654 ZigType *elem_type = type->data.array.child_type;8660 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;
8656 // TODO https://github.com/ziglang/zig/issues/14248664 // 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
8659 uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, type->llvm_type);8667 uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, type->llvm_type);
8660 uint64_t debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, type->llvm_type);8668 uint64_t debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, type->llvm_type);
86618669
8662 type->llvm_di_type = ZigLLVMCreateDebugArrayType(g->dbuilder, debug_size_in_bits,8670 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);
8664}8672}
86658673
8666static void resolve_llvm_types_fn_type(CodeGen *g, ZigType *fn_type) {8674static 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,...@@ -9150,3 +9158,24 @@ Error analyze_import(CodeGen *g, ZigType *source_import, Buf *import_target_str,
9150 *out_import = add_source_file(g, target_package, resolved_path, import_code, source_kind);9158 *out_import = add_source_file(g, target_package, resolved_path, import_code, source_kind);
9151 return ErrorNone;9159 return ErrorNone;
9152}9160}
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);...@@ -126,9 +126,6 @@ ScopeExpr *create_expr_scope(CodeGen *g, AstNode *node, Scope *parent);
126void init_const_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *str);126void init_const_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *str);
127ConstExprValue *create_const_str_lit(CodeGen *g, Buf *str);127ConstExprValue *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
132void init_const_bigint(ConstExprValue *const_val, ZigType *type, const BigInt *bigint);129void init_const_bigint(ConstExprValue *const_val, ZigType *type, const BigInt *bigint);
133ConstExprValue *create_const_bigint(ZigType *type, const BigInt *bigint);130ConstExprValue *create_const_bigint(ZigType *type, const BigInt *bigint);
134131
...@@ -176,6 +173,9 @@ ConstExprValue *create_const_slice(CodeGen *g, ConstExprValue *array_val, size_t...@@ -176,6 +173,9 @@ ConstExprValue *create_const_slice(CodeGen *g, ConstExprValue *array_val, size_t
176void init_const_arg_tuple(CodeGen *g, ConstExprValue *const_val, size_t arg_index_start, size_t arg_index_end);173void init_const_arg_tuple(CodeGen *g, ConstExprValue *const_val, size_t arg_index_start, size_t arg_index_end);
177ConstExprValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_t arg_index_end);174ConstExprValue *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
179ConstExprValue *create_const_vals(size_t count);179ConstExprValue *create_const_vals(size_t count);
180ConstExprValue **alloc_const_vals_ptrs(size_t count);180ConstExprValue **alloc_const_vals_ptrs(size_t count);
181ConstExprValue **realloc_const_vals_ptrs(ConstExprValue **ptr, size_t old_count, size_t new_count);181ConstExprValue **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,...@@ -275,5 +275,6 @@ IrInstruction *ir_create_alloca(CodeGen *g, Scope *scope, AstNode *source_node,
275 ZigType *var_type, const char *name_hint);275 ZigType *var_type, const char *name_hint);
276Error analyze_import(CodeGen *codegen, ZigType *source_import, Buf *import_target_str,276Error analyze_import(CodeGen *codegen, ZigType *source_import, Buf *import_target_str,
277 ZigType **out_import, Buf **out_import_target_path, Buf *out_full_path);277 ZigType **out_import, Buf **out_import_target_path, Buf *out_full_path);
278278ConstExprValue *get_the_one_possible_value(CodeGen *g, ZigType *type_entry);
279ConstExprValue *get_null_value(ZigType *ty);
279#endif280#endif
src/ast_render.cpp-3
...@@ -619,9 +619,6 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {...@@ -619,9 +619,6 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {
619 break;619 break;
620 case NodeTypeStringLiteral:620 case NodeTypeStringLiteral:
621 {621 {
622 if (node->data.string_literal.c) {
623 fprintf(ar->f, "c");
624 }
625 Buf tmp_buf = BUF_INIT;622 Buf tmp_buf = BUF_INIT;
626 string_literal_escape(node->data.string_literal.buf, &tmp_buf);623 string_literal_escape(node->data.string_literal.buf, &tmp_buf);
627 fprintf(ar->f, "\"%s\"", buf_ptr(&tmp_buf));624 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) {...@@ -949,7 +949,7 @@ static LLVMValueRef get_panic_msg_ptr_val(CodeGen *g, PanicMsgId msg_id) {
949 if (!val->global_refs->llvm_global) {949 if (!val->global_refs->llvm_global) {
950950
951 Buf *buf_msg = panic_msg_buf(msg_id);951 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;
953 init_const_slice(g, val, array_val, 0, buf_len(buf_msg), true);953 init_const_slice(g, val, array_val, 0, buf_len(buf_msg), true);
954954
955 render_const_val(g, val, "");955 render_const_val(g, val, "");
...@@ -2784,14 +2784,6 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,...@@ -2784,14 +2784,6 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
2784 IrInstruction *op1 = bin_op_instruction->op1;2784 IrInstruction *op1 = bin_op_instruction->op1;
2785 IrInstruction *op2 = bin_op_instruction->op2;2785 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 );
2795 ZigType *operand_type = op1->value.type;2787 ZigType *operand_type = op1->value.type;
2796 ZigType *scalar_type = (operand_type->id == ZigTypeIdVector) ? operand_type->data.vector.elem_type : operand_type;2788 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,...@@ -2848,7 +2840,6 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
2848 AddSubMulMul;2840 AddSubMulMul;
28492841
2850 if (scalar_type->id == ZigTypeIdPointer) {2842 if (scalar_type->id == ZigTypeIdPointer) {
2851 assert(scalar_type->data.pointer.ptr_len != PtrLenSingle);
2852 LLVMValueRef subscript_value;2843 LLVMValueRef subscript_value;
2853 if (operand_type->id == ZigTypeIdVector)2844 if (operand_type->id == ZigTypeIdVector)
2854 zig_panic("TODO: Implement vector operations on pointers.");2845 zig_panic("TODO: Implement vector operations on pointers.");
...@@ -3077,7 +3068,14 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,...@@ -3077,7 +3068,14 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
3077 case CastOpNumLitToConcrete:3068 case CastOpNumLitToConcrete:
3078 zig_unreachable();3069 zig_unreachable();
3079 case CastOpNoop:3070 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 }
3081 case CastOpIntToFloat:3079 case CastOpIntToFloat:
3082 assert(actual_type->id == ZigTypeIdInt);3080 assert(actual_type->id == ZigTypeIdInt);
3083 if (actual_type->data.integral.is_signed) {3081 if (actual_type->data.integral.is_signed) {
...@@ -3709,8 +3707,9 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI...@@ -3709,8 +3707,9 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI
3709 array_type = array_type->data.pointer.child_type;3707 array_type = array_type->data.pointer.child_type;
3710 }3708 }
3711 if (safety_check_on) {3709 if (safety_check_on) {
3712 LLVMValueRef end = LLVMConstInt(g->builtin_types.entry_usize->llvm_type,3710 uint64_t extra_len_from_null = array_type->data.array.is_null_terminated ? 1 : 0;
3713 array_type->data.array.len, false);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);
3714 add_bounds_check(g, subscript_value, LLVMIntEQ, nullptr, LLVMIntULT, end);3713 add_bounds_check(g, subscript_value, LLVMIntEQ, nullptr, LLVMIntULT, end);
3715 }3714 }
3716 if (array_ptr_type->data.pointer.host_int_bytes != 0) {3715 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...@@ -6637,11 +6636,20 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con
6637 ConstExprValue *array_const_val = const_val->data.x_ptr.data.base_array.array_val;6636 ConstExprValue *array_const_val = const_val->data.x_ptr.data.base_array.array_val;
6638 assert(array_const_val->type->id == ZigTypeIdArray);6637 assert(array_const_val->type->id == ZigTypeIdArray);
6639 if (!type_has_bits(array_const_val->type)) {6638 if (!type_has_bits(array_const_val->type)) {
6640 // make this a null pointer6639 if (array_const_val->type->data.array.is_null_terminated) {
6641 ZigType *usize = g->builtin_types.entry_usize;6640 ConstExprValue *pointee = get_null_value(array_const_val->type->data.array.child_type);
6642 const_val->global_refs->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->llvm_type),6641 render_const_val(g, pointee, "");
6643 get_llvm_type(g, const_val->type));6642 render_const_val_global(g, pointee, "");
6644 return const_val->global_refs->llvm_value;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 }
6645 }6653 }
6646 size_t elem_index = const_val->data.x_ptr.data.base_array.elem_index;6654 size_t elem_index = const_val->data.x_ptr.data.base_array.elem_index;
6647 LLVMValueRef uncasted_ptr_val = gen_const_ptr_array_recursive(g, array_const_val, elem_index);6655 LLVMValueRef uncasted_ptr_val = gen_const_ptr_array_recursive(g, array_const_val, elem_index);
...@@ -6955,7 +6963,9 @@ check: switch (const_val->special) {...@@ -6955,7 +6963,9 @@ check: switch (const_val->special) {
6955 case ConstArraySpecialUndef:6963 case ConstArraySpecialUndef:
6956 return LLVMGetUndef(get_llvm_type(g, type_entry));6964 return LLVMGetUndef(get_llvm_type(g, type_entry));
6957 case ConstArraySpecialNone: {6965 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);
6959 LLVMTypeRef element_type_ref = get_llvm_type(g, type_entry->data.array.child_type);6969 LLVMTypeRef element_type_ref = get_llvm_type(g, type_entry->data.array.child_type);
6960 bool make_unnamed_struct = false;6970 bool make_unnamed_struct = false;
6961 for (uint64_t i = 0; i < len; i += 1) {6971 for (uint64_t i = 0; i < len; i += 1) {
...@@ -6964,15 +6974,19 @@ check: switch (const_val->special) {...@@ -6964,15 +6974,19 @@ check: switch (const_val->special) {
6964 values[i] = val;6974 values[i] = val;
6965 make_unnamed_struct = make_unnamed_struct || is_llvm_value_unnamed_type(g, elem_value->type, val);6975 make_unnamed_struct = make_unnamed_struct || is_llvm_value_unnamed_type(g, elem_value->type, val);
6966 }6976 }
6977 if (type_entry->data.array.is_null_terminated) {
6978 values[len] = LLVMConstNull(element_type_ref);
6979 }
6967 if (make_unnamed_struct) {6980 if (make_unnamed_struct) {
6968 return LLVMConstStruct(values, len, true);6981 return LLVMConstStruct(values, full_len, true);
6969 } else {6982 } else {
6970 return LLVMConstArray(element_type_ref, values, (unsigned)len);6983 return LLVMConstArray(element_type_ref, values, (unsigned)full_len);
6971 }6984 }
6972 }6985 }
6973 case ConstArraySpecialBuf: {6986 case ConstArraySpecialBuf: {
6974 Buf *buf = const_val->data.x_array.data.s_buf;6987 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);
6976 }6990 }
6977 }6991 }
6978 zig_unreachable();6992 zig_unreachable();
...@@ -9092,7 +9106,7 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) {...@@ -9092,7 +9106,7 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) {
9092 this_val->data.x_struct.fields = alloc_const_vals_ptrs(2);9106 this_val->data.x_struct.fields = alloc_const_vals_ptrs(2);
90939107
9094 ConstExprValue *name_field = this_val->data.x_struct.fields[0];9108 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;
9096 init_const_slice(g, name_field, name_array_val, 0, buf_len(&test_fn_entry->symbol_name), true);9110 init_const_slice(g, name_field, name_array_val, 0, buf_len(&test_fn_entry->symbol_name), true);
90979111
9098 ConstExprValue *fn_field = this_val->data.x_struct.fields[1];9112 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...@@ -10415,6 +10429,7 @@ CodeGen *codegen_create(Buf *main_pkg_path, Buf *root_src_path, const ZigTarget
10415 g->external_prototypes.init(8);10429 g->external_prototypes.init(8);
10416 g->string_literals_table.init(16);10430 g->string_literals_table.init(16);
10417 g->type_info_cache.init(32);10431 g->type_info_cache.init(32);
10432 g->one_possible_values.init(32);
10418 g->is_test_build = is_test_build;10433 g->is_test_build = is_test_build;
10419 g->is_single_threaded = false;10434 g->is_single_threaded = false;
10420 buf_resize(&g->global_asm, 0);10435 buf_resize(&g->global_asm, 0);
src/ir.cpp+321-127
...@@ -66,6 +66,8 @@ enum ConstCastResultId {...@@ -66,6 +66,8 @@ enum ConstCastResultId {
66 ConstCastResultIdUnresolvedInferredErrSet,66 ConstCastResultIdUnresolvedInferredErrSet,
67 ConstCastResultIdAsyncAllocatorType,67 ConstCastResultIdAsyncAllocatorType,
68 ConstCastResultIdBadAllowsZero,68 ConstCastResultIdBadAllowsZero,
69 ConstCastResultIdArrayChild,
70 ConstCastResultIdBadNullTermArrays,
69};71};
7072
71struct ConstCastOnly;73struct ConstCastOnly;
...@@ -87,7 +89,9 @@ struct ConstCastErrUnionErrSetMismatch;...@@ -87,7 +89,9 @@ struct ConstCastErrUnionErrSetMismatch;
87struct ConstCastErrUnionPayloadMismatch;89struct ConstCastErrUnionPayloadMismatch;
88struct ConstCastErrSetMismatch;90struct ConstCastErrSetMismatch;
89struct ConstCastTypeMismatch;91struct ConstCastTypeMismatch;
92struct ConstCastArrayMismatch;
90struct ConstCastBadAllowsZero;93struct ConstCastBadAllowsZero;
94struct ConstCastBadNullTermArrays;
9195
92struct ConstCastOnly {96struct ConstCastOnly {
93 ConstCastResultId id;97 ConstCastResultId id;
...@@ -99,11 +103,13 @@ struct ConstCastOnly {...@@ -99,11 +103,13 @@ struct ConstCastOnly {
99 ConstCastErrUnionPayloadMismatch *error_union_payload;103 ConstCastErrUnionPayloadMismatch *error_union_payload;
100 ConstCastErrUnionErrSetMismatch *error_union_error_set;104 ConstCastErrUnionErrSetMismatch *error_union_error_set;
101 ConstCastTypeMismatch *type_mismatch;105 ConstCastTypeMismatch *type_mismatch;
106 ConstCastArrayMismatch *array_mismatch;
102 ConstCastOnly *return_type;107 ConstCastOnly *return_type;
103 ConstCastOnly *null_wrap_ptr_child;108 ConstCastOnly *null_wrap_ptr_child;
104 ConstCastArg fn_arg;109 ConstCastArg fn_arg;
105 ConstCastArgNoAlias arg_no_alias;110 ConstCastArgNoAlias arg_no_alias;
106 ConstCastBadAllowsZero *bad_allows_zero;111 ConstCastBadAllowsZero *bad_allows_zero;
112 ConstCastBadNullTermArrays *bad_null_term_arrays;
107 } data;113 } data;
108};114};
109115
...@@ -130,6 +136,12 @@ struct ConstCastSliceMismatch {...@@ -130,6 +136,12 @@ struct ConstCastSliceMismatch {
130 ZigType *actual_child;136 ZigType *actual_child;
131};137};
132138
139struct ConstCastArrayMismatch {
140 ConstCastOnly child;
141 ZigType *wanted_child;
142 ZigType *actual_child;
143};
144
133struct ConstCastErrUnionErrSetMismatch {145struct ConstCastErrUnionErrSetMismatch {
134 ConstCastOnly child;146 ConstCastOnly child;
135 ZigType *wanted_err_set;147 ZigType *wanted_err_set;
...@@ -151,6 +163,12 @@ struct ConstCastBadAllowsZero {...@@ -151,6 +163,12 @@ struct ConstCastBadAllowsZero {
151 ZigType *actual_type;163 ZigType *actual_type;
152};164};
153165
166struct ConstCastBadNullTermArrays {
167 ConstCastOnly child;
168 ZigType *wanted_type;
169 ZigType *actual_type;
170};
171
154172
155static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope);173static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope);
156static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *scope, LVal lval,174static 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...@@ -217,10 +235,7 @@ static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *c
217 case OnePossibleValueInvalid:235 case OnePossibleValueInvalid:
218 zig_unreachable();236 zig_unreachable();
219 case OnePossibleValueYes:237 case OnePossibleValueYes:
220 result = create_const_vals(1);238 return get_the_one_possible_value(g, const_val->type->data.pointer.child_type);
221 result->type = const_val->type->data.pointer.child_type;
222 result->special = ConstValSpecialStatic;
223 return result;
224 case OnePossibleValueNo:239 case OnePossibleValueNo:
225 break;240 break;
226 }241 }
...@@ -233,8 +248,13 @@ static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *c...@@ -233,8 +248,13 @@ static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *c
233 break;248 break;
234 case ConstPtrSpecialBaseArray: {249 case ConstPtrSpecialBaseArray: {
235 ConstExprValue *array_val = const_val->data.x_ptr.data.base_array.array_val;250 ConstExprValue *array_val = const_val->data.x_ptr.data.base_array.array_val;
236 expand_undef_array(g, array_val);251 if (const_val->data.x_ptr.data.base_array.elem_index == array_val->type->data.array.len) {
237 result = &array_val->data.x_array.data.s_none.elements[const_val->data.x_ptr.data.base_array.elem_index];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 }
238 break;258 break;
239 }259 }
240 case ConstPtrSpecialBaseStruct: {260 case ConstPtrSpecialBaseStruct: {
...@@ -282,20 +302,20 @@ static bool slice_is_const(ZigType *type) {...@@ -282,20 +302,20 @@ static bool slice_is_const(ZigType *type) {
282302
283// This function returns true when you can change the type of a ConstExprValue and the303// This function returns true when you can change the type of a ConstExprValue and the
284// value remains meaningful.304// value remains meaningful.
285static bool types_have_same_zig_comptime_repr(ZigType *a, ZigType *b) {305static bool types_have_same_zig_comptime_repr(ZigType *expected, ZigType *actual) {
286 if (a == b)306 if (expected == actual)
287 return true;307 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)
290 return true;310 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))
293 return true;313 return true;
294314
295 if (a->id != b->id)315 if (expected->id != actual->id)
296 return false;316 return false;
297317
298 switch (a->id) {318 switch (expected->id) {
299 case ZigTypeIdInvalid:319 case ZigTypeIdInvalid:
300 case ZigTypeIdUnreachable:320 case ZigTypeIdUnreachable:
301 zig_unreachable();321 zig_unreachable();
...@@ -314,12 +334,11 @@ static bool types_have_same_zig_comptime_repr(ZigType *a, ZigType *b) {...@@ -314,12 +334,11 @@ static bool types_have_same_zig_comptime_repr(ZigType *a, ZigType *b) {
314 case ZigTypeIdAnyFrame:334 case ZigTypeIdAnyFrame:
315 return true;335 return true;
316 case ZigTypeIdFloat:336 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;
318 case ZigTypeIdInt:338 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;
320 case ZigTypeIdStruct:340 case ZigTypeIdStruct:
321 return is_slice(a) && is_slice(b);341 return is_slice(expected) && is_slice(actual);
322 case ZigTypeIdArray:
323 case ZigTypeIdOptional:342 case ZigTypeIdOptional:
324 case ZigTypeIdErrorUnion:343 case ZigTypeIdErrorUnion:
325 case ZigTypeIdEnum:344 case ZigTypeIdEnum:
...@@ -329,6 +348,10 @@ static bool types_have_same_zig_comptime_repr(ZigType *a, ZigType *b) {...@@ -329,6 +348,10 @@ static bool types_have_same_zig_comptime_repr(ZigType *a, ZigType *b) {
329 case ZigTypeIdVector:348 case ZigTypeIdVector:
330 case ZigTypeIdFnFrame:349 case ZigTypeIdFnFrame:
331 return false;350 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);
332 }355 }
333 zig_unreachable();356 zig_unreachable();
334}357}
...@@ -1299,12 +1322,6 @@ static IrInstruction *ir_build_const_str_lit(IrBuilder *irb, Scope *scope, AstNo...@@ -1299,12 +1322,6 @@ static IrInstruction *ir_build_const_str_lit(IrBuilder *irb, Scope *scope, AstNo
1299 return instruction;1322 return instruction;
1300}1323}
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
1308static IrInstruction *ir_build_bin_op(IrBuilder *irb, Scope *scope, AstNode *source_node, IrBinOp op_id,1325static IrInstruction *ir_build_bin_op(IrBuilder *irb, Scope *scope, AstNode *source_node, IrBinOp op_id,
1309 IrInstruction *op1, IrInstruction *op2, bool safety_check_on)1326 IrInstruction *op1, IrInstruction *op2, bool safety_check_on)
1310{1327{
...@@ -6932,11 +6949,7 @@ static IrInstruction *ir_gen_enum_literal(IrBuilder *irb, Scope *scope, AstNode...@@ -6932,11 +6949,7 @@ static IrInstruction *ir_gen_enum_literal(IrBuilder *irb, Scope *scope, AstNode
6932static IrInstruction *ir_gen_string_literal(IrBuilder *irb, Scope *scope, AstNode *node) {6949static IrInstruction *ir_gen_string_literal(IrBuilder *irb, Scope *scope, AstNode *node) {
6933 assert(node->type == NodeTypeStringLiteral);6950 assert(node->type == NodeTypeStringLiteral);
69346951
6935 if (node->data.string_literal.c) {6952 return ir_build_const_str_lit(irb, scope, node, node->data.string_literal.buf);
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 }
6940}6953}
69416954
6942static IrInstruction *ir_gen_array_type(IrBuilder *irb, Scope *scope, AstNode *node) {6955static IrInstruction *ir_gen_array_type(IrBuilder *irb, Scope *scope, AstNode *node) {
...@@ -8662,7 +8675,15 @@ ConstExprValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ConstExprVal...@@ -8662,7 +8675,15 @@ ConstExprValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ConstExprVal
8662 assert(val != nullptr);8675 assert(val != nullptr);
8663 assert(const_val->type->id == ZigTypeIdPointer);8676 assert(const_val->type->id == ZigTypeIdPointer);
8664 ZigType *expected_type = const_val->type->data.pointer.child_type;8677 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)) {
8666 if ((err = eval_comptime_ptr_reinterpret(ira, codegen, source_node, const_val)))8687 if ((err = eval_comptime_ptr_reinterpret(ira, codegen, source_node, const_val)))
8667 return nullptr;8688 return nullptr;
8668 return const_ptr_pointee_unchecked(codegen, const_val);8689 return const_ptr_pointee_unchecked(codegen, const_val);
...@@ -9876,6 +9897,35 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted...@@ -9876,6 +9897,35 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
9876 }9897 }
9877 }9898 }
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
9879 // slice const9929 // slice const
9880 if (is_slice(wanted_type) && is_slice(actual_type)) {9930 if (is_slice(wanted_type) && is_slice(actual_type)) {
9881 ZigType *actual_ptr_type = actual_type->data.structure.fields[slice_ptr_index]->type_entry;9931 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...@@ -10692,6 +10742,42 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
10692 continue;10742 continue;
10693 }10743 }
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
10695 // [N]T to []T10781 // [N]T to []T
10696 if (prev_type->id == ZigTypeIdArray && is_slice(cur_type) &&10782 if (prev_type->id == ZigTypeIdArray && is_slice(cur_type) &&
10697 (cur_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const ||10783 (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...@@ -10740,16 +10826,33 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
10740 free(errors);10826 free(errors);
1074110827
10742 if (convert_to_const_slice) {10828 if (convert_to_const_slice) {
10743 assert(prev_inst->value.type->id == ZigTypeIdArray);10829 if (prev_inst->value.type->id == ZigTypeIdArray) {
10744 ZigType *ptr_type = get_pointer_to_type_extra(10830 ZigType *ptr_type = get_pointer_to_type_extra(
10745 ira->codegen, prev_inst->value.type->data.array.child_type,10831 ira->codegen, prev_inst->value.type->data.array.child_type,
10746 true, false, PtrLenUnknown,10832 true, false, PtrLenUnknown,
10747 0, 0, 0, false);10833 0, 0, 0, false);
10748 ZigType *slice_type = get_slice_type(ira->codegen, ptr_type);10834 ZigType *slice_type = get_slice_type(ira->codegen, ptr_type);
10749 if (err_set_type != nullptr) {10835 if (err_set_type != nullptr) {
10750 return get_error_union_type(ira->codegen, err_set_type, slice_type);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 }
10751 } else {10854 } else {
10752 return slice_type;10855 zig_unreachable();
10753 }10856 }
10754 } else if (err_set_type != nullptr) {10857 } else if (err_set_type != nullptr) {
10755 if (prev_inst->value.type->id == ZigTypeIdErrorSet) {10858 if (prev_inst->value.type->id == ZigTypeIdErrorSet) {
...@@ -10970,7 +11073,6 @@ static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira,...@@ -10970,7 +11073,6 @@ static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira,
10970 result->value.data.x_ptr.mut = value->value.data.x_ptr.mut;11073 result->value.data.x_ptr.mut = value->value.data.x_ptr.mut;
10971 result->value.data.x_ptr.data.base_array.array_val = pointee;11074 result->value.data.x_ptr.data.base_array.array_val = pointee;
10972 result->value.data.x_ptr.data.base_array.elem_index = 0;11075 result->value.data.x_ptr.data.base_array.elem_index = 0;
10973 result->value.data.x_ptr.data.base_array.is_cstr = false;
10974 return result;11076 return result;
10975 }11077 }
10976 }11078 }
...@@ -10982,31 +11084,31 @@ static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira,...@@ -10982,31 +11084,31 @@ static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira,
10982}11084}
1098311085
10984static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruction *source_instr,11086static 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)
10986{11088{
10987 Error err;11089 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,
10990 ResolveStatusAlignmentKnown)))11092 ResolveStatusAlignmentKnown)))
10991 {11093 {
10992 return ira->codegen->invalid_instruction;11094 return ira->codegen->invalid_instruction;
10993 }11095 }
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)) {11099 if (instr_is_comptime(array_ptr)) {
10998 ConstExprValue *pointee = const_ptr_pointee(ira, ira->codegen, &value->value, source_instr->source_node);11100 ConstExprValue *pointee = const_ptr_pointee(ira, ira->codegen, &array_ptr->value, source_instr->source_node);
10999 if (pointee == nullptr)11101 if (pointee == nullptr)
11000 return ira->codegen->invalid_instruction;11102 return ira->codegen->invalid_instruction;
11001 if (pointee->special != ConstValSpecialRuntime) {11103 if (pointee->special != ConstValSpecialRuntime) {
11002 assert(value->value.type->id == ZigTypeIdPointer);11104 assert(array_ptr->value.type->id == ZigTypeIdPointer);
11003 ZigType *array_type = value->value.type->data.pointer.child_type;11105 ZigType *array_type = array_ptr->value.type->data.pointer.child_type;
11004 assert(is_slice(wanted_type));11106 assert(is_slice(wanted_type));
11005 bool is_const = wanted_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const;11107 bool is_const = wanted_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const;
1100611108
11007 IrInstruction *result = ir_const(ira, source_instr, wanted_type);11109 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
11008 init_const_slice(ira->codegen, &result->value, pointee, 0, array_type->data.array.len, is_const);11110 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;
11010 result->value.type = wanted_type;11112 result->value.type = wanted_type;
11011 return result;11113 return result;
11012 }11114 }
...@@ -11018,7 +11120,7 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc...@@ -11018,7 +11120,7 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc
11018 if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) {11120 if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) {
11019 return result_loc_inst;11121 return result_loc_inst;
11020 }11122 }
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);
11022}11124}
1102311125
11024static IrBasicBlock *ir_get_new_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrInstruction *ref_old_instruction) {11126static 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...@@ -12483,6 +12585,8 @@ static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCa
12483 case ConstCastResultIdFnArgNoAlias: // TODO12585 case ConstCastResultIdFnArgNoAlias: // TODO
12484 case ConstCastResultIdUnresolvedInferredErrSet: // TODO12586 case ConstCastResultIdUnresolvedInferredErrSet: // TODO
12485 case ConstCastResultIdAsyncAllocatorType: // TODO12587 case ConstCastResultIdAsyncAllocatorType: // TODO
12588 case ConstCastResultIdArrayChild: // TODO
12589 case ConstCastResultIdBadNullTermArrays: // TODO
12486 break;12590 break;
12487 }12591 }
12488}12592}
...@@ -12795,7 +12899,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -12795,7 +12899,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
12795 return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type);12899 return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type);
12796 }12900 }
1279712901
12798
12799 // cast from [N]T to []const T12902 // cast from [N]T to []const T
12800 // TODO: once https://github.com/ziglang/zig/issues/265 lands, remove this12903 // TODO: once https://github.com/ziglang/zig/issues/265 lands, remove this
12801 if (is_slice(wanted_type) && actual_type->id == ZigTypeIdArray) {12904 if (is_slice(wanted_type) && actual_type->id == ZigTypeIdArray) {
...@@ -12834,23 +12937,46 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -12834,23 +12937,46 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
12834 }12937 }
12835 }12938 }
1283612939
12837 // *[N]T to [*]T and [*c]T12940 // *[N]T to ?[]const T
12838 if (wanted_type->id == ZigTypeIdPointer &&12941 if (wanted_type->id == ZigTypeIdOptional &&
12839 (wanted_type->data.pointer.ptr_len == PtrLenUnknown || wanted_type->data.pointer.ptr_len == PtrLenC) &&12942 is_slice(wanted_type->data.maybe.child_type) &&
12840 actual_type->id == ZigTypeIdPointer &&12943 actual_type->id == ZigTypeIdPointer &&
12841 actual_type->data.pointer.ptr_len == PtrLenSingle &&12944 actual_type->data.pointer.ptr_len == PtrLenSingle &&
12842 actual_type->data.pointer.child_type->id == ZigTypeIdArray)12945 actual_type->data.pointer.child_type->id == ZigTypeIdArray)
12843 {12946 {
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))
12845 return ira->codegen->invalid_instruction;12949 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))
12847 return ira->codegen->invalid_instruction;12953 return ira->codegen->invalid_instruction;
12848 if (get_ptr_align(ira->codegen, actual_type) >= get_ptr_align(ira->codegen, wanted_type) &&12954
12849 types_match_const_cast_only(ira, wanted_type->data.pointer.child_type,12955 return cast2;
12850 actual_type->data.pointer.child_type->data.array.child_type, source_node,12956 }
12851 !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk)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)
12852 {12968 {
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 }
12854 }12980 }
12855 }12981 }
1285612982
...@@ -14544,8 +14670,6 @@ static bool ok_float_op(IrBinOp op) {...@@ -14544,8 +14670,6 @@ static bool ok_float_op(IrBinOp op) {
14544}14670}
1454514671
14546static bool is_pointer_arithmetic_allowed(ZigType *lhs_type, IrBinOp op) {14672static bool is_pointer_arithmetic_allowed(ZigType *lhs_type, IrBinOp op) {
14547 if (lhs_type->id != ZigTypeIdPointer)
14548 return false;
14549 switch (op) {14673 switch (op) {
14550 case IrBinOpAdd:14674 case IrBinOpAdd:
14551 case IrBinOpSub:14675 case IrBinOpSub:
...@@ -14553,15 +14677,17 @@ static bool is_pointer_arithmetic_allowed(ZigType *lhs_type, IrBinOp op) {...@@ -14553,15 +14677,17 @@ static bool is_pointer_arithmetic_allowed(ZigType *lhs_type, IrBinOp op) {
14553 default:14677 default:
14554 return false;14678 return false;
14555 }14679 }
14680 if (lhs_type->id != ZigTypeIdPointer)
14681 return false;
14556 switch (lhs_type->data.pointer.ptr_len) {14682 switch (lhs_type->data.pointer.ptr_len) {
14557 case PtrLenSingle:14683 case PtrLenSingle:
14558 return false;14684 return lhs_type->data.pointer.child_type->id == ZigTypeIdArray;
14559 case PtrLenUnknown:14685 case PtrLenUnknown:
14560 case PtrLenNull:14686 case PtrLenNull:
14561 case PtrLenC:14687 case PtrLenC:
14562 break;14688 return true;
14563 }14689 }
14564 return true;14690 zig_unreachable();
14565}14691}
1456614692
14567static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp *instruction) {14693static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp *instruction) {
...@@ -14823,6 +14949,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i...@@ -14823,6 +14949,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
14823 if (!op2_val)14949 if (!op2_val)
14824 return ira->codegen->invalid_instruction;14950 return ira->codegen->invalid_instruction;
1482514951
14952 bool is_null_terminated = false;
14826 ConstExprValue *op1_array_val;14953 ConstExprValue *op1_array_val;
14827 size_t op1_array_index;14954 size_t op1_array_index;
14828 size_t op1_array_end;14955 size_t op1_array_end;
...@@ -14834,13 +14961,14 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i...@@ -14834,13 +14961,14 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
14834 op1_array_end = op1_type->data.array.len;14961 op1_array_end = op1_type->data.array.len;
14835 } else if (op1_type->id == ZigTypeIdPointer &&14962 } else if (op1_type->id == ZigTypeIdPointer &&
14836 op1_type->data.pointer.child_type == ira->codegen->builtin_types.entry_u8 &&14963 op1_type->data.pointer.child_type == ira->codegen->builtin_types.entry_u8 &&
14837 op1_val->data.x_ptr.special == ConstPtrSpecialBaseArray &&14964 op1_type->data.pointer.ptr_len == PtrLenNull &&
14838 op1_val->data.x_ptr.data.base_array.is_cstr)14965 op1_val->data.x_ptr.special == ConstPtrSpecialBaseArray)
14839 {14966 {
14840 child_type = op1_type->data.pointer.child_type;14967 child_type = op1_type->data.pointer.child_type;
14841 op1_array_val = op1_val->data.x_ptr.data.base_array.array_val;14968 op1_array_val = op1_val->data.x_ptr.data.base_array.array_val;
14842 op1_array_index = op1_val->data.x_ptr.data.base_array.elem_index;14969 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;
14844 } else if (is_slice(op1_type)) {14972 } else if (is_slice(op1_type)) {
14845 ZigType *ptr_type = op1_type->data.structure.fields[slice_ptr_index]->type_entry;14973 ZigType *ptr_type = op1_type->data.structure.fields[slice_ptr_index]->type_entry;
14846 child_type = ptr_type->data.pointer.child_type;14974 child_type = ptr_type->data.pointer.child_type;
...@@ -14850,9 +14978,20 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i...@@ -14850,9 +14978,20 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
14850 op1_array_index = ptr_val->data.x_ptr.data.base_array.elem_index;14978 op1_array_index = ptr_val->data.x_ptr.data.base_array.elem_index;
14851 ConstExprValue *len_val = op1_val->data.x_struct.fields[slice_len_index];14979 ConstExprValue *len_val = op1_val->data.x_struct.fields[slice_len_index];
14852 op1_array_end = op1_array_index + bigint_as_usize(&len_val->data.x_bigint);14980 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;
14853 } else {14992 } else {
14854 ir_add_error(ira, op1,14993 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)));
14856 return ira->codegen->invalid_instruction;14995 return ira->codegen->invalid_instruction;
14857 }14996 }
1485814997
...@@ -14866,14 +15005,14 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i...@@ -14866,14 +15005,14 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
14866 op2_array_index = 0;15005 op2_array_index = 0;
14867 op2_array_end = op2_array_val->type->data.array.len;15006 op2_array_end = op2_array_val->type->data.array.len;
14868 } else if (op2_type->id == ZigTypeIdPointer &&15007 } else if (op2_type->id == ZigTypeIdPointer &&
14869 op2_type->data.pointer.child_type == ira->codegen->builtin_types.entry_u8 &&15008 op2_type->data.pointer.ptr_len == PtrLenNull &&
14870 op2_val->data.x_ptr.special == ConstPtrSpecialBaseArray &&15009 op2_val->data.x_ptr.special == ConstPtrSpecialBaseArray)
14871 op2_val->data.x_ptr.data.base_array.is_cstr)
14872 {15010 {
14873 op2_type_valid = child_type == ira->codegen->builtin_types.entry_u8;15011 op2_type_valid = op2_type->data.pointer.child_type == child_type;
14874 op2_array_val = op2_val->data.x_ptr.data.base_array.array_val;15012 op2_array_val = op2_val->data.x_ptr.data.base_array.array_val;
14875 op2_array_index = op2_val->data.x_ptr.data.base_array.elem_index;15013 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;
14877 } else if (is_slice(op2_type)) {15016 } else if (is_slice(op2_type)) {
14878 ZigType *ptr_type = op2_type->data.structure.fields[slice_ptr_index]->type_entry;15017 ZigType *ptr_type = op2_type->data.structure.fields[slice_ptr_index]->type_entry;
14879 op2_type_valid = ptr_type->data.pointer.child_type == child_type;15018 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...@@ -14883,6 +15022,17 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
14883 op2_array_index = ptr_val->data.x_ptr.data.base_array.elem_index;15022 op2_array_index = ptr_val->data.x_ptr.data.base_array.elem_index;
14884 ConstExprValue *len_val = op2_val->data.x_struct.fields[slice_len_index];15023 ConstExprValue *len_val = op2_val->data.x_struct.fields[slice_len_index];
14885 op2_array_end = op2_array_index + bigint_as_usize(&len_val->data.x_bigint);15024 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;
14886 } else {15036 } else {
14887 ir_add_error(ira, op2,15037 ir_add_error(ira, op2,
14888 buf_sprintf("expected array or C string literal, found '%s'", buf_ptr(&op2->value.type->name)));15038 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...@@ -14905,6 +15055,14 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
14905 result->value.type = get_array_type(ira->codegen, child_type, new_len, false);15055 result->value.type = get_array_type(ira->codegen, child_type, new_len, false);
1490615056
14907 out_array_val = out_val;15057 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);
14908 } else if (is_slice(op1_type) || is_slice(op2_type)) {15066 } else if (is_slice(op1_type) || is_slice(op2_type)) {
14909 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, child_type,15067 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, child_type,
14910 true, false, PtrLenUnknown, 0, 0, 0, false);15068 true, false, PtrLenUnknown, 0, 0, 0, false);
...@@ -14925,22 +15083,20 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i...@@ -14925,22 +15083,20 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
14925 out_val->data.x_struct.fields[slice_len_index]->special = ConstValSpecialStatic;15083 out_val->data.x_struct.fields[slice_len_index]->special = ConstValSpecialStatic;
14926 bigint_init_unsigned(&out_val->data.x_struct.fields[slice_len_index]->data.x_bigint, new_len);15084 bigint_init_unsigned(&out_val->data.x_struct.fields[slice_len_index]->data.x_bigint, new_len);
14927 } else {15085 } else {
14928 new_len += 1; // null byte15086 result->value.type = get_pointer_to_type_extra(ira->codegen, child_type, true, false, PtrLenNull,
1492915087 0, 0, 0, false);
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);
1493215088
14933 out_array_val = create_const_vals(1);15089 out_array_val = create_const_vals(1);
14934 out_array_val->special = ConstValSpecialStatic;15090 out_array_val->special = ConstValSpecialStatic;
14935 out_array_val->type = get_array_type(ira->codegen, child_type, new_len, false);15091 out_array_val->type = get_array_type(ira->codegen, child_type, new_len, false);
14936 out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;15092 out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;
14937 out_val->data.x_ptr.data.base_array.is_cstr = true;
14938 out_val->data.x_ptr.data.base_array.array_val = out_array_val;15093 out_val->data.x_ptr.data.base_array.array_val = out_array_val;
14939 out_val->data.x_ptr.data.base_array.elem_index = 0;15094 out_val->data.x_ptr.data.base_array.elem_index = 0;
14940 }15095 }
1494115096
14942 if (op1_array_val->data.x_array.special == ConstArraySpecialUndef &&15097 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 {
14944 out_array_val->data.x_array.special = ConstArraySpecialUndef;15100 out_array_val->data.x_array.special = ConstArraySpecialUndef;
14945 return result;15101 return result;
14946 }15102 }
...@@ -14978,20 +15134,34 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *...@@ -14978,20 +15134,34 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *
14978 if (type_is_invalid(op2->value.type))15134 if (type_is_invalid(op2->value.type))
14979 return ira->codegen->invalid_instruction;15135 return ira->codegen->invalid_instruction;
1498015136
14981 ConstExprValue *array_val = ir_resolve_const(ira, op1, UndefBad);15137 bool want_ptr_to_array = false;
14982 if (!array_val)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)));
14983 return ira->codegen->invalid_instruction;15158 return ira->codegen->invalid_instruction;
15159 }
1498415160
14985 uint64_t mult_amt;15161 uint64_t mult_amt;
14986 if (!ir_resolve_usize(ira, op2, &mult_amt))15162 if (!ir_resolve_usize(ira, op2, &mult_amt))
14987 return ira->codegen->invalid_instruction;15163 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
14995 uint64_t old_array_len = array_type->data.array.len;15165 uint64_t old_array_len = array_type->data.array.len;
14996 uint64_t new_array_len;15166 uint64_t new_array_len;
1499715167
...@@ -15001,42 +15171,59 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *...@@ -15001,42 +15171,59 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *
15001 }15171 }
1500215172
15003 ZigType *child_type = array_type->data.array.child_type;15173 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,15177 IrInstruction *array_result;
15006 get_array_type(ira->codegen, child_type, new_array_len, false));15178 if (array_val->special == ConstValSpecialUndef || array_val->data.x_array.special == ConstArraySpecialUndef) {
15007 ConstExprValue *out_val = &result->value;15179 array_result = ir_const_undef(ira, &instruction->base, result_array_type);
15008 if (array_val->data.x_array.special == ConstArraySpecialUndef) {15180 } else {
15009 out_val->data.x_array.special = ConstArraySpecialUndef;15181 array_result = ir_const(ira, &instruction->base, result_array_type);
15010 return result;15182 ConstExprValue *out_val = &array_result->value;
15011 }
1501215183
15013 switch (type_has_one_possible_value(ira->codegen, result->value.type)) {15184 switch (type_has_one_possible_value(ira->codegen, result_array_type)) {
15014 case OnePossibleValueInvalid:15185 case OnePossibleValueInvalid:
15015 return ira->codegen->invalid_instruction;15186 return ira->codegen->invalid_instruction;
15016 case OnePossibleValueYes:15187 case OnePossibleValueYes:
15017 return result;15188 goto skip_computation;
15018 case OnePossibleValueNo:15189 case OnePossibleValueNo:
15019 break;15190 break;
15020 }15191 }
1502115192
15022 // TODO optimize the buf case15193 // TODO optimize the buf case
15023 expand_undef_array(ira->codegen, array_val);15194 expand_undef_array(ira->codegen, array_val);
15024 out_val->data.x_array.data.s_none.elements = create_const_vals(new_array_len);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;15198 uint64_t i = 0;
15027 for (uint64_t x = 0; x < mult_amt; x += 1) {15199 for (uint64_t x = 0; x < mult_amt; x += 1) {
15028 for (uint64_t y = 0; y < old_array_len; y += 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);
15029 ConstExprValue *elem_dest_val = &out_val->data.x_array.data.s_none.elements[i];15213 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);
15031 elem_dest_val->parent.id = ConstParentIdArray;15215 elem_dest_val->parent.id = ConstParentIdArray;
15032 elem_dest_val->parent.data.p_array.array_val = out_val;15216 elem_dest_val->parent.data.p_array.array_val = out_val;
15033 elem_dest_val->parent.data.p_array.elem_index = i;15217 elem_dest_val->parent.data.p_array.elem_index = i;
15034 i += 1;15218 i += 1;
15035 }15219 }
15036 }15220 }
15037 assert(i == new_array_len);15221skip_computation:
1503815222 if (want_ptr_to_array) {
15039 return result;15223 return ir_get_ref(ira, &instruction->base, array_result, true, false);
15224 } else {
15225 return array_result;
15226 }
15040}15227}
1504115228
15042static IrInstruction *ir_analyze_instruction_merge_err_sets(IrAnalyze *ira,15229static 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...@@ -17309,6 +17496,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source
17309 assert(out_val->type != nullptr);17496 assert(out_val->type != nullptr);
1731017497
17311 ConstExprValue *pointee = const_ptr_pointee_unchecked(codegen, ptr_val);17498 ConstExprValue *pointee = const_ptr_pointee_unchecked(codegen, ptr_val);
17499 src_assert(pointee->type != nullptr, source_node);
1731217500
17313 if ((err = type_resolve(codegen, pointee->type, ResolveStatusSizeKnown)))17501 if ((err = type_resolve(codegen, pointee->type, ResolveStatusSizeKnown)))
17314 return ErrorSemanticAnalyzeFail;17502 return ErrorSemanticAnalyzeFail;
...@@ -17319,7 +17507,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source...@@ -17319,7 +17507,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source
17319 size_t dst_size = type_size(codegen, out_val->type);17507 size_t dst_size = type_size(codegen, out_val->type);
1732017508
17321 if (dst_size <= src_size) {17509 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)) {
17323 copy_const_val(out_val, pointee, ptr_val->data.x_ptr.mut != ConstPtrMutComptimeVar);17511 copy_const_val(out_val, pointee, ptr_val->data.x_ptr.mut != ConstPtrMutComptimeVar);
17324 return ErrorNone;17512 return ErrorNone;
17325 }17513 }
...@@ -18070,6 +18258,12 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -18070,6 +18258,12 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
18070 uint64_t index = bigint_as_u64(&casted_elem_index->value.data.x_bigint);18258 uint64_t index = bigint_as_u64(&casted_elem_index->value.data.x_bigint);
18071 if (array_type->id == ZigTypeIdArray) {18259 if (array_type->id == ZigTypeIdArray) {
18072 uint64_t array_len = array_type->data.array.len;18260 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 }
18073 if (index >= array_len) {18267 if (index >= array_len) {
18074 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,18268 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
18075 buf_sprintf("index %" ZIG_PRI_u64 " outside array of size %" ZIG_PRI_u64,18269 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...@@ -18203,7 +18397,11 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
18203 {18397 {
18204 size_t offset = array_ptr_val->data.x_ptr.data.base_array.elem_index;18398 size_t offset = array_ptr_val->data.x_ptr.data.base_array.elem_index;
18205 new_index = offset + index;18399 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 }
18207 old_size = mem_size - offset;18405 old_size = mem_size - offset;
1820818406
18209 assert(array_ptr_val->data.x_ptr.data.base_array.array_val);18407 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...@@ -18212,8 +18410,6 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
18212 out_val->data.x_ptr.data.base_array.array_val =18410 out_val->data.x_ptr.data.base_array.array_val =
18213 array_ptr_val->data.x_ptr.data.base_array.array_val;18411 array_ptr_val->data.x_ptr.data.base_array.array_val;
18214 out_val->data.x_ptr.data.base_array.elem_index = new_index;18412 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
18218 break;18414 break;
18219 }18415 }
...@@ -18277,8 +18473,6 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -18277,8 +18473,6 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
18277 out_val->data.x_ptr.data.base_array.array_val =18473 out_val->data.x_ptr.data.base_array.array_val =
18278 ptr_field->data.x_ptr.data.base_array.array_val;18474 ptr_field->data.x_ptr.data.base_array.array_val;
18279 out_val->data.x_ptr.data.base_array.elem_index = new_index;18475 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;
18282 break;18476 break;
18283 }18477 }
18284 case ConstPtrSpecialBaseStruct:18478 case ConstPtrSpecialBaseStruct:
...@@ -19550,7 +19744,7 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr...@@ -19550,7 +19744,7 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr
19550 ZigType *result_type = get_pointer_to_type_extra(ira->codegen, child_type,19744 ZigType *result_type = get_pointer_to_type_extra(ira->codegen, child_type,
19551 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, PtrLenSingle, 0, 0, 0, false);19745 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
19555 if (instr_is_comptime(base_ptr)) {19749 if (instr_is_comptime(base_ptr)) {
19556 ConstExprValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad);19750 ConstExprValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad);
...@@ -20685,7 +20879,7 @@ static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruct...@@ -20685,7 +20879,7 @@ static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruct
20685 return ira->codegen->invalid_instruction;20879 return ira->codegen->invalid_instruction;
20686 ErrorTableEntry *err = casted_value->value.data.x_err_set;20880 ErrorTableEntry *err = casted_value->value.data.x_err_set;
20687 if (!err->cached_error_name_val) {20881 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;
20689 err->cached_error_name_val = create_const_slice(ira->codegen, array_val, 0, buf_len(&err->name), true);20883 err->cached_error_name_val = create_const_slice(ira->codegen, array_val, 0, buf_len(&err->name), true);
20690 }20884 }
20691 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);20885 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
...@@ -20714,7 +20908,7 @@ static IrInstruction *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrIns...@@ -20714,7 +20908,7 @@ static IrInstruction *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrIns
20714 if ((err = type_resolve(ira->codegen, target->value.type, ResolveStatusZeroBitsKnown)))20908 if ((err = type_resolve(ira->codegen, target->value.type, ResolveStatusZeroBitsKnown)))
20715 return ira->codegen->invalid_instruction;20909 return ira->codegen->invalid_instruction;
20716 TypeEnumField *field = find_enum_field_by_tag(target->value.type, &target->value.data.x_bigint);20910 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;
20718 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);20912 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
20719 init_const_slice(ira->codegen, &result->value, array_val, 0, buf_len(field->name), true);20913 init_const_slice(ira->codegen, &result->value, array_val, 0, buf_len(field->name), true);
20720 return result;20914 return result;
...@@ -21019,7 +21213,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr...@@ -21019,7 +21213,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
21019 declaration_val->type = type_info_declaration_type;21213 declaration_val->type = type_info_declaration_type;
2102021214
21021 ConstExprValue **inner_fields = alloc_const_vals_ptrs(3);21215 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;
21023 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(curr_entry->key), true);21217 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(curr_entry->key), true);
21024 inner_fields[1]->special = ConstValSpecialStatic;21218 inner_fields[1]->special = ConstValSpecialStatic;
21025 inner_fields[1]->type = ira->codegen->builtin_types.entry_bool;21219 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...@@ -21122,7 +21316,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
21122 fn_decl_fields[6]->type = get_optional_type(ira->codegen, get_slice_type(ira->codegen, u8_ptr));21316 fn_decl_fields[6]->type = get_optional_type(ira->codegen, get_slice_type(ira->codegen, u8_ptr));
21123 if (fn_node->is_extern && fn_node->lib_name != nullptr && buf_len(fn_node->lib_name) > 0) {21317 if (fn_node->is_extern && fn_node->lib_name != nullptr && buf_len(fn_node->lib_name) > 0) {
21124 fn_decl_fields[6]->data.x_optional = create_const_vals(1);21318 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;
21126 init_const_slice(ira->codegen, fn_decl_fields[6]->data.x_optional, lib_name, 0,21320 init_const_slice(ira->codegen, fn_decl_fields[6]->data.x_optional, lib_name, 0,
21127 buf_len(fn_node->lib_name), true);21321 buf_len(fn_node->lib_name), true);
21128 } else {21322 } else {
...@@ -21149,7 +21343,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr...@@ -21149,7 +21343,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
21149 ZigVar *arg_var = fn_entry->variable_list.at(fn_arg_index);21343 ZigVar *arg_var = fn_entry->variable_list.at(fn_arg_index);
21150 ConstExprValue *fn_arg_name_val = &fn_arg_name_array->data.x_array.data.s_none.elements[fn_arg_index];21344 ConstExprValue *fn_arg_name_val = &fn_arg_name_array->data.x_array.data.s_none.elements[fn_arg_index];
21151 ConstExprValue *arg_name = create_const_str_lit(ira->codegen,21345 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;
21153 init_const_slice(ira->codegen, fn_arg_name_val, arg_name, 0, strlen(arg_var->name), true);21347 init_const_slice(ira->codegen, fn_arg_name_val, arg_name, 0, strlen(arg_var->name), true);
21154 fn_arg_name_val->parent.id = ConstParentIdArray;21348 fn_arg_name_val->parent.id = ConstParentIdArray;
21155 fn_arg_name_val->parent.data.p_array.array_val = fn_arg_name_array;21349 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,...@@ -21294,7 +21488,7 @@ static void make_enum_field_val(IrAnalyze *ira, ConstExprValue *enum_field_val,
21294 inner_fields[1]->special = ConstValSpecialStatic;21488 inner_fields[1]->special = ConstValSpecialStatic;
21295 inner_fields[1]->type = ira->codegen->builtin_types.entry_num_lit_int;21489 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;
21298 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(enum_field->name), true);21492 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(enum_field->name), true);
2129921493
21300 bigint_init_bigint(&inner_fields[1]->data.x_bigint, &enum_field->value);21494 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...@@ -21560,7 +21754,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21560 if (error->cached_error_name_val != nullptr)21754 if (error->cached_error_name_val != nullptr)
21561 name = error->cached_error_name_val;21755 name = error->cached_error_name_val;
21562 if (name == nullptr)21756 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;
21564 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(&error->name), true);21758 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(&error->name), true);
21565 bigint_init_unsigned(&inner_fields[1]->data.x_bigint, error->value);21759 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...@@ -21666,7 +21860,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21666 inner_fields[2]->type = ira->codegen->builtin_types.entry_type;21860 inner_fields[2]->type = ira->codegen->builtin_types.entry_type;
21667 inner_fields[2]->data.x_type = union_field->type_entry;21861 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;
21670 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(union_field->name), true);21864 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(union_field->name), true);
2167121865
21672 union_field_val->data.x_struct.fields = inner_fields;21866 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...@@ -21752,7 +21946,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21752 inner_fields[2]->type = ira->codegen->builtin_types.entry_type;21946 inner_fields[2]->type = ira->codegen->builtin_types.entry_type;
21753 inner_fields[2]->data.x_type = struct_field->type_entry;21947 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;
21756 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(struct_field->name), true);21950 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(struct_field->name), true);
2175721951
21758 struct_field_val->data.x_struct.fields = inner_fields;21952 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) {...@@ -1718,7 +1718,6 @@ static AstNode *ast_parse_primary_type_expr(ParseContext *pc) {
1718 if (string_lit != nullptr) {1718 if (string_lit != nullptr) {
1719 AstNode *res = ast_create_node(pc, NodeTypeStringLiteral, string_lit);1719 AstNode *res = ast_create_node(pc, NodeTypeStringLiteral, string_lit);
1720 res->data.string_literal.buf = token_buf(string_lit);1720 res->data.string_literal.buf = token_buf(string_lit);
1721 res->data.string_literal.c = string_lit->data.str_lit.is_c_str;
1722 return res;1721 return res;
1723 }1722 }
17241723
src/tokenizer.cpp+3-50
...@@ -33,10 +33,10 @@...@@ -33,10 +33,10 @@
33 '0': \33 '0': \
34 case DIGIT_NON_ZERO34 case DIGIT_NON_ZERO
3535
36#define ALPHA_EXCEPT_C \36#define ALPHA \
37 'a': \37 'a': \
38 case 'b': \38 case 'b': \
39 /*case 'c':*/ \39 case 'c': \
40 case 'd': \40 case 'd': \
41 case 'e': \41 case 'e': \
42 case 'f': \42 case 'f': \
...@@ -87,10 +87,6 @@...@@ -87,10 +87,6 @@
87 case 'Y': \87 case 'Y': \
88 case 'Z'88 case 'Z'
8989
90#define ALPHA \
91 ALPHA_EXCEPT_C: \
92 case 'c'
93
94#define SYMBOL_CHAR \90#define SYMBOL_CHAR \
95 ALPHA: \91 ALPHA: \
96 case DIGIT: \92 case DIGIT: \
...@@ -180,7 +176,6 @@ static bool is_symbol_char(uint8_t c) {...@@ -180,7 +176,6 @@ static bool is_symbol_char(uint8_t c) {
180enum TokenizeState {176enum TokenizeState {
181 TokenizeStateStart,177 TokenizeStateStart,
182 TokenizeStateSymbol,178 TokenizeStateSymbol,
183 TokenizeStateSymbolFirstC,
184 TokenizeStateZero, // "0", which might lead to "0x"179 TokenizeStateZero, // "0", which might lead to "0x"
185 TokenizeStateNumber, // "123", "0x123"180 TokenizeStateNumber, // "123", "0x123"
186 TokenizeStateNumberDot,181 TokenizeStateNumberDot,
...@@ -279,7 +274,6 @@ static void set_token_id(Tokenize *t, Token *token, TokenId id) {...@@ -279,7 +274,6 @@ static void set_token_id(Tokenize *t, Token *token, TokenId id) {
279 } else if (id == TokenIdStringLiteral || id == TokenIdSymbol) {274 } else if (id == TokenIdStringLiteral || id == TokenIdSymbol) {
280 memset(&token->data.str_lit.str, 0, sizeof(Buf));275 memset(&token->data.str_lit.str, 0, sizeof(Buf));
281 buf_resize(&token->data.str_lit.str, 0);276 buf_resize(&token->data.str_lit.str, 0);
282 token->data.str_lit.is_c_str = false;
283 }277 }
284}278}
285279
...@@ -429,12 +423,7 @@ void tokenize(Buf *buf, Tokenization *out) {...@@ -429,12 +423,7 @@ void tokenize(Buf *buf, Tokenization *out) {
429 switch (c) {423 switch (c) {
430 case WHITESPACE:424 case WHITESPACE:
431 break;425 break;
432 case 'c':426 case ALPHA:
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:
438 case '_':427 case '_':
439 t.state = TokenizeStateSymbol;428 t.state = TokenizeStateSymbol;
440 begin_token(&t, TokenIdSymbol);429 begin_token(&t, TokenIdSymbol);
...@@ -1007,19 +996,7 @@ void tokenize(Buf *buf, Tokenization *out) {...@@ -1007,19 +996,7 @@ void tokenize(Buf *buf, Tokenization *out) {
1007 switch (c) {996 switch (c) {
1008 case WHITESPACE:997 case WHITESPACE:
1009 break;998 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;
1019 case '\\':999 case '\\':
1020 if (t.cur_tok->data.str_lit.is_c_str) {
1021 invalid_char_error(&t, c);
1022 }
1023 t.state = TokenizeStateLineStringContinue;1000 t.state = TokenizeStateLineStringContinue;
1024 break;1001 break;
1025 default:1002 default:
...@@ -1084,29 +1061,6 @@ void tokenize(Buf *buf, Tokenization *out) {...@@ -1084,29 +1061,6 @@ void tokenize(Buf *buf, Tokenization *out) {
1084 break;1061 break;
1085 }1062 }
1086 break;1063 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;
1110 case TokenizeStateSawAtSign:1064 case TokenizeStateSawAtSign:
1111 switch (c) {1065 switch (c) {
1112 case '"':1066 case '"':
...@@ -1544,7 +1498,6 @@ void tokenize(Buf *buf, Tokenization *out) {...@@ -1544,7 +1498,6 @@ void tokenize(Buf *buf, Tokenization *out) {
1544 tokenize_error(&t, "unterminated character literal");1498 tokenize_error(&t, "unterminated character literal");
1545 break;1499 break;
1546 case TokenizeStateSymbol:1500 case TokenizeStateSymbol:
1547 case TokenizeStateSymbolFirstC:
1548 case TokenizeStateZero:1501 case TokenizeStateZero:
1549 case TokenizeStateNumber:1502 case TokenizeStateNumber:
1550 case TokenizeStateFloatFraction:1503 case TokenizeStateFloatFraction:
src/tokenizer.hpp-1
...@@ -149,7 +149,6 @@ struct TokenIntLit {...@@ -149,7 +149,6 @@ struct TokenIntLit {
149149
150struct TokenStrLit {150struct TokenStrLit {
151 Buf str;151 Buf str;
152 bool is_c_str;
153};152};
154153
155struct TokenCharLit {154struct TokenCharLit {
src/translate_c.cpp+5-13
...@@ -323,17 +323,9 @@ static AstNode *trans_create_node_bool(Context *c, bool value) {...@@ -323,17 +323,9 @@ static AstNode *trans_create_node_bool(Context *c, bool value) {
323 return bool_node;323 return bool_node;
324}324}
325325
326static AstNode *trans_create_node_str_lit_c(Context *c, Buf *buf) {326static AstNode *trans_create_node_str_lit(Context *c, Buf *buf) {
327 AstNode *node = trans_create_node(c, NodeTypeStringLiteral);327 AstNode *node = trans_create_node(c, NodeTypeStringLiteral);
328 node->data.string_literal.buf = buf;328 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;
337 return node;329 return node;
338}330}
339331
...@@ -632,7 +624,7 @@ static AstNode *qual_type_to_log2_int_ref(Context *c, const ZigClangQualType qt,...@@ -632,7 +624,7 @@ static AstNode *qual_type_to_log2_int_ref(Context *c, const ZigClangQualType qt,
632// zig_type_node624// zig_type_node
633625
634 AstNode *import_fn_call = trans_create_node_builtin_fn_call_str(c, "import");626 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")));
636 AstNode *inner_field_access = trans_create_node_field_access_str(c, import_fn_call, "math");628 AstNode *inner_field_access = trans_create_node_field_access_str(c, import_fn_call, "math");
637 AstNode *outer_field_access = trans_create_node_field_access_str(c, inner_field_access, "Log2Int");629 AstNode *outer_field_access = trans_create_node_field_access_str(c, inner_field_access, "Log2Int");
638 AstNode *log2int_fn_call = trans_create_node_fn_call_1(c, outer_field_access, zig_type_node);630 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...@@ -3391,7 +3383,7 @@ static AstNode *trans_string_literal(Context *c, ResultUsed result_used, TransSc
3391 case ZigClangStringLiteral_StringKind_UTF8: {3383 case ZigClangStringLiteral_StringKind_UTF8: {
3392 size_t str_len;3384 size_t str_len;
3393 const char *str_ptr = ZigClangStringLiteral_getString_bytes_begin_size(stmt, &str_len);3385 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));
3395 return maybe_suppress_result(c, result_used, node);3387 return maybe_suppress_result(c, result_used, node);
3396 }3388 }
3397 case ZigClangStringLiteral_StringKind_UTF16:3389 case ZigClangStringLiteral_StringKind_UTF16:
...@@ -4890,7 +4882,7 @@ static AstNode *parse_ctok_primary_expr(Context *c, CTokenize *ctok, size_t *tok...@@ -4890,7 +4882,7 @@ static AstNode *parse_ctok_primary_expr(Context *c, CTokenize *ctok, size_t *tok
4890 return trans_create_node_unsigned(c, tok->data.char_lit);4882 return trans_create_node_unsigned(c, tok->data.char_lit);
4891 case CTokIdStrLit:4883 case CTokIdStrLit:
4892 *tok_i += 1;4884 *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));
4894 case CTokIdMinus:4886 case CTokIdMinus:
4895 *tok_i += 1;4887 *tok_i += 1;
4896 return parse_ctok_num_lit(c, ctok, tok_i, true);4888 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...@@ -4937,7 +4929,7 @@ static AstNode *parse_ctok_primary_expr(Context *c, CTokenize *ctok, size_t *tok
4937 // (dest)(x)4929 // (dest)(x)
49384930
4939 AstNode *import_builtin = trans_create_node_builtin_fn_call_str(c, "import");4931 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")));
4941 AstNode *typeid_type = trans_create_node_field_access_str(c, import_builtin, "TypeId");4933 AstNode *typeid_type = trans_create_node_field_access_str(c, import_builtin, "TypeId");
4942 AstNode *typeid_pointer = trans_create_node_field_access_str(c, typeid_type, "Pointer");4934 AstNode *typeid_pointer = trans_create_node_field_access_str(c, typeid_type, "Pointer");
4943 AstNode *typeid_integer = trans_create_node_field_access_str(c, typeid_type, "Int");4935 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 {...@@ -7,7 +7,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
7 cases.addC("hello world with libc",7 cases.addC("hello world with libc",
8 \\const c = @cImport(@cInclude("stdio.h"));8 \\const c = @cImport(@cInclude("stdio.h"));
9 \\export fn main(argc: c_int, argv: [*][*]u8) c_int {9 \\export fn main(argc: c_int, argv: [*][*]u8) c_int {
10 \\ _ = c.puts(c"Hello, world!");10 \\ _ = c.puts("Hello, world!");
11 \\ return 0;11 \\ return 0;
12 \\}12 \\}
13 , "Hello, world!" ++ std.cstr.line_sep);13 , "Hello, world!" ++ std.cstr.line_sep);
...@@ -144,75 +144,75 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -144,75 +144,75 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
144 \\ // we want actual \n, not \r\n144 \\ // we want actual \n, not \r\n
145 \\ _ = c._setmode(1, c._O_BINARY);145 \\ _ = c._setmode(1, c._O_BINARY);
146 \\ }146 \\ }
147 \\ _ = c.printf(c"0: %llu\n",147 \\ _ = c.printf("0: %llu\n",
148 \\ @as(u64, 0));148 \\ @as(u64, 0));
149 \\ _ = c.printf(c"320402575052271: %llu\n",149 \\ _ = c.printf("320402575052271: %llu\n",
150 \\ @as(u64, 320402575052271));150 \\ @as(u64, 320402575052271));
151 \\ _ = c.printf(c"0x01236789abcdef: %llu\n",151 \\ _ = c.printf("0x01236789abcdef: %llu\n",
152 \\ @as(u64, 0x01236789abcdef));152 \\ @as(u64, 0x01236789abcdef));
153 \\ _ = c.printf(c"0xffffffffffffffff: %llu\n",153 \\ _ = c.printf("0xffffffffffffffff: %llu\n",
154 \\ @as(u64, 0xffffffffffffffff));154 \\ @as(u64, 0xffffffffffffffff));
155 \\ _ = c.printf(c"0x000000ffffffffffffffff: %llu\n",155 \\ _ = c.printf("0x000000ffffffffffffffff: %llu\n",
156 \\ @as(u64, 0x000000ffffffffffffffff));156 \\ @as(u64, 0x000000ffffffffffffffff));
157 \\ _ = c.printf(c"0o1777777777777777777777: %llu\n",157 \\ _ = c.printf("0o1777777777777777777777: %llu\n",
158 \\ @as(u64, 0o1777777777777777777777));158 \\ @as(u64, 0o1777777777777777777777));
159 \\ _ = c.printf(c"0o0000001777777777777777777777: %llu\n",159 \\ _ = c.printf("0o0000001777777777777777777777: %llu\n",
160 \\ @as(u64, 0o0000001777777777777777777777));160 \\ @as(u64, 0o0000001777777777777777777777));
161 \\ _ = c.printf(c"0b1111111111111111111111111111111111111111111111111111111111111111: %llu\n",161 \\ _ = c.printf("0b1111111111111111111111111111111111111111111111111111111111111111: %llu\n",
162 \\ @as(u64, 0b1111111111111111111111111111111111111111111111111111111111111111));162 \\ @as(u64, 0b1111111111111111111111111111111111111111111111111111111111111111));
163 \\ _ = c.printf(c"0b0000001111111111111111111111111111111111111111111111111111111111111111: %llu\n",163 \\ _ = c.printf("0b0000001111111111111111111111111111111111111111111111111111111111111111: %llu\n",
164 \\ @as(u64, 0b0000001111111111111111111111111111111111111111111111111111111111111111));164 \\ @as(u64, 0b0000001111111111111111111111111111111111111111111111111111111111111111));
165 \\165 \\
166 \\ _ = c.printf(c"\n");166 \\ _ = c.printf("\n");
167 \\167 \\
168 \\ _ = c.printf(c"0.0: %.013a\n",168 \\ _ = c.printf("0.0: %.013a\n",
169 \\ @as(f64, 0.0));169 \\ @as(f64, 0.0));
170 \\ _ = c.printf(c"0e0: %.013a\n",170 \\ _ = c.printf("0e0: %.013a\n",
171 \\ @as(f64, 0e0));171 \\ @as(f64, 0e0));
172 \\ _ = c.printf(c"0.0e0: %.013a\n",172 \\ _ = c.printf("0.0e0: %.013a\n",
173 \\ @as(f64, 0.0e0));173 \\ @as(f64, 0.0e0));
174 \\ _ = c.printf(c"000000000000000000000000000000000000000000000000000000000.0e0: %.013a\n",174 \\ _ = c.printf("000000000000000000000000000000000000000000000000000000000.0e0: %.013a\n",
175 \\ @as(f64, 000000000000000000000000000000000000000000000000000000000.0e0));175 \\ @as(f64, 000000000000000000000000000000000000000000000000000000000.0e0));
176 \\ _ = c.printf(c"0.000000000000000000000000000000000000000000000000000000000e0: %.013a\n",176 \\ _ = c.printf("0.000000000000000000000000000000000000000000000000000000000e0: %.013a\n",
177 \\ @as(f64, 0.000000000000000000000000000000000000000000000000000000000e0));177 \\ @as(f64, 0.000000000000000000000000000000000000000000000000000000000e0));
178 \\ _ = c.printf(c"0.0e000000000000000000000000000000000000000000000000000000000: %.013a\n",178 \\ _ = c.printf("0.0e000000000000000000000000000000000000000000000000000000000: %.013a\n",
179 \\ @as(f64, 0.0e000000000000000000000000000000000000000000000000000000000));179 \\ @as(f64, 0.0e000000000000000000000000000000000000000000000000000000000));
180 \\ _ = c.printf(c"1.0: %.013a\n",180 \\ _ = c.printf("1.0: %.013a\n",
181 \\ @as(f64, 1.0));181 \\ @as(f64, 1.0));
182 \\ _ = c.printf(c"10.0: %.013a\n",182 \\ _ = c.printf("10.0: %.013a\n",
183 \\ @as(f64, 10.0));183 \\ @as(f64, 10.0));
184 \\ _ = c.printf(c"10.5: %.013a\n",184 \\ _ = c.printf("10.5: %.013a\n",
185 \\ @as(f64, 10.5));185 \\ @as(f64, 10.5));
186 \\ _ = c.printf(c"10.5e5: %.013a\n",186 \\ _ = c.printf("10.5e5: %.013a\n",
187 \\ @as(f64, 10.5e5));187 \\ @as(f64, 10.5e5));
188 \\ _ = c.printf(c"10.5e+5: %.013a\n",188 \\ _ = c.printf("10.5e+5: %.013a\n",
189 \\ @as(f64, 10.5e+5));189 \\ @as(f64, 10.5e+5));
190 \\ _ = c.printf(c"50.0e-2: %.013a\n",190 \\ _ = c.printf("50.0e-2: %.013a\n",
191 \\ @as(f64, 50.0e-2));191 \\ @as(f64, 50.0e-2));
192 \\ _ = c.printf(c"50e-2: %.013a\n",192 \\ _ = c.printf("50e-2: %.013a\n",
193 \\ @as(f64, 50e-2));193 \\ @as(f64, 50e-2));
194 \\194 \\
195 \\ _ = c.printf(c"\n");195 \\ _ = c.printf("\n");
196 \\196 \\
197 \\ _ = c.printf(c"0x1.0: %.013a\n",197 \\ _ = c.printf("0x1.0: %.013a\n",
198 \\ @as(f64, 0x1.0));198 \\ @as(f64, 0x1.0));
199 \\ _ = c.printf(c"0x10.0: %.013a\n",199 \\ _ = c.printf("0x10.0: %.013a\n",
200 \\ @as(f64, 0x10.0));200 \\ @as(f64, 0x10.0));
201 \\ _ = c.printf(c"0x100.0: %.013a\n",201 \\ _ = c.printf("0x100.0: %.013a\n",
202 \\ @as(f64, 0x100.0));202 \\ @as(f64, 0x100.0));
203 \\ _ = c.printf(c"0x103.0: %.013a\n",203 \\ _ = c.printf("0x103.0: %.013a\n",
204 \\ @as(f64, 0x103.0));204 \\ @as(f64, 0x103.0));
205 \\ _ = c.printf(c"0x103.7: %.013a\n",205 \\ _ = c.printf("0x103.7: %.013a\n",
206 \\ @as(f64, 0x103.7));206 \\ @as(f64, 0x103.7));
207 \\ _ = c.printf(c"0x103.70: %.013a\n",207 \\ _ = c.printf("0x103.70: %.013a\n",
208 \\ @as(f64, 0x103.70));208 \\ @as(f64, 0x103.70));
209 \\ _ = c.printf(c"0x103.70p4: %.013a\n",209 \\ _ = c.printf("0x103.70p4: %.013a\n",
210 \\ @as(f64, 0x103.70p4));210 \\ @as(f64, 0x103.70p4));
211 \\ _ = c.printf(c"0x103.70p5: %.013a\n",211 \\ _ = c.printf("0x103.70p5: %.013a\n",
212 \\ @as(f64, 0x103.70p5));212 \\ @as(f64, 0x103.70p5));
213 \\ _ = c.printf(c"0x103.70p+5: %.013a\n",213 \\ _ = c.printf("0x103.70p+5: %.013a\n",
214 \\ @as(f64, 0x103.70p+5));214 \\ @as(f64, 0x103.70p+5));
215 \\ _ = c.printf(c"0x103.70p-5: %.013a\n",215 \\ _ = c.printf("0x103.70p-5: %.013a\n",
216 \\ @as(f64, 0x103.70p-5));216 \\ @as(f64, 0x103.70p-5));
217 \\217 \\
218 \\ return 0;218 \\ return 0;
...@@ -323,7 +323,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -323,7 +323,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
323 \\ const x: f64 = small;323 \\ const x: f64 = small;
324 \\ const y = @floatToInt(i32, x);324 \\ const y = @floatToInt(i32, x);
325 \\ const z = @intToFloat(f64, y);325 \\ 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));
327 \\ return 0;327 \\ return 0;
328 \\}328 \\}
329 , "3.25\n3\n3.00\n-0.40\n");329 , "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 {...@@ -164,7 +164,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
164 cases.add(164 cases.add(
165 "using an unknown len ptr type instead of array",165 "using an unknown len ptr type instead of array",
166 \\const resolutions = [*][*]const u8{166 \\const resolutions = [*][*]const u8{
167 \\ c"[320 240 ]",167 \\ "[320 240 ]",
168 \\ null,168 \\ null,
169 \\};169 \\};
170 \\comptime {170 \\comptime {
...@@ -781,7 +781,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -781,7 +781,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
781 "peer cast then implicit cast const pointer to mutable C pointer",781 "peer cast then implicit cast const pointer to mutable C pointer",
782 \\export fn func() void {782 \\export fn func() void {
783 \\ var strValue: [*c]u8 = undefined;783 \\ var strValue: [*c]u8 = undefined;
784 \\ strValue = strValue orelse c"";784 \\ strValue = strValue orelse "";
785 \\}785 \\}
786 ,786 ,
787 "tmp.zig:3:32: error: cast discards const qualifier",787 "tmp.zig:3:32: error: cast discards const qualifier",
...@@ -1115,7 +1115,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -1115,7 +1115,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
1115 "libc headers note",1115 "libc headers note",
1116 \\const c = @cImport(@cInclude("stdio.h"));1116 \\const c = @cImport(@cInclude("stdio.h"));
1117 \\export fn entry() void {1117 \\export fn entry() void {
1118 \\ _ = c.printf(c"hello, world!\n");1118 \\ _ = c.printf("hello, world!\n");
1119 \\}1119 \\}
1120 ,1120 ,
1121 "tmp.zig:1:11: error: C import failed",1121 "tmp.zig:1:11: error: C import failed",
...@@ -3352,7 +3352,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3352,7 +3352,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3352 cases.add(3352 cases.add(
3353 "variable has wrong type",3353 "variable has wrong type",
3354 \\export fn f() i32 {3354 \\export fn f() i32 {
3355 \\ const a = c"a";3355 \\ const a = "a";
3356 \\ return a;3356 \\ return a;
3357 \\}3357 \\}
3358 ,3358 ,
...@@ -4786,7 +4786,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4786,7 +4786,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4786 cases.add(4786 cases.add(
4787 "assign through constant pointer",4787 "assign through constant pointer",
4788 \\export fn f() void {4788 \\export fn f() void {
4789 \\ var cstr = c"Hat";4789 \\ var cstr = "Hat";
4790 \\ cstr[0] = 'W';4790 \\ cstr[0] = 'W';
4791 \\}4791 \\}
4792 ,4792 ,
test/stage1/behavior/array.zig+33-6
...@@ -132,9 +132,16 @@ test "single-item pointer to array indexing and slicing" {...@@ -132,9 +132,16 @@ test "single-item pointer to array indexing and slicing" {
132}132}
133133
134fn testSingleItemPtrArrayIndexSlice() void {134fn testSingleItemPtrArrayIndexSlice() void {
135 var array = "aaaa";135 {
136 doSomeMangling(&array);136 var array: [4]u8 = "aaaa".*;
137 expect(mem.eql(u8, "azya", array));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 }
138}145}
139146
140fn doSomeMangling(array: *[4]u8) void {147fn doSomeMangling(array: *[4]u8) void {
...@@ -294,9 +301,16 @@ test "read/write through global variable array of struct fields initialized via...@@ -294,9 +301,16 @@ test "read/write through global variable array of struct fields initialized via
294}301}
295302
296test "implicit cast zero sized array ptr to slice" {303test "implicit cast zero sized array ptr to slice" {
297 var b = "";304 {
298 const c: []const u8 = &b;305 var b = "".*;
299 expect(c.len == 0);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 }
300}314}
301315
302test "anonymous list literal syntax" {316test "anonymous list literal syntax" {
...@@ -333,3 +347,16 @@ test "anonymous literal in array" {...@@ -333,3 +347,16 @@ test "anonymous literal in array" {
333 S.doTheTest();347 S.doTheTest();
334 comptime S.doTheTest();348 comptime S.doTheTest();
335}349}
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" {...@@ -8,8 +8,16 @@ test "comptime code should not modify constant data" {
8}8}
99
10fn testCastPtrOfArrayToSliceAndPtr() void {10fn testCastPtrOfArrayToSliceAndPtr() void {
11 var array = "aoeu";11 {
12 const x: [*]u8 = &array;12 var array = "aoeu".*;
13 x[0] += 1;13 const x: [*]u8 = &array;
14 expect(mem.eql(u8, array[0..], "boeu"));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 }
15}23}
test/stage1/behavior/cast.zig+83-27
...@@ -179,18 +179,24 @@ fn gimmeErrOrSlice() anyerror![]u8 {...@@ -179,18 +179,24 @@ fn gimmeErrOrSlice() anyerror![]u8 {
179}179}
180180
181test "peer type resolution: [0]u8, []const u8, and anyerror![]u8" {181test "peer type resolution: [0]u8, []const u8, and anyerror![]u8" {
182 {182 const S = struct {
183 var data = "hi";183 fn doTheTest() anyerror!void {
184 const slice = data[0..];184 {
185 expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);185 var data = "hi".*;
186 expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);186 const slice = data[0..];
187 }187 expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
188 comptime {188 expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
189 var data = "hi";189 }
190 const slice = data[0..];190 {
191 expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);191 var data: [2]u8 = "hi".*;
192 expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);192 const slice = data[0..];
193 }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();
194}200}
195fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {201fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {
196 if (a) {202 if (a) {
...@@ -217,11 +223,20 @@ test "implicit cast from &const [N]T to []const T" {...@@ -217,11 +223,20 @@ test "implicit cast from &const [N]T to []const T" {
217}223}
218224
219fn testCastConstArrayRefToConstSlice() void {225fn testCastConstArrayRefToConstSlice() void {
220 const blah = "aoeu";226 {
221 const const_array_ref = &blah;227 const blah = "aoeu".*;
222 expect(@typeOf(const_array_ref) == *const [4]u8);228 const const_array_ref = &blah;
223 const slice: []const u8 = const_array_ref;229 expect(@typeOf(const_array_ref) == *const [4]null u8);
224 expect(mem.eql(u8, slice, "aoeu"));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 }
225}240}
226241
227test "peer type resolution: error and [N]T" {242test "peer type resolution: error and [N]T" {
...@@ -310,17 +325,28 @@ test "single-item pointer of array to slice and to unknown length pointer" {...@@ -310,17 +325,28 @@ test "single-item pointer of array to slice and to unknown length pointer" {
310}325}
311326
312fn testCastPtrOfArrayToSliceAndPtr() void {327fn testCastPtrOfArrayToSliceAndPtr() void {
313 var array = "aoeu";328 {
314 const x: [*]u8 = &array;329 var array = "aoeu".*;
315 x[0] += 1;330 const x: [*]u8 = &array;
316 expect(mem.eql(u8, array[0..], "boeu"));331 x[0] += 1;
317 const y: []u8 = &array;332 expect(mem.eql(u8, array[0..], "boeu"));
318 y[0] += 1;333 const y: []u8 = &array;
319 expect(mem.eql(u8, array[0..], "coeu"));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 }
320}346}
321347
322test "cast *[1][*]const u8 to [*]const ?[*]const u8" {348test "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"};
324 const x: [*]const ?[*]const u8 = &window_name;350 const x: [*]const ?[*]const u8 = &window_name;
325 expect(mem.eql(u8, std.mem.toSliceConst(u8, x[0].?), "window name"));351 expect(mem.eql(u8, std.mem.toSliceConst(u8, x[0].?), "window name"));
326}352}
...@@ -545,7 +571,7 @@ test "implicit cast *[0]T to E![]const u8" {...@@ -545,7 +571,7 @@ test "implicit cast *[0]T to E![]const u8" {
545}571}
546572
547test "peer cast *[0]T to E![]const T" {573test "peer cast *[0]T to E![]const T" {
548 var buffer: [5]u8 = "abcde";574 var buffer: [5]u8 = "abcde".*;
549 var buf: anyerror![]const u8 = buffer[0..];575 var buf: anyerror![]const u8 = buffer[0..];
550 var b = false;576 var b = false;
551 var y = if (b) &[0]u8{} else buf;577 var y = if (b) &[0]u8{} else buf;
...@@ -553,7 +579,7 @@ test "peer cast *[0]T to E![]const T" {...@@ -553,7 +579,7 @@ test "peer cast *[0]T to E![]const T" {
553}579}
554580
555test "peer cast *[0]T to []const T" {581test "peer cast *[0]T to []const T" {
556 var buffer: [5]u8 = "abcde";582 var buffer: [5]u8 = "abcde".*;
557 var buf: []const u8 = buffer[0..];583 var buf: []const u8 = buffer[0..];
558 var b = false;584 var b = false;
559 var y = if (b) &[0]u8{} else buf;585 var y = if (b) &[0]u8{} else buf;
...@@ -565,3 +591,33 @@ test "cast from array reference to fn" {...@@ -565,3 +591,33 @@ test "cast from array reference to fn" {
565 const f = @ptrCast(extern fn () void, &global_array);591 const f = @ptrCast(extern fn () void, &global_array);
566 expect(@ptrToInt(f) == @ptrToInt(&global_array));592 expect(@ptrToInt(f) == @ptrToInt(&global_array));
567}593}
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;...@@ -6,12 +6,11 @@ var argv: [*]const [*]const u8 = undefined;
66
7test "const slice child" {7test "const slice child" {
8 const strs = [_][*]const u8{8 const strs = [_][*]const u8{
9 c"one",9 "one",
10 c"two",10 "two",
11 c"three",11 "three",
12 };12 };
13 // TODO this should implicitly cast13 argv = &strs;
14 argv = @ptrCast([*]const [*]const u8, &strs);
15 bar(strs.len);14 bar(strs.len);
16}15}
1716
test/stage1/behavior/eval.zig+1-1
...@@ -736,7 +736,7 @@ test "comptime pointer cast array and then slice" {...@@ -736,7 +736,7 @@ test "comptime pointer cast array and then slice" {
736736
737test "slice bounds in comptime concatenation" {737test "slice bounds in comptime concatenation" {
738 const bs = comptime blk: {738 const bs = comptime blk: {
739 const b = c"........1........";739 const b = "........1........";
740 break :blk b[8..9];740 break :blk b[8..9];
741 };741 };
742 const str = "" ++ bs;742 const str = "" ++ bs;
test/stage1/behavior/misc.zig+10-7
...@@ -204,11 +204,11 @@ test "multiline string" {...@@ -204,11 +204,11 @@ test "multiline string" {
204204
205test "multiline C string" {205test "multiline C string" {
206 const s1 =206 const s1 =
207 c\\one207 \\one
208 c\\two)208 \\two)
209 c\\three209 \\three
210 ;210 ;
211 const s2 = c"one\ntwo)\nthree";211 const s2 = "one\ntwo)\nthree";
212 expect(std.cstr.cmp(s1, s2) == 0);212 expect(std.cstr.cmp(s1, s2) == 0);
213}213}
214214
...@@ -358,9 +358,12 @@ fn ptrEql(a: *const []const u8, b: *const []const u8) bool {...@@ -358,9 +358,12 @@ fn ptrEql(a: *const []const u8, b: *const []const u8) bool {
358 return a == b;358 return a == b;
359}359}
360360
361test "C string concatenation" {361test "string concatenation" {
362 const a = c"OK" ++ c" IT " ++ c"WORKED";362 const a = "OK" ++ " IT " ++ "WORKED";
363 const b = c"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
365 const len = mem.len(u8, b);368 const len = mem.len(u8, b);
366 const len_with_null = len + 1;369 const len_with_null = len + 1;
test/stage1/behavior/pointers.zig+1-1
...@@ -15,7 +15,7 @@ fn testDerefPtr() void {...@@ -15,7 +15,7 @@ fn testDerefPtr() void {
15}15}
1616
17test "pointer arithmetic" {17test "pointer arithmetic" {
18 var ptr = c"abcd";18 var ptr: [*]const u8 = "abcd";
1919
20 expect(ptr[0] == 'a');20 expect(ptr[0] == 'a');
21 ptr += 1;21 ptr += 1;
test/stage1/behavior/ptrcast.zig+1-1
...@@ -60,7 +60,7 @@ test "comptime ptrcast keeps larger alignment" {...@@ -60,7 +60,7 @@ test "comptime ptrcast keeps larger alignment" {
60}60}
6161
62test "implicit optional pointer to optional c_void pointer" {62test "implicit optional pointer to optional c_void pointer" {
63 var buf: [4]u8 = "aoeu";63 var buf: [4]u8 = "aoeu".*;
64 var x: ?[*]u8 = &buf;64 var x: ?[*]u8 = &buf;
65 var y: ?*c_void = x;65 var y: ?*c_void = x;
66 var z = @ptrCast(*[4]u8, y);66 var z = @ptrCast(*[4]u8, y);
test/stage1/behavior/slice.zig+1-1
...@@ -36,7 +36,7 @@ fn assertLenIsZero(msg: []const u8) void {...@@ -36,7 +36,7 @@ fn assertLenIsZero(msg: []const u8) void {
36}36}
3737
38test "C pointer" {38test "C pointer" {
39 var buf: [*c]const u8 = c"kjdhfkjdhfdkjhfkfjhdfkjdhfkdjhfdkjhf";39 var buf: [*c]const u8 = "kjdhfkjdhfdkjhfkfjhdfkjdhfkdjhfdkjhf";
40 var len: u32 = 10;40 var len: u32 = 10;
41 var slice = buf[0..len];41 var slice = buf[0..len];
42 expectEqualSlices(u8, "kjdhfkjdhf", slice);42 expectEqualSlices(u8, "kjdhfkjdhf", slice);
test/stage1/behavior/struct.zig+1-1
...@@ -493,7 +493,7 @@ test "non-byte-aligned array inside packed struct" {...@@ -493,7 +493,7 @@ test "non-byte-aligned array inside packed struct" {
493 fn doTheTest() void {493 fn doTheTest() void {
494 var foo = Foo{494 var foo = Foo{
495 .a = true,495 .a = true,
496 .b = "abcdefghijklmnopqurstu",496 .b = "abcdefghijklmnopqurstu".*,
497 };497 };
498 bar(foo.b);498 bar(foo.b);
499 }499 }
test/stage2/compare_output.zig+2-2
...@@ -6,7 +6,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -6,7 +6,7 @@ pub fn addCases(ctx: *TestContext) !void {
6 try ctx.testCompareOutputLibC(6 try ctx.testCompareOutputLibC(
7 \\extern fn puts([*]const u8) void;7 \\extern fn puts([*]const u8) void;
8 \\export fn main() c_int {8 \\export fn main() c_int {
9 \\ puts(c"Hello, world!");9 \\ puts("Hello, world!");
10 \\ return 0;10 \\ return 0;
11 \\}11 \\}
12 , "Hello, world!" ++ std.cstr.line_sep);12 , "Hello, world!" ++ std.cstr.line_sep);
...@@ -15,7 +15,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -15,7 +15,7 @@ pub fn addCases(ctx: *TestContext) !void {
15 try ctx.testCompareOutputLibC(15 try ctx.testCompareOutputLibC(
16 \\extern fn puts(s: [*]const u8) void;16 \\extern fn puts(s: [*]const u8) void;
17 \\export fn main() c_int {17 \\export fn main() c_int {
18 \\ return foo(c"OK");18 \\ return foo("OK");
19 \\}19 \\}
20 \\fn foo(s: [*]const u8) c_int {20 \\fn foo(s: [*]const u8) c_int {
21 \\ puts(s);21 \\ puts(s);
test/standalone/hello_world/hello_libc.zig+1-1
...@@ -5,7 +5,7 @@ const c = @cImport({...@@ -5,7 +5,7 @@ const c = @cImport({
5 @cInclude("string.h");5 @cInclude("string.h");
6});6});
77
8const msg = c"Hello, world!\n";8const msg = "Hello, world!\n";
99
10export fn main(argc: c_int, argv: **u8) c_int {10export fn main(argc: c_int, argv: **u8) c_int {
11 if (c.printf(msg) != @intCast(c_int, c.strlen(msg))) return -1;11 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 {...@@ -47,7 +47,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
47 \\pub fn foo() void {47 \\pub fn foo() void {
48 \\ var a: c_int = undefined;48 \\ var a: c_int = undefined;
49 \\ _ = 1;49 \\ _ = 1;
50 \\ _ = c"hey";50 \\ _ = "hey";
51 \\ _ = (1 + 1);51 \\ _ = (1 + 1);
52 \\ _ = (1 - 1);52 \\ _ = (1 - 1);
53 \\ a = 1;53 \\ a = 1;
...@@ -213,9 +213,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -213,9 +213,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
213 \\}213 \\}
214 ,214 ,
215 \\pub fn foo() void {215 \\pub fn foo() void {
216 \\ _ = c"foo";216 \\ _ = "foo";
217 \\ _ = c"foo";217 \\ _ = "foo";
218 \\ _ = c"void foo(void)";218 \\ _ = "void foo(void)";
219 \\}219 \\}
220 );220 );
221221
...@@ -232,7 +232,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -232,7 +232,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
232 \\pub fn foo() void {232 \\pub fn foo() void {
233 \\ var a: c_int = undefined;233 \\ var a: c_int = undefined;
234 \\ _ = 1;234 \\ _ = 1;
235 \\ _ = c"hey";235 \\ _ = "hey";
236 \\ _ = (1 + 1);236 \\ _ = (1 + 1);
237 \\ _ = (1 - 1);237 \\ _ = (1 - 1);
238 \\ a = 1;238 \\ a = 1;
...@@ -543,7 +543,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -543,7 +543,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
543 cases.add("#define string",543 cases.add("#define string",
544 \\#define foo "a string"544 \\#define foo "a string"
545 ,545 ,
546 \\pub const foo = c"a string";546 \\pub const foo = "a string";
547 );547 );
548548
549 cases.add("__cdecl doesn't mess up function pointers",549 cases.add("__cdecl doesn't mess up function pointers",
...@@ -617,9 +617,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -617,9 +617,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
617 \\#define FOO2 "aoeu\x0007a derp"617 \\#define FOO2 "aoeu\x0007a derp"
618 \\#define FOO_CHAR '\xfF'618 \\#define FOO_CHAR '\xfF'
619 ,619 ,
620 \\pub const FOO = c"aoeu\xab derp";620 \\pub const FOO = "aoeu\xab derp";
621 ,621 ,
622 \\pub const FOO2 = c"aoeuz derp";622 \\pub const FOO2 = "aoeuz derp";
623 ,623 ,
624 \\pub const FOO_CHAR = 255;624 \\pub const FOO_CHAR = 255;
625 );625 );
...@@ -629,9 +629,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -629,9 +629,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
629 \\#define FOO2 "aoeu\0234 derp"629 \\#define FOO2 "aoeu\0234 derp"
630 \\#define FOO_CHAR '\077'630 \\#define FOO_CHAR '\077'
631 ,631 ,
632 \\pub const FOO = c"aoeu\x13 derp";632 \\pub const FOO = "aoeu\x13 derp";
633 ,633 ,
634 \\pub const FOO2 = c"aoeu\x134 derp";634 \\pub const FOO2 = "aoeu\x134 derp";
635 ,635 ,
636 \\pub const FOO_CHAR = 63;636 \\pub const FOO_CHAR = 63;
637 );637 );
...@@ -1351,7 +1351,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1351,7 +1351,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1351 \\}1351 \\}
1352 ,1352 ,
1353 \\pub fn foo() [*c]const u8 {1353 \\pub fn foo() [*c]const u8 {
1354 \\ return c"bar";1354 \\ return "bar";
1355 \\}1355 \\}
1356 );1356 );
13571357
...@@ -1523,7 +1523,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1523,7 +1523,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1523 cases.add("const ptr initializer",1523 cases.add("const ptr initializer",
1524 \\static const char *v0 = "0.0.0";1524 \\static const char *v0 = "0.0.0";
1525 ,1525 ,
1526 \\pub var v0: [*c]const u8 = c"0.0.0";1526 \\pub var v0: [*c]const u8 = "0.0.0";
1527 );1527 );
15281528
1529 cases.add("static incomplete array inside function",1529 cases.add("static incomplete array inside function",
...@@ -1532,7 +1532,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1532,7 +1532,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1532 \\}1532 \\}
1533 ,1533 ,
1534 \\pub fn foo() void {1534 \\pub fn foo() void {
1535 \\ const v2: [*c]const u8 = c"2.2.2";1535 \\ const v2: [*c]const u8 = "2.2.2";
1536 \\}1536 \\}
1537 );1537 );
15381538
...@@ -1809,7 +1809,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1809,7 +1809,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1809 \\ var i: u8 = @as(u8, '\x0b');1809 \\ var i: u8 = @as(u8, '\x0b');
1810 \\ var j: u8 = @as(u8, '\x00');1810 \\ var j: u8 = @as(u8, '\x00');
1811 \\ var k: u8 = @as(u8, '\"');1811 \\ 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\"";
1813 \\}1813 \\}
1814 \\1814 \\
1815 );1815 );