Skip to content

Commit a3dd4e8

Browse files
committed
handle initializing some structs to 0
1 parent 195e18d commit a3dd4e8

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

backends/asm/outasm.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5539,7 +5539,20 @@ CompileFunctionBody(Function *f)
55395539
if (init) {
55405540
AST *zero = AstInteger(0);
55415541
if (IsIdentifier(init) || init->kind == AST_RESULT) {
5542-
AST *resinit = AstAssign(init, zero);
5542+
AST *typ = ExprType(init);
5543+
int n = TypeSize(typ);
5544+
AST *resinit;
5545+
if (n <= LONG_SIZE) {
5546+
resinit = AstAssign(init, zero);
5547+
} else {
5548+
/* do a multiple assignment */
5549+
AST *initlist = NULL;
5550+
n = (n + LONG_SIZE - 1) / LONG_SIZE;
5551+
for (int i = 0; i < n; i++) {
5552+
initlist = AddToList(initlist, NewAST(AST_EXPRLIST, zero, NULL));
5553+
}
5554+
resinit = AstAssign(init, initlist);
5555+
}
55435556
CompileStatement(irl, cold_irl_ptr, resinit);
55445557
} else if (init->kind == AST_EXPRLIST) {
55455558
AST *var;

0 commit comments

Comments
 (0)