| author | |
| committer | |
| log | 7a51e0befe12c9d17e39f736027a205b1f19bdc6 |
| tree | bfcb19cbe80a98d9a15b461d32930eced8582586 |
| parent | 1c4c68e6ba058f0c320f222275335245305974a0 |
Closes #117693 files changed, 29 insertions(+), 3 deletions(-)
src/Sema.zig+6-3| ... | @@ -23426,8 +23426,11 @@ const InMemoryCoercionResult = union(enum) { | ... | @@ -23426,8 +23426,11 @@ const InMemoryCoercionResult = union(enum) { |
| 23426 | var index: u6 = 0; | 23426 | var index: u6 = 0; |
| 23427 | var actual_noalias = false; | 23427 | var actual_noalias = false; |
| 23428 | while (true) : (index += 1) { | 23428 | while (true) : (index += 1) { |
| 23429 | if (param.actual << index != param.wanted << index) { | 23429 | const actual = @truncate(u1, param.actual >> index); |
| 23430 | actual_noalias = (param.actual << index) == (1 << 31); | 23430 | const wanted = @truncate(u1, param.wanted >> index); |
| 23431 | if (actual != wanted) { | ||
| 23432 | actual_noalias = actual == 1; | ||
| 23433 | break; | ||
| 23431 | } | 23434 | } |
| 23432 | } | 23435 | } |
| 23433 | if (!actual_noalias) { | 23436 | if (!actual_noalias) { |
| ... | @@ -23921,7 +23924,7 @@ fn coerceInMemoryAllowedFns( | ... | @@ -23921,7 +23924,7 @@ fn coerceInMemoryAllowedFns( |
| 23921 | 23924 | ||
| 23922 | if (dest_info.noalias_bits != src_info.noalias_bits) { | 23925 | if (dest_info.noalias_bits != src_info.noalias_bits) { |
| 23923 | return InMemoryCoercionResult{ .fn_param_noalias = .{ | 23926 | return InMemoryCoercionResult{ .fn_param_noalias = .{ |
| 23924 | .actual = dest_info.noalias_bits, | 23927 | .actual = src_info.noalias_bits, |
| 23925 | .wanted = dest_info.noalias_bits, | 23928 | .wanted = dest_info.noalias_bits, |
| 23926 | } }; | 23929 | } }; |
| 23927 | } | 23930 | } |
src/type.zig+3| ... | @@ -2042,6 +2042,9 @@ pub const Type = extern union { | ... | @@ -2042,6 +2042,9 @@ pub const Type = extern union { |
| 2042 | try writer.writeAll("fn("); | 2042 | try writer.writeAll("fn("); |
| 2043 | for (fn_info.param_types) |param_ty, i| { | 2043 | for (fn_info.param_types) |param_ty, i| { |
| 2044 | if (i != 0) try writer.writeAll(", "); | 2044 | if (i != 0) try writer.writeAll(", "); |
| 2045 | if (std.math.cast(u5, i)) |index| if (@truncate(u1, fn_info.noalias_bits >> index) != 0) { | ||
| 2046 | try writer.writeAll("noalias "); | ||
| 2047 | }; | ||
| 2045 | if (param_ty.tag() == .generic_poison) { | 2048 | if (param_ty.tag() == .generic_poison) { |
| 2046 | try writer.writeAll("anytype"); | 2049 | try writer.writeAll("anytype"); |
| 2047 | } else { | 2050 | } else { |
test/cases/compile_errors/noalias_param_coersion.zig created+20| ... | @@ -0,0 +1,20 @@ | ||
| 1 | pub export fn entry() void { | ||
| 2 | comptime var x: fn (noalias *i32, noalias *i32) void = undefined; | ||
| 3 | x = bar; | ||
| 4 | } | ||
| 5 | pub export fn entry1() void { | ||
| 6 | comptime var x: fn (*i32, *i32) void = undefined; | ||
| 7 | x = foo; | ||
| 8 | } | ||
| 9 | |||
| 10 | fn foo(noalias _: *i32, noalias _: *i32) void {} | ||
| 11 | fn bar(noalias _: *i32, _: *i32) void {} | ||
| 12 | |||
| 13 | // error | ||
| 14 | // backend=stage2 | ||
| 15 | // target=native | ||
| 16 | // | ||
| 17 | // :3:9: error: expected type 'fn(noalias *i32, noalias *i32) void', found 'fn(noalias *i32, *i32) void' | ||
| 18 | // :3:9: note: regular parameter 1 cannot cast into a noalias parameter | ||
| 19 | // :7:9: error: expected type 'fn(*i32, *i32) void', found 'fn(noalias *i32, noalias *i32) void' | ||
| 20 | // :7:9: note: noalias parameter 0 cannot cast into a regular parameter | ||