Skip to content

Commit 5ee4e5a

Browse files
committed
copy elision: runtime struct init
```zig export fn entry() void { var x = Foo.{ .x = 1, .y = bar(), }; } ``` ```llvm define void @entry() #2 !dbg !41 { Entry: %x = alloca %Foo, align 4 %0 = getelementptr inbounds %Foo, %Foo* %x, i32 0, i32 0, !dbg !56 store i32 1, i32* %0, align 4, !dbg !57 %1 = getelementptr inbounds %Foo, %Foo* %x, i32 0, i32 1, !dbg !58 call fastcc void @bar(%Bar* sret %1), !dbg !59 ret void, !dbg !60 } ```
1 parent e1dfb5f commit 5ee4e5a

File tree

5 files changed

+84
-59
lines changed

5 files changed

+84
-59
lines changed

src/all_types.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ enum NodeType {
436436
NodeTypeArrayType,
437437
NodeTypeErrorType,
438438
NodeTypeIfErrorExpr,
439-
NodeTypeTestExpr,
439+
NodeTypeIfOptional,
440440
NodeTypeErrorSetDecl,
441441
NodeTypeCancel,
442442
NodeTypeResume,
@@ -2370,6 +2370,7 @@ struct IrInstructionFieldPtr {
23702370
IrInstruction *container_ptr;
23712371
Buf *field_name_buffer;
23722372
IrInstruction *field_name_expr;
2373+
IrInstruction *container_type;
23732374
bool is_const;
23742375
};
23752376

src/analyze.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3517,7 +3517,7 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {
35173517
case NodeTypeArrayType:
35183518
case NodeTypeErrorType:
35193519
case NodeTypeIfErrorExpr:
3520-
case NodeTypeTestExpr:
3520+
case NodeTypeIfOptional:
35213521
case NodeTypeErrorSetDecl:
35223522
case NodeTypeCancel:
35233523
case NodeTypeResume:

src/ast_render.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ static const char *node_type_str(NodeType node_type) {
235235
return "ErrorType";
236236
case NodeTypeIfErrorExpr:
237237
return "IfErrorExpr";
238-
case NodeTypeTestExpr:
239-
return "TestExpr";
238+
case NodeTypeIfOptional:
239+
return "IfOptional";
240240
case NodeTypeErrorSetDecl:
241241
return "ErrorSetDecl";
242242
case NodeTypeCancel:
@@ -938,7 +938,7 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {
938938
}
939939
break;
940940
}
941-
case NodeTypeTestExpr:
941+
case NodeTypeIfOptional:
942942
{
943943
fprintf(ar->f, "if (");
944944
render_node_grouped(ar, node->data.test_expr.target_node);

0 commit comments

Comments
 (0)