mirror of
https://github.com/ziglang/zig.git
synced 2026-01-21 06:45:24 +00:00
Compiler: move checking function-scope-only builtins to AstGen
This commit is contained in:
parent
bece97ef24
commit
2252dcc508
@ -8266,6 +8266,28 @@ fn builtinCall(
|
||||
}
|
||||
}
|
||||
|
||||
// Check function scope-only builtins
|
||||
|
||||
if (astgen.fn_block == null) {
|
||||
switch (info.tag) {
|
||||
.c_va_arg,
|
||||
.c_va_copy,
|
||||
.c_va_end,
|
||||
.c_va_start,
|
||||
.work_item_id,
|
||||
.work_group_size,
|
||||
.work_group_id,
|
||||
.set_align_stack,
|
||||
.set_cold,
|
||||
.return_address,
|
||||
.frame_address,
|
||||
.breakpoint,
|
||||
.src,
|
||||
=> return astgen.failNode(node, "'{s}' outside function scope", .{builtin_name}),
|
||||
else => {},
|
||||
}
|
||||
}
|
||||
|
||||
switch (info.tag) {
|
||||
.import => {
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
@ -8802,9 +8824,6 @@ fn builtinCall(
|
||||
return rvalue(gz, ri, .void_value, node);
|
||||
},
|
||||
.c_va_arg => {
|
||||
if (astgen.fn_block == null) {
|
||||
return astgen.failNode(node, "'@cVaArg' outside function scope", .{});
|
||||
}
|
||||
const result = try gz.addExtendedPayload(.c_va_arg, Zir.Inst.BinNode{
|
||||
.node = gz.nodeIndexToRelative(node),
|
||||
.lhs = try expr(gz, scope, .{ .rl = .none }, params[0]),
|
||||
@ -8813,9 +8832,6 @@ fn builtinCall(
|
||||
return rvalue(gz, ri, result, node);
|
||||
},
|
||||
.c_va_copy => {
|
||||
if (astgen.fn_block == null) {
|
||||
return astgen.failNode(node, "'@cVaCopy' outside function scope", .{});
|
||||
}
|
||||
const result = try gz.addExtendedPayload(.c_va_copy, Zir.Inst.UnNode{
|
||||
.node = gz.nodeIndexToRelative(node),
|
||||
.operand = try expr(gz, scope, .{ .rl = .none }, params[0]),
|
||||
@ -8823,9 +8839,6 @@ fn builtinCall(
|
||||
return rvalue(gz, ri, result, node);
|
||||
},
|
||||
.c_va_end => {
|
||||
if (astgen.fn_block == null) {
|
||||
return astgen.failNode(node, "'@cVaEnd' outside function scope", .{});
|
||||
}
|
||||
const result = try gz.addExtendedPayload(.c_va_end, Zir.Inst.UnNode{
|
||||
.node = gz.nodeIndexToRelative(node),
|
||||
.operand = try expr(gz, scope, .{ .rl = .none }, params[0]),
|
||||
@ -8833,9 +8846,6 @@ fn builtinCall(
|
||||
return rvalue(gz, ri, result, node);
|
||||
},
|
||||
.c_va_start => {
|
||||
if (astgen.fn_block == null) {
|
||||
return astgen.failNode(node, "'@cVaStart' outside function scope", .{});
|
||||
}
|
||||
if (!astgen.fn_var_args) {
|
||||
return astgen.failNode(node, "'@cVaStart' in a non-variadic function", .{});
|
||||
}
|
||||
@ -8843,9 +8853,6 @@ fn builtinCall(
|
||||
},
|
||||
|
||||
.work_item_id => {
|
||||
if (astgen.fn_block == null) {
|
||||
return astgen.failNode(node, "'@workItemId' outside function scope", .{});
|
||||
}
|
||||
const operand = try comptimeExpr(gz, scope, .{ .rl = .{ .coerced_ty = .u32_type } }, params[0]);
|
||||
const result = try gz.addExtendedPayload(.work_item_id, Zir.Inst.UnNode{
|
||||
.node = gz.nodeIndexToRelative(node),
|
||||
@ -8854,9 +8861,6 @@ fn builtinCall(
|
||||
return rvalue(gz, ri, result, node);
|
||||
},
|
||||
.work_group_size => {
|
||||
if (astgen.fn_block == null) {
|
||||
return astgen.failNode(node, "'@workGroupSize' outside function scope", .{});
|
||||
}
|
||||
const operand = try comptimeExpr(gz, scope, .{ .rl = .{ .coerced_ty = .u32_type } }, params[0]);
|
||||
const result = try gz.addExtendedPayload(.work_group_size, Zir.Inst.UnNode{
|
||||
.node = gz.nodeIndexToRelative(node),
|
||||
@ -8865,9 +8869,6 @@ fn builtinCall(
|
||||
return rvalue(gz, ri, result, node);
|
||||
},
|
||||
.work_group_id => {
|
||||
if (astgen.fn_block == null) {
|
||||
return astgen.failNode(node, "'@workGroupId' outside function scope", .{});
|
||||
}
|
||||
const operand = try comptimeExpr(gz, scope, .{ .rl = .{ .coerced_ty = .u32_type } }, params[0]);
|
||||
const result = try gz.addExtendedPayload(.work_group_id, Zir.Inst.UnNode{
|
||||
.node = gz.nodeIndexToRelative(node),
|
||||
|
||||
@ -6151,9 +6151,6 @@ fn zirSetAlignStack(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst
|
||||
alignment.toByteUnitsOptional().?,
|
||||
});
|
||||
}
|
||||
if (sema.func_index == .none) {
|
||||
return sema.fail(block, src, "@setAlignStack outside function body", .{});
|
||||
}
|
||||
|
||||
const fn_owner_decl = mod.funcOwnerDeclPtr(sema.func_index);
|
||||
switch (fn_owner_decl.ty.fnCallingConvention(mod)) {
|
||||
@ -16780,13 +16777,12 @@ fn zirBuiltinSrc(
|
||||
block: *Block,
|
||||
extended: Zir.Inst.Extended.InstData,
|
||||
) CompileError!Air.Inst.Ref {
|
||||
_ = block;
|
||||
const tracy = trace(@src());
|
||||
defer tracy.end();
|
||||
|
||||
const mod = sema.mod;
|
||||
const extra = sema.code.extraData(Zir.Inst.Src, extended.operand).data;
|
||||
const src = LazySrcLoc.nodeOffset(extra.node);
|
||||
if (sema.func_index == .none) return sema.fail(block, src, "@src outside function", .{});
|
||||
const fn_owner_decl = mod.funcOwnerDeclPtr(sema.func_index);
|
||||
const ip = &mod.intern_pool;
|
||||
const gpa = sema.gpa;
|
||||
|
||||
@ -0,0 +1,69 @@
|
||||
comptime {
|
||||
@setAlignStack(1);
|
||||
}
|
||||
|
||||
comptime {
|
||||
@setCold(true);
|
||||
}
|
||||
|
||||
comptime {
|
||||
@src();
|
||||
}
|
||||
|
||||
comptime {
|
||||
@returnAddress();
|
||||
}
|
||||
|
||||
comptime {
|
||||
@frameAddress();
|
||||
}
|
||||
|
||||
comptime {
|
||||
@breakpoint();
|
||||
}
|
||||
|
||||
comptime {
|
||||
@cVaArg(1, 2);
|
||||
}
|
||||
|
||||
comptime {
|
||||
@cVaCopy(1);
|
||||
}
|
||||
|
||||
comptime {
|
||||
@cVaEnd(1);
|
||||
}
|
||||
|
||||
comptime {
|
||||
@cVaStart();
|
||||
}
|
||||
|
||||
comptime {
|
||||
@workItemId(42);
|
||||
}
|
||||
|
||||
comptime {
|
||||
@workGroupSize(42);
|
||||
}
|
||||
|
||||
comptime {
|
||||
@workGroupId(42);
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// :2:5: error: '@setAlignStack' outside function scope
|
||||
// :6:5: error: '@setCold' outside function scope
|
||||
// :10:5: error: '@src' outside function scope
|
||||
// :14:5: error: '@returnAddress' outside function scope
|
||||
// :18:5: error: '@frameAddress' outside function scope
|
||||
// :22:5: error: '@breakpoint' outside function scope
|
||||
// :26:5: error: '@cVaArg' outside function scope
|
||||
// :30:5: error: '@cVaCopy' outside function scope
|
||||
// :34:5: error: '@cVaEnd' outside function scope
|
||||
// :38:5: error: '@cVaStart' outside function scope
|
||||
// :42:5: error: '@workItemId' outside function scope
|
||||
// :46:5: error: '@workGroupSize' outside function scope
|
||||
// :50:5: error: '@workGroupId' outside function scope
|
||||
@ -1,9 +0,0 @@
|
||||
comptime {
|
||||
@setAlignStack(16);
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// :2:5: error: @setAlignStack outside function body
|
||||
@ -1,9 +0,0 @@
|
||||
comptime {
|
||||
@src();
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// :2:5: error: @src outside function
|
||||
Loading…
x
Reference in New Issue
Block a user