aboutsummaryrefslogtreecommitdiff
path: root/src/Module.zig
diff options
context:
space:
mode:
authorRobin Voetter <robin@voetter.nl>2021-09-01 17:33:45 +0200
committerRobin Voetter <robin@voetter.nl>2021-09-20 02:29:04 +0200
commit13b917148e97560760eb13cd0e4a0b7365739f64 (patch)
tree6c738f53f4bbcd131ac0c1d00364ed476fe21703 /src/Module.zig
parent90a945b38c44c673e230feb8a6b124f5c8f977a1 (diff)
downloadzig-13b917148e97560760eb13cd0e4a0b7365739f64.tar.gz
zig-13b917148e97560760eb13cd0e4a0b7365739f64.zip
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.
Diffstat (limited to 'src/Module.zig')
-rw-r--r--src/Module.zig15
1 files changed, 11 insertions, 4 deletions
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.