aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2022-07-06 23:17:33 +0300
committerVeikka Tuominen <git@vexu.eu>2022-07-07 10:50:06 +0300
commit5007f727e5a2631ce55e9b44f93e69a9cb82cde8 (patch)
tree1588f424b99bb71efedcc0c9cb7c467d32150167 /src
parentb5ac2b4330b84799060609ce0f22eda266ad171b (diff)
downloadzig-5007f727e5a2631ce55e9b44f93e69a9cb82cde8.tar.gz
zig-5007f727e5a2631ce55e9b44f93e69a9cb82cde8.zip
stage2: move C pointer allowzero error to AstGen
Diffstat (limited to 'src')
-rw-r--r--src/AstGen.zig4
-rw-r--r--src/Sema.zig8
2 files changed, 7 insertions, 5 deletions
diff --git a/src/AstGen.zig b/src/AstGen.zig
index a92723b068..5d6c53768f 100644
--- a/src/AstGen.zig
+++ b/src/AstGen.zig
@@ -3104,6 +3104,10 @@ fn ptrType(
node: Ast.Node.Index,
ptr_info: Ast.full.PtrType,
) InnerError!Zir.Inst.Ref {
+ if (ptr_info.size == .C and ptr_info.allowzero_token != null) {
+ return gz.astgen.failTok(ptr_info.allowzero_token.?, "C pointers always allow address zero", .{});
+ }
+
const elem_type = try typeExpr(gz, scope, ptr_info.ast.child_type);
const simple = ptr_info.ast.align_node == 0 and
diff --git a/src/Sema.zig b/src/Sema.zig
index fcc403152e..054f645230 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -13713,7 +13713,7 @@ fn zirPtrTypeSimple(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
.@"volatile" = inst_data.is_volatile,
.size = inst_data.size,
});
- try sema.validatePtrTy(block, elem_ty_src, ty, inst_data.is_allowzero);
+ try sema.validatePtrTy(block, elem_ty_src, ty);
return sema.addType(ty);
}
@@ -13799,11 +13799,11 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
.@"volatile" = inst_data.flags.is_volatile,
.size = inst_data.size,
});
- try sema.validatePtrTy(block, elem_ty_src, ty, inst_data.flags.is_allowzero);
+ try sema.validatePtrTy(block, elem_ty_src, ty);
return sema.addType(ty);
}
-fn validatePtrTy(sema: *Sema, block: *Block, elem_src: LazySrcLoc, ty: Type, explicit_allowzer: bool) CompileError!void {
+fn validatePtrTy(sema: *Sema, block: *Block, elem_src: LazySrcLoc, ty: Type) CompileError!void {
const ptr_info = ty.ptrInfo().data;
const pointee_tag = ptr_info.pointee_type.zigTypeTag();
if (pointee_tag == .NoReturn) {
@@ -13814,8 +13814,6 @@ fn validatePtrTy(sema: *Sema, block: *Block, elem_src: LazySrcLoc, ty: Type, exp
// TODO check extern type
if (pointee_tag == .Opaque) {
return sema.fail(block, elem_src, "C pointers cannot point to opaque types", .{});
- } else if (explicit_allowzer) {
- return sema.fail(block, elem_src, "C pointers always allow address zero", .{});
}
}
}