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
signature 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...@@ -18916,7 +18916,8 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
18916 return ira->codegen->invalid_instruction;18916 return ira->codegen->invalid_instruction;
18917 if (actual_array_type->id != ZigTypeIdArray) {18917 if (actual_array_type->id != ZigTypeIdArray) {
18918 ir_add_error_node(ira, elem_ptr_instruction->init_array_type_source_node,18918 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)));
18920 return ira->codegen->invalid_instruction;18921 return ira->codegen->invalid_instruction;
18921 }18922 }
1892218923
...@@ -21308,7 +21309,8 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,...@@ -21308,7 +21309,8 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
2130821309
21309 if (is_slice(container_type)) {21310 if (is_slice(container_type)) {
21310 ir_add_error_node(ira, instruction->init_array_type_source_node,21311 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)));
21312 return ira->codegen->invalid_instruction;21314 return ira->codegen->invalid_instruction;
21313 }21315 }
2131421316
...@@ -22835,7 +22837,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi...@@ -22835,7 +22837,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
22835 }22837 }
22836 ir_add_error(ira, instruction,22838 ir_add_error(ira, instruction,
22837 buf_sprintf("%d-bit float unsupported", bits));22839 buf_sprintf("%d-bit float unsupported", bits));
22838 return nullptr;22840 return ira->codegen->invalid_instruction->value->type;
22839 }22841 }
22840 case ZigTypeIdPointer:22842 case ZigTypeIdPointer:
22841 {22843 {
...@@ -23643,7 +23645,12 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru...@@ -23643,7 +23645,12 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru
23643 return result_loc;23645 return result_loc;
23644 }23646 }
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) {
23647 known_len = casted_value->value->data.rh_slice.len;23654 known_len = casted_value->value->data.rh_slice.len;
23648 have_known_len = true;23655 have_known_len = true;
23649 }23656 }
src/util.hpp+6-2
...@@ -26,20 +26,24 @@...@@ -26,20 +26,24 @@
26#define ATTRIBUTE_NORETURN __declspec(noreturn)26#define ATTRIBUTE_NORETURN __declspec(noreturn)
27#define ATTRIBUTE_MUST_USE27#define ATTRIBUTE_MUST_USE
2828
29#define BREAKPOINT __debugbreak()
30
29#else31#else
3032
33#include <signal.h>
34
31#define ATTRIBUTE_COLD __attribute__((cold))35#define ATTRIBUTE_COLD __attribute__((cold))
32#define ATTRIBUTE_PRINTF(a, b) __attribute__((format(printf, a, b)))36#define ATTRIBUTE_PRINTF(a, b) __attribute__((format(printf, a, b)))
33#define ATTRIBUTE_RETURNS_NOALIAS __attribute__((__malloc__))37#define ATTRIBUTE_RETURNS_NOALIAS __attribute__((__malloc__))
34#define ATTRIBUTE_NORETURN __attribute__((noreturn))38#define ATTRIBUTE_NORETURN __attribute__((noreturn))
35#define ATTRIBUTE_MUST_USE __attribute__((warn_unused_result))39#define ATTRIBUTE_MUST_USE __attribute__((warn_unused_result))
3640
41#define BREAKPOINT raise(SIGTRAP)
42
37#endif43#endif
3844
39#include "softfloat.hpp"45#include "softfloat.hpp"
4046
41#define BREAKPOINT __asm("int $0x03")
42
43ATTRIBUTE_COLD47ATTRIBUTE_COLD
44ATTRIBUTE_NORETURN48ATTRIBUTE_NORETURN
45ATTRIBUTE_PRINTF(1, 2)49ATTRIBUTE_PRINTF(1, 2)
test/compile_errors.zig+16-41
...@@ -20,6 +20,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -20,6 +20,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
20 break :x tc;20 break :x tc;
21 });21 });
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.
23 cases.add(25 cases.add(
24 "incompatible sentinels",26 "incompatible sentinels",
25 \\export fn entry1(ptr: [*:255]u8) [*:0]u8 {27 \\export fn entry1(ptr: [*:255]u8) [*:0]u8 {
...@@ -40,8 +42,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -40,8 +42,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
40 "tmp.zig:5:12: error: expected type '[*:0]u8', found '[*]u8'",42 "tmp.zig:5:12: error: expected type '[*:0]u8', found '[*]u8'",
41 "tmp.zig:5:12: note: destination pointer requires a terminating '0' sentinel",43 "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'",45 "tmp.zig:8:35: error: expected type '[2:255]u8', found '[2:0]u8'",
44 "tmp.zig:8:35: note: destination array requires a terminating '0' sentinel, but source array has a terminating '255' sentinel",46 "tmp.zig:8:35: note: destination array requires a terminating '255' sentinel, but source array has a terminating '0' sentinel",
45 "tmp.zig:11:31: error: expected type '[2:0]u8', found '[2]u8'",47 "tmp.zig:11:31: error: expected type '[2:0]u8', found '[2]u8'",
46 "tmp.zig:11:31: note: destination array requires a terminating '0' sentinel",48 "tmp.zig:11:31: note: destination array requires a terminating '0' sentinel",
47 );49 );
...@@ -96,32 +98,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -96,32 +98,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
96 "tmp.zig:11:25: error: expected type 'u32', found '@typeOf(get_uval).ReturnType.ErrorSet!u32'",98 "tmp.zig:11:25: error: expected type 'u32', found '@typeOf(get_uval).ReturnType.ErrorSet!u32'",
97 );99 );
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
125 cases.add(101 cases.add(
126 "asigning to struct or union fields that are not optionals with a function that returns an optional",102 "asigning to struct or union fields that are not optionals with a function that returns an optional",
127 \\fn maybe(is: bool) ?u8 {103 \\fn maybe(is: bool) ?u8 {
...@@ -205,7 +181,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -205,7 +181,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
205 \\ var geo_data = getGeo3DTex2D();181 \\ var geo_data = getGeo3DTex2D();
206 \\}182 \\}
207 ,183 ,
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'",
209 );185 );
210186
211 cases.add(187 cases.add(
...@@ -802,7 +778,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -802,7 +778,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
802 \\ const x = []u8{1, 2};778 \\ const x = []u8{1, 2};
803 \\}779 \\}
804 ,780 ,
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'",
806 );782 );
807783
808 cases.add(784 cases.add(
...@@ -811,7 +787,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -811,7 +787,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
811 \\ const x = []u8{};787 \\ const x = []u8{};
812 \\}788 \\}
813 ,789 ,
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'",
815 );791 );
816792
817 cases.add(793 cases.add(
...@@ -2310,8 +2286,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2310,8 +2286,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2310 \\2286 \\
2311 \\fn bar(x: *b.Foo) void {}2287 \\fn bar(x: *b.Foo) void {}
2312 ,2288 ,
2313 "tmp.zig:6:9: error: expected type '*b.Foo', found '*a.Foo'",2289 "tmp.zig:6:10: 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'",2290 "tmp.zig:6:10: note: pointer type child 'a.Foo' cannot cast into pointer type child 'b.Foo'",
2315 "a.zig:1:17: note: a.Foo declared here",2291 "a.zig:1:17: note: a.Foo declared here",
2316 "b.zig:1:17: note: b.Foo declared here",2292 "b.zig:1:17: note: b.Foo declared here",
2317 );2293 );
...@@ -4836,10 +4812,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4836,10 +4812,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4836 "convert fixed size array to slice with invalid size",4812 "convert fixed size array to slice with invalid size",
4837 \\export fn f() void {4813 \\export fn f() void {
4838 \\ var array: [5]u8 = undefined;4814 \\ var array: [5]u8 = undefined;
4839 \\ var foo = @bytesToSlice(u32, array)[0];4815 \\ var foo = @bytesToSlice(u32, &array)[0];
4840 \\}4816 \\}
4841 ,4817 ,
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",
4843 "tmp.zig:3:29: note: u32 has size 4; remaining bytes: 1",4819 "tmp.zig:3:29: note: u32 has size 4; remaining bytes: 1",
4844 );4820 );
48454821
...@@ -5176,7 +5152,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -5176,7 +5152,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
5176 \\5152 \\
5177 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }5153 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
5178 ,5154 ,
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'",
5180 );5156 );
51815157
5182 cases.add(5158 cases.add(
...@@ -5873,7 +5849,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -5873,7 +5849,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
5873 \\ x.* += 1;5849 \\ x.* += 1;
5874 \\}5850 \\}
5875 ,5851 ,
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'",
5877 );5853 );
58785854
5879 cases.add(5855 cases.add(
...@@ -5893,9 +5869,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -5893,9 +5869,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
5893 \\ x[0] += 1;5869 \\ x[0] += 1;
5894 \\}5870 \\}
5895 ,5871 ,
5896 "tmp.zig:9:9: error: cast increases pointer alignment",5872 "tmp.zig:9:26: error: cast increases pointer alignment",
5897 "tmp.zig:9:26: note: '*align(1) u32' has alignment 1",5873 "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",
5899 );5875 );
59005876
5901 cases.add(5877 cases.add(
...@@ -6943,7 +6919,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -6943,7 +6919,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
6943 \\ var foo: u32 = @This(){};6919 \\ var foo: u32 = @This(){};
6944 \\}6920 \\}
6945 ,6921 ,
6946 "tmp.zig:2:27: error: expected type 'u32', found '(root)'",6922 "tmp.zig:2:27: error: type 'u32' does not support array initialization",
6947 "tmp.zig:1:1: note: (root) declared here",
6948 );6923 );
6949}6924}