From 13b917148e97560760eb13cd0e4a0b7365739f64 Mon Sep 17 00:00:00 2001 From: Robin Voetter Date: Wed, 1 Sep 2021 17:33:45 +0200 Subject: Address Spaces: basic system to check for validity. Validity checks are also based on context; whether the entity being validated is a mutable/constant value, a pointer (that is ascripted with an addrspace attribute) or a function with an addrspace attribute. Error messages are relatively simple for now. --- src/Module.zig | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/Module.zig') diff --git a/src/Module.zig b/src/Module.zig index 1f9b5abcb9..2313480aeb 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -3213,11 +3213,18 @@ fn semaDecl(mod: *Module, decl: *Decl) !bool { break :blk (try sema.resolveInstConst(&block_scope, src, linksection_ref)).val; }; const address_space = blk: { - const addrspace_ref = decl.zirAddrspaceRef(); - if (addrspace_ref == .none) break :blk .generic; - const addrspace_tv = try sema.resolveInstConst(&block_scope, src, addrspace_ref); - break :blk addrspace_tv.val.toEnum(std.builtin.AddressSpace); + const addrspace_ctx: Sema.AddressSpaceContext = switch (decl_tv.val.tag()) { + .function, .extern_fn => .function, + .variable => .variable, + else => .constant, + }; + + break :blk switch (decl.zirAddrspaceRef()) { + .none => .generic, + else => |addrspace_ref| try sema.analyzeAddrspace(&block_scope, src, addrspace_ref, addrspace_ctx), + }; }; + // Note this resolves the type of the Decl, not the value; if this Decl // is a struct, for example, this resolves `type` (which needs no resolution), // not the struct itself. -- cgit v1.2.3