authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-07-06 23:17:33+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-07-07 10:50:06+03:00
log5007f727e5a2631ce55e9b44f93e69a9cb82cde8
tree1588f424b99bb71efedcc0c9cb7c467d32150167
parentb5ac2b4330b84799060609ce0f22eda266ad171b

stage2: move C pointer allowzero error to AstGen


2 files changed, 7 insertions(+), 5 deletions(-)

src/AstGen.zig+4
...@@ -3104,6 +3104,10 @@ fn ptrType(...@@ -3104,6 +3104,10 @@ fn ptrType(
3104 node: Ast.Node.Index,3104 node: Ast.Node.Index,
3105 ptr_info: Ast.full.PtrType,3105 ptr_info: Ast.full.PtrType,
3106) InnerError!Zir.Inst.Ref {3106) InnerError!Zir.Inst.Ref {
3107 if (ptr_info.size == .C and ptr_info.allowzero_token != null) {
3108 return gz.astgen.failTok(ptr_info.allowzero_token.?, "C pointers always allow address zero", .{});
3109 }
3110
3107 const elem_type = try typeExpr(gz, scope, ptr_info.ast.child_type);3111 const elem_type = try typeExpr(gz, scope, ptr_info.ast.child_type);
31083112
3109 const simple = ptr_info.ast.align_node == 0 and3113 const simple = ptr_info.ast.align_node == 0 and
src/Sema.zig+3-5
...@@ -13713,7 +13713,7 @@ fn zirPtrTypeSimple(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr...@@ -13713,7 +13713,7 @@ fn zirPtrTypeSimple(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
13713 .@"volatile" = inst_data.is_volatile,13713 .@"volatile" = inst_data.is_volatile,
13714 .size = inst_data.size,13714 .size = inst_data.size,
13715 });13715 });
13716 try sema.validatePtrTy(block, elem_ty_src, ty, inst_data.is_allowzero);13716 try sema.validatePtrTy(block, elem_ty_src, ty);
13717 return sema.addType(ty);13717 return sema.addType(ty);
13718}13718}
1371913719
...@@ -13799,11 +13799,11 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -13799,11 +13799,11 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
13799 .@"volatile" = inst_data.flags.is_volatile,13799 .@"volatile" = inst_data.flags.is_volatile,
13800 .size = inst_data.size,13800 .size = inst_data.size,
13801 });13801 });
13802 try sema.validatePtrTy(block, elem_ty_src, ty, inst_data.flags.is_allowzero);13802 try sema.validatePtrTy(block, elem_ty_src, ty);
13803 return sema.addType(ty);13803 return sema.addType(ty);
13804}13804}
1380513805
13806fn validatePtrTy(sema: *Sema, block: *Block, elem_src: LazySrcLoc, ty: Type, explicit_allowzer: bool) CompileError!void {13806fn validatePtrTy(sema: *Sema, block: *Block, elem_src: LazySrcLoc, ty: Type) CompileError!void {
13807 const ptr_info = ty.ptrInfo().data;13807 const ptr_info = ty.ptrInfo().data;
13808 const pointee_tag = ptr_info.pointee_type.zigTypeTag();13808 const pointee_tag = ptr_info.pointee_type.zigTypeTag();
13809 if (pointee_tag == .NoReturn) {13809 if (pointee_tag == .NoReturn) {
...@@ -13814,8 +13814,6 @@ fn validatePtrTy(sema: *Sema, block: *Block, elem_src: LazySrcLoc, ty: Type, exp...@@ -13814,8 +13814,6 @@ fn validatePtrTy(sema: *Sema, block: *Block, elem_src: LazySrcLoc, ty: Type, exp
13814 // TODO check extern type13814 // TODO check extern type
13815 if (pointee_tag == .Opaque) {13815 if (pointee_tag == .Opaque) {
13816 return sema.fail(block, elem_src, "C pointers cannot point to opaque types", .{});13816 return sema.fail(block, elem_src, "C pointers cannot point to opaque types", .{});
13817 } else if (explicit_allowzer) {
13818 return sema.fail(block, elem_src, "C pointers always allow address zero", .{});
13819 }13817 }
13820 }13818 }
13821}13819}