aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthew Borkowski <matthew.h.borkowski@gmail.com>2021-10-23 21:52:21 -0400
committerMatthew Borkowski <matthew.h.borkowski@gmail.com>2021-10-23 22:52:43 -0400
commit9c5b852f9bb47e25c878cbccdaa175517ae48fc6 (patch)
treecdad612fccceb4ba7664059c790d3785b0d3fbd5 /src
parent8a95bac593ce9aa36b76229a9f2f4aba8c8d30dd (diff)
downloadzig-9c5b852f9bb47e25c878cbccdaa175517ae48fc6.tar.gz
zig-9c5b852f9bb47e25c878cbccdaa175517ae48fc6.zip
astgen.zig: emit ZIR for callconv before return type in fnDecl and fnProtoExpr
Diffstat (limited to 'src')
-rw-r--r--src/AstGen.zig30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/AstGen.zig b/src/AstGen.zig
index 33f538df1b..92d0e3de7c 100644
--- a/src/AstGen.zig
+++ b/src/AstGen.zig
@@ -1156,16 +1156,6 @@ fn fnProtoExpr(
return astgen.failNode(fn_proto.ast.section_expr, "linksection not allowed on function prototypes", .{});
}
- const maybe_bang = tree.firstToken(fn_proto.ast.return_type) - 1;
- const is_inferred_error = token_tags[maybe_bang] == .bang;
- if (is_inferred_error) {
- return astgen.failTok(maybe_bang, "function prototype may not have inferred error set", .{});
- }
- var ret_gz = gz.makeSubBlock(scope);
- defer ret_gz.instructions.deinit(gpa);
- const ret_ty = try expr(&ret_gz, scope, coerced_type_rl, fn_proto.ast.return_type);
- const ret_br = try ret_gz.addBreak(.break_inline, 0, ret_ty);
-
const cc: Zir.Inst.Ref = if (fn_proto.ast.callconv_expr != 0)
try expr(
gz,
@@ -1176,6 +1166,16 @@ fn fnProtoExpr(
else
Zir.Inst.Ref.none;
+ const maybe_bang = tree.firstToken(fn_proto.ast.return_type) - 1;
+ const is_inferred_error = token_tags[maybe_bang] == .bang;
+ if (is_inferred_error) {
+ return astgen.failTok(maybe_bang, "function prototype may not have inferred error set", .{});
+ }
+ var ret_gz = gz.makeSubBlock(scope);
+ defer ret_gz.instructions.deinit(gpa);
+ const ret_ty = try expr(&ret_gz, scope, coerced_type_rl, fn_proto.ast.return_type);
+ const ret_br = try ret_gz.addBreak(.break_inline, 0, ret_ty);
+
const result = try gz.addFunc(.{
.src_node = fn_proto.ast.proto_node,
.param_block = 0,
@@ -3182,11 +3182,6 @@ fn fnDecl(
break :inst try comptimeExpr(&decl_gz, params_scope, .{ .ty = .const_slice_u8_type }, fn_proto.ast.section_expr);
};
- var ret_gz = decl_gz.makeSubBlock(params_scope);
- defer ret_gz.instructions.deinit(gpa);
- const ret_ty = try expr(&ret_gz, params_scope, coerced_type_rl, fn_proto.ast.return_type);
- const ret_br = try ret_gz.addBreak(.break_inline, 0, ret_ty);
-
const cc: Zir.Inst.Ref = blk: {
if (fn_proto.ast.callconv_expr != 0) {
if (has_inline_keyword) {
@@ -3212,6 +3207,11 @@ fn fnDecl(
}
};
+ var ret_gz = decl_gz.makeSubBlock(params_scope);
+ defer ret_gz.instructions.deinit(gpa);
+ const ret_ty = try expr(&ret_gz, params_scope, coerced_type_rl, fn_proto.ast.return_type);
+ const ret_br = try ret_gz.addBreak(.break_inline, 0, ret_ty);
+
const func_inst: Zir.Inst.Ref = if (body_node == 0) func: {
if (!is_extern) {
return astgen.failTok(fn_proto.ast.fn_token, "non-extern function has no body", .{});