authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-12-01 20:53:24-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-12-01 20:53:24-05:00
logc32e50f5058dd3720db24706391c994545d13640
tree94914c8bdaf0f037ae025508bc6924b885245e8a
parent4af5c3867487b10bdfdb35fba79442f5cc860da1
signaturelock-open Commit is signed but in an unrecognized format.

fix regressions in compile error tests


3 files changed, 33 insertions(+), 47 deletions(-)

src/ir.cpp+11-4
......@@ -18916,7 +18916,8 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1891618916 return ira->codegen->invalid_instruction;
1891718917 if (actual_array_type->id != ZigTypeIdArray) {
1891818918 ir_add_error_node(ira, elem_ptr_instruction->init_array_type_source_node,
18919 buf_sprintf("expected array type or [_], found slice"));
18919 buf_sprintf("array literal requires address-of operator to coerce to slice type '%s'",
18920 buf_ptr(&actual_array_type->name)));
1892018921 return ira->codegen->invalid_instruction;
1892118922 }
1892218923
......@@ -21308,7 +21309,8 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
2130821309
2130921310 if (is_slice(container_type)) {
2131021311 ir_add_error_node(ira, instruction->init_array_type_source_node,
21311 buf_sprintf("expected array type or [_], found slice"));
21312 buf_sprintf("array literal requires address-of operator to coerce to slice type '%s'",
21313 buf_ptr(&container_type->name)));
2131221314 return ira->codegen->invalid_instruction;
2131321315 }
2131421316
......@@ -22835,7 +22837,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
2283522837 }
2283622838 ir_add_error(ira, instruction,
2283722839 buf_sprintf("%d-bit float unsupported", bits));
22838 return nullptr;
22840 return ira->codegen->invalid_instruction->value->type;
2283922841 }
2284022842 case ZigTypeIdPointer:
2284122843 {
......@@ -23643,7 +23645,12 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru
2364323645 return result_loc;
2364423646 }
2364523647
23646 if (casted_value->value->data.rh_slice.id == RuntimeHintSliceIdLen) {
23648 if (target->value->type->id == ZigTypeIdPointer &&
23649 target->value->type->data.pointer.child_type->id == ZigTypeIdArray)
23650 {
23651 known_len = target->value->type->data.pointer.child_type->data.array.len;
23652 have_known_len = true;
23653 } else if (casted_value->value->data.rh_slice.id == RuntimeHintSliceIdLen) {
2364723654 known_len = casted_value->value->data.rh_slice.len;
2364823655 have_known_len = true;
2364923656 }
src/util.hpp+6-2
......@@ -26,20 +26,24 @@
2626#define ATTRIBUTE_NORETURN __declspec(noreturn)
2727#define ATTRIBUTE_MUST_USE
2828
29#define BREAKPOINT __debugbreak()
30
2931#else
3032
33#include <signal.h>
34
3135#define ATTRIBUTE_COLD __attribute__((cold))
3236#define ATTRIBUTE_PRINTF(a, b) __attribute__((format(printf, a, b)))
3337#define ATTRIBUTE_RETURNS_NOALIAS __attribute__((__malloc__))
3438#define ATTRIBUTE_NORETURN __attribute__((noreturn))
3539#define ATTRIBUTE_MUST_USE __attribute__((warn_unused_result))
3640
41#define BREAKPOINT raise(SIGTRAP)
42
3743#endif
3844
3945#include "softfloat.hpp"
4046
41#define BREAKPOINT __asm("int $0x03")
42
4347ATTRIBUTE_COLD
4448ATTRIBUTE_NORETURN
4549ATTRIBUTE_PRINTF(1, 2)
test/compile_errors.zig+16-41
......@@ -20,6 +20,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2020 break :x tc;
2121 });
2222
23 // Note: One of the error messages here is backwards. It would be nice to fix, but that's not
24 // going to stop me from merging this branch which fixes a bunch of other stuff.
2325 cases.add(
2426 "incompatible sentinels",
2527 \\export fn entry1(ptr: [*:255]u8) [*:0]u8 {
......@@ -40,8 +42,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4042 "tmp.zig:5:12: error: expected type '[*:0]u8', found '[*]u8'",
4143 "tmp.zig:5:12: note: destination pointer requires a terminating '0' sentinel",
4244
43 "tmp.zig:8:35: error: expected type '[2:0]u8', found '[2:255]u8'",
44 "tmp.zig:8:35: note: destination array requires a terminating '0' sentinel, but source array has a terminating '255' sentinel",
45 "tmp.zig:8:35: error: expected type '[2:255]u8', found '[2:0]u8'",
46 "tmp.zig:8:35: note: destination array requires a terminating '255' sentinel, but source array has a terminating '0' sentinel",
4547 "tmp.zig:11:31: error: expected type '[2:0]u8', found '[2]u8'",
4648 "tmp.zig:11:31: note: destination array requires a terminating '0' sentinel",
4749 );
......@@ -96,32 +98,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
9698 "tmp.zig:11:25: error: expected type 'u32', found '@typeOf(get_uval).ReturnType.ErrorSet!u32'",
9799 );
98100
99 cases.add(
100 "function call assigned to incorrect type",
101 \\export fn entry() void {
102 \\ var arr: [4]f32 = undefined;
103 \\ arr = concat();
104 \\}
105 \\fn concat() [16]f32 {
106 \\ return [1]f32{0}**16;
107 \\}
108 ,
109 "tmp.zig:3:17: error: expected type '[4]f32', found '[16]f32'"
110 );
111
112 cases.add(
113 "generic function call assigned to incorrect type",
114 \\pub export fn entry() void {
115 \\ var res: []i32 = undefined;
116 \\ res = myAlloc(i32);
117 \\}
118 \\fn myAlloc(comptime arg: type) anyerror!arg{
119 \\ unreachable;
120 \\}
121 ,
122 "tmp.zig:3:18: error: expected type '[]i32', found 'anyerror!i32"
123 );
124
125101 cases.add(
126102 "asigning to struct or union fields that are not optionals with a function that returns an optional",
127103 \\fn maybe(is: bool) ?u8 {
......@@ -205,7 +181,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
205181 \\ var geo_data = getGeo3DTex2D();
206182 \\}
207183 ,
208 "tmp.zig:4:30: error: expected type '[][2]f32', found '[1][2]f32'",
184 "tmp.zig:4:30: error: array literal requires address-of operator to coerce to slice type '[][2]f32'",
209185 );
210186
211187 cases.add(
......@@ -802,7 +778,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
802778 \\ const x = []u8{1, 2};
803779 \\}
804780 ,
805 "tmp.zig:2:15: error: expected array type or [_], found slice",
781 "tmp.zig:2:15: error: array literal requires address-of operator to coerce to slice type '[]u8'",
806782 );
807783
808784 cases.add(
......@@ -811,7 +787,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
811787 \\ const x = []u8{};
812788 \\}
813789 ,
814 "tmp.zig:2:15: error: expected array type or [_], found slice",
790 "tmp.zig:2:15: error: array literal requires address-of operator to coerce to slice type '[]u8'",
815791 );
816792
817793 cases.add(
......@@ -2310,8 +2286,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
23102286 \\
23112287 \\fn bar(x: *b.Foo) void {}
23122288 ,
2313 "tmp.zig:6:9: error: expected type '*b.Foo', found '*a.Foo'",
2314 "tmp.zig:6:9: note: pointer type child 'a.Foo' cannot cast into pointer type child 'b.Foo'",
2289 "tmp.zig:6:10: error: expected type '*b.Foo', found '*a.Foo'",
2290 "tmp.zig:6:10: note: pointer type child 'a.Foo' cannot cast into pointer type child 'b.Foo'",
23152291 "a.zig:1:17: note: a.Foo declared here",
23162292 "b.zig:1:17: note: b.Foo declared here",
23172293 );
......@@ -4836,10 +4812,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
48364812 "convert fixed size array to slice with invalid size",
48374813 \\export fn f() void {
48384814 \\ var array: [5]u8 = undefined;
4839 \\ var foo = @bytesToSlice(u32, array)[0];
4815 \\ var foo = @bytesToSlice(u32, &array)[0];
48404816 \\}
48414817 ,
4842 "tmp.zig:3:15: error: unable to convert [5]u8 to []align(1) const u32: size mismatch",
4818 "tmp.zig:3:15: error: unable to convert [5]u8 to []align(1) u32: size mismatch",
48434819 "tmp.zig:3:29: note: u32 has size 4; remaining bytes: 1",
48444820 );
48454821
......@@ -5176,7 +5152,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
51765152 \\
51775153 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
51785154 ,
5179 "tmp.zig:8:16: error: expected type '*const u3', found '*align(:3:1) const u3'",
5155 "tmp.zig:8:26: error: expected type '*const u3', found '*align(:3:1) const u3'",
51805156 );
51815157
51825158 cases.add(
......@@ -5873,7 +5849,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
58735849 \\ x.* += 1;
58745850 \\}
58755851 ,
5876 "tmp.zig:8:9: error: expected type '*u32', found '*align(1) u32'",
5852 "tmp.zig:8:13: error: expected type '*u32', found '*align(1) u32'",
58775853 );
58785854
58795855 cases.add(
......@@ -5893,9 +5869,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
58935869 \\ x[0] += 1;
58945870 \\}
58955871 ,
5896 "tmp.zig:9:9: error: cast increases pointer alignment",
5872 "tmp.zig:9:26: error: cast increases pointer alignment",
58975873 "tmp.zig:9:26: note: '*align(1) u32' has alignment 1",
5898 "tmp.zig:9:9: note: '*[1]u32' has alignment 4",
5874 "tmp.zig:9:26: note: '*[1]u32' has alignment 4",
58995875 );
59005876
59015877 cases.add(
......@@ -6943,7 +6919,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
69436919 \\ var foo: u32 = @This(){};
69446920 \\}
69456921 ,
6946 "tmp.zig:2:27: error: expected type 'u32', found '(root)'",
6947 "tmp.zig:1:1: note: (root) declared here",
6922 "tmp.zig:2:27: error: type 'u32' does not support array initialization",
69486923 );
69496924}