implement allowzero pointer attribute

closes #1953

only needed for freestanding targets.

also adds safety for `@intToPtr` when the address is zero.
This commit is contained in:
Andrew Kelley
2019-03-25 12:55:45 -04:00
parent 3306e43984
commit 5eaead6a56
18 changed files with 225 additions and 78 deletions

View File

@@ -2,6 +2,15 @@ const tests = @import("tests.zig");
const builtin = @import("builtin");
pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add(
"@ptrToInt 0 to non optional pointer",
\\export fn entry() void {
\\ var b = @intToPtr(*i32, 0);
\\}
,
"tmp.zig:2:13: error: pointer type '*i32' does not allow address zero",
);
cases.add(
"cast enum literal to enum but it doesn't match",
\\const Foo = enum {