Address spaces: Forbid addrspace and linksection for local variables

This commit is contained in:
Robin Voetter 2021-09-02 14:49:24 +02:00
parent 805e1bffbd
commit cfbe9a6f61

View File

@ -2377,6 +2377,7 @@ fn varDecl(
const gpa = astgen.gpa; const gpa = astgen.gpa;
const tree = astgen.tree; const tree = astgen.tree;
const token_tags = tree.tokens.items(.tag); const token_tags = tree.tokens.items(.tag);
const main_tokens = tree.nodes.items(.main_token);
const name_token = var_decl.ast.mut_token + 1; const name_token = var_decl.ast.mut_token + 1;
const ident_name_raw = tree.tokenSlice(name_token); const ident_name_raw = tree.tokenSlice(name_token);
@ -2391,6 +2392,14 @@ fn varDecl(
return astgen.failNode(node, "variables must be initialized", .{}); return astgen.failNode(node, "variables must be initialized", .{});
} }
if (var_decl.ast.addrspace_node != 0) {
return astgen.failTok(main_tokens[var_decl.ast.addrspace_node], "cannot set address space of local variable '{s}'", .{ ident_name_raw });
}
if (var_decl.ast.section_node != 0) {
return astgen.failTok(main_tokens[var_decl.ast.section_node], "cannot set section of local variable '{s}'", .{ ident_name_raw });
}
const align_inst: Zir.Inst.Ref = if (var_decl.ast.align_node != 0) const align_inst: Zir.Inst.Ref = if (var_decl.ast.align_node != 0)
try expr(gz, scope, align_rl, var_decl.ast.align_node) try expr(gz, scope, align_rl, var_decl.ast.align_node)
else else